Skip to content

Commit

Permalink
Added new WateringPlan function
Browse files Browse the repository at this point in the history
  • Loading branch information
Hydrosys4 committed Sep 4, 2021
1 parent 88d9d44 commit 36850c6
Show file tree
Hide file tree
Showing 25 changed files with 1,115 additions and 593 deletions.
82 changes: 82 additions & 0 deletions ActuatorControllermod.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import logging
import hardwaremod
import emailmod
import actuatordbmod
import autofertilizermod


logger = logging.getLogger("hydrosys4."+__name__)

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
out=""
actuatortype=hardwaremod.searchdata(hardwaremod.HW_INFO_NAME,target,hardwaremod.HW_CTRL_CMD)
actuatortypelist=actuatortype.split("/")
if actuatortypelist:
actuatortype=actuatortypelist[0]
print (" 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
out, isok=hardwaremod.makepulse(target,duration)
# salva su database
if isok:
actuatordbmod.insertdataintable(target,duration)

# 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 out , isok




if __name__ == '__main__':

"""
prova functions
"""
target="Relay1_1"
value="10"



61 changes: 26 additions & 35 deletions GPIOEXPI2Ccontrol.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,15 @@ def tonumber(thestring, outwhenfail):
except:
return outwhenfail

def returnmsg(recdata,cmd,msg,successful):
recdata.clear()
print(msg)
recdata.append(cmd)
recdata.append(msg)
recdata.append(successful)
if not successful:
logger.error("Error: %s" ,msg)
return True

def execute_task(cmd, message, recdata):
global hbridge_data
Expand All @@ -131,12 +140,10 @@ def execute_task(cmd, message, recdata):


else:
print("Command not found")
recdata.append(cmd)
recdata.append("e")
recdata.append(0)
return False;
return False;
msg="Command not found"
returnmsg(recdata,cmd,msg,0)
return False
return False


def execute_task_fake(cmd, message, recdata):
Expand All @@ -149,11 +156,9 @@ def execute_task_fake(cmd, message, recdata):


else:
print("no fake command available" , cmd)
recdata.append(cmd)
recdata.append("e")
recdata.append(0)
return False;
msg="no fake command available" + cmd
returnmsg(recdata,cmd,msg,0)
return False

return True

Expand Down Expand Up @@ -326,9 +331,7 @@ def gpio_pulse(cmd, message, recdata):
print("No Action, pulse activated when PIN already active and activationmode is NOADD")
logger.warning("No Action, pulse activated when PIN already active and activationmode is NOADD")
successflag=1
recdata.append(cmd)
recdata.append(PIN)
recdata.append(successflag)
returnmsg(recdata,cmd,PIN,successflag)
return True


Expand All @@ -349,11 +352,7 @@ def gpio_pulse(cmd, message, recdata):
pulseok=GPIO_output(address, PIN, level)
if not pulseok:
msg="Not able to activate the pulse in GPIO Expansion, Address I2C: " + address + " PIN: "+ PIN
print(msg)
logger.error(msg)
recdata.append(cmd)
recdata.append(msg)
recdata.append(0)
returnmsg(recdata,cmd,msg,0)
return True


Expand All @@ -364,9 +363,7 @@ def gpio_pulse(cmd, message, recdata):

#print "pulse started", time.ctime() , " PIN=", PIN , " Logic=", logic
successflag=1
recdata.append(cmd)
recdata.append(PIN)
recdata.append(successflag)
returnmsg(recdata,cmd,PIN,successflag)
return True

def gpio_stoppulse(cmd, message, recdata):
Expand Down Expand Up @@ -394,9 +391,7 @@ def gpio_stoppulse(cmd, message, recdata):
print("No Action, Already OFF")
logger.warning("No Action, Already OFF")
successflag=1
recdata.append(cmd)
recdata.append(PIN)
recdata.append(successflag)
returnmsg(recdata,cmd,PIN,successflag)
return True


Expand All @@ -406,8 +401,8 @@ def gpio_stoppulse(cmd, message, recdata):
PINthreadID.cancel()

endpulse(address, PIN,logic,POWERPIN) #this also put powerpin off
recdata.append(cmd)
recdata.append(PIN)

returnmsg(recdata,cmd,PIN,1)
return True


Expand All @@ -418,13 +413,12 @@ def gpio_pin_level(cmd, message, recdata):
if address=="":
address="0x20"

recdata.append(msgarray[0])
PINlevel=statusdataDBmod.read_status_data(GPIO_data,address+PIN,"level")
if PINlevel is not None:
recdata.append(str(PINlevel))
returnmsg(recdata,cmd,str(PINlevel),1)
return True
else:
recdata.append("e")
returnmsg(recdata,cmd,"error",0)
return False


Expand All @@ -437,18 +431,15 @@ def read_input_pin(cmd, message, recdata):
#print " read pin input ", message
PINstr=msgarray[1]
isRealPIN,PIN=CheckRealHWpin(PINstr)
recdata.append(cmd)
if isRealPIN:
if GPIO.input(PIN):
reading="1"
else:
reading="0"
recdata.append(reading)
recdata.append(successflag)
returnmsg(recdata,cmd,reading,successflag)
else:
successflag=0
recdata.append("e")
recdata.append(successflag)
returnmsg(recdata,cmd,"error",successflag)
return True

def isPinActive(address, PIN, logic):
Expand Down
Loading

0 comments on commit 36850c6

Please sign in to comment.