def activateactuator(target, value): # return true in case the state change: activation is >0 or a different position from prevoius position. # check the actuator isok=False actuatortype=hardwaremod.searchdata(hardwaremod.HW_INFO_NAME,target,hardwaremod.HW_CTRL_CMD) actuatortypelist=actuatortype.split("/") if actuatortypelist: actuatortype=actuatortypelist[0] print (" Automation Actuator " + actuatortype + " target " + target) supportedactuators=["pulse","servo","stepper"] # stepper motor if actuatortype=="stepper": out, isok = hardwaremod.GO_stepper_position(target,value) if isok: actuatordbmod.insertdataintable(target,value) # hbridge motor if actuatortype=="hbridge": out, isok = hardwaremod.GO_hbridge_position(target,value) if isok: actuatordbmod.insertdataintable(target,value) # pulse if actuatortype=="pulse": duration=hardwaremod.toint(value,0) # check the fertilizer doser flag before activating the pulse doseron=autofertilizermod.checkactivate(target,duration) # start pulse pulseok=hardwaremod.makepulse(target,duration) # salva su database if "Started" in pulseok: actuatordbmod.insertdataintable(target,duration) isok=True # servo motor if actuatortype=="servo": out, isok = hardwaremod.servoangle(target,value,0.5) if isok: actuatordbmod.insertdataintable(target,value) # photo if actuatortype=="photo": duration=hardwaremod.toint(value,0) if duration>0: isok=hardwaremod.takephoto(True) # save action in database if isok: actuatordbmod.insertdataintable(target,1) # mail if (actuatortype=="mail+info+link")or(actuatortype=="mail+info"): if value>0: mailtext=str(value) isok=emailmod.sendmail(target,"info","Automation Value:" + mailtext) # save action in database if isok: actuatordbmod.insertdataintable(target,1) return isok
def sendmail(target): logger.info('send Mail %s', datetime.now().strftime("%Y-%m-%d %H:%M:%S")) # save action in database issent = emailmod.sendmail( target, "report", "Periodic system report generated automatically") if issent: actuatordbmod.insertdataintable(target, 1) print "Action", target, " ", datetime.now()
def activateactuator(target, value): # return true in case the state change: activation is >0 or a different position from prevoius position. # check the actuator isok=False actuatortype=hardwaremod.searchdata(hardwaremod.HW_INFO_NAME,target,hardwaremod.HW_CTRL_CMD) supportedactuators=["pulse","servo","stepper"] # stepper motor if actuatortype=="stepper": out, isok = hardwaremod.GO_stepper_position(target,value,priority=ACTIONPRIORITYLEVEL) if isok: actuatordbmod.insertdataintable(target,value) # hbridge motor if actuatortype=="hbridge": out, isok = hardwaremod.GO_hbridge_position(target,value) if isok: actuatordbmod.insertdataintable(target,value) # pulse if actuatortype=="pulse": duration=hardwaremod.toint(value,0) if duration>0: # check the fertilizer doser flag before activating the pulse doseron=autofertilizermod.checkactivate(target,duration) # start pulse pulseok=hardwaremod.makepulse(target,duration,priority=ACTIONPRIORITYLEVEL) # salva su database if "Started" in pulseok: actuatordbmod.insertdataintable(target,duration) isok=True else: pulseok=hardwaremod.stoppulse(target) # servo motor if actuatortype=="servo": out, isok = hardwaremod.servoangle(target,value,0.5,priority=ACTIONPRIORITYLEVEL) if isok: actuatordbmod.insertdataintable(target,value) # photo if actuatortype=="photo": duration=hardwaremod.toint(value,0) if duration>0: isok=hardwaremod.takephoto(True) # True override the daily activation # save action in database if isok: actuatordbmod.insertdataintable(target,1) # mail if (actuatortype=="mail+info+link")or(actuatortype=="mail+info"): if value>0: mailtext=str(value) isok=emailmod.sendmail(target,"info","Interrupt Value:" + mailtext) # save action in database if isok: actuatordbmod.insertdataintable(target,1) return isok
def sendmail(target): logger.info('send Mail %s', datetime.now().strftime("%Y-%m-%d %H:%M:%S")) # save action in database issent=emailmod.sendmail(target,"report","Periodic system report generated automatically") if issent: actuatordbmod.insertdataintable(target,1) print "Action", target , " " , datetime.now() return True