def Timer_Settings_Start(data): global timer_pending timer_pending += 1 settings = data timer_name = settings["timer_name"] text.writeln("Timer Start: " + timer_name)
def Timer_Settings_Stop(data): global timer_pending timer_pending -= 0 settings = data timer_name = settings["timer_name"] text.writeln("Timer Stop: " + timer_name) if (timer_pending == 0): Setup_Default_Settings()
def Check_Settings_Changed(): global last_settings_changed try: time = webservice.LoadSettingChanged(controller_id) if (time): changed = False settings_changed = datetime.datetime.strptime( time, "%Y-%m-%d %H:%M:%S") text.writeln("Check Settings Changes: " + str(settings_changed) + " " + str(last_settings_changed)) if (settings_changed != last_settings_changed): last_settings_changed = settings_changed changed = True Setup_Default_Settings() except: text.error("Check Settings Changes Error " + sys.exc_info()[0])
def Update_Hardware_Status(): try: data = {} data["moist"] = hardware.Get_Moisture_Status() data["humid"] = hardware.Get_Humidity_Status() data["temper"] = hardware.Get_Temperature_Status() data["lux"] = hardware.Get_Luminance_Status() data["light"] = hardware.Get_Light_Status() data["pump"] = hardware.Get_Pump_Status() data["aircon"] = hardware.Get_Aircon_Status() data["temp"] = hardware.Get_Temp_Status() data["fan"] = hardware.Get_Fan_Status() text.writeln("Update Status: " + str(data)) webservice.UpdateStatus(controller_id, data) except: text.error("Update Status Error " + str(sys.exc_info()[0]))
def Setup_Default_Settings(): new_settings = webservice.LoadSettingData(controller_id) if (new_settings): text.writeln("Setup Default Settings") changed = setup.ChangeSettings(new_settings) if (changed): text.writeln("New Settings:" + str(new_settings)) text.writeln("Current Settings:" + str(setup.current_settings))
def Setting_Fan(value): hardware.Set_Fan_Status(value) current_settings["fan"] = value text.writeln("Setting Fan = " + str(value))
def Setting_Temp(value): hardware.Set_Temp_Status(value) current_settings["temp"] = value text.writeln("Setting Temp = " + str(value))
def Setting_Aircon(value): hardware.Set_Aircon_Status(value) current_settings["aircon"] = value text.writeln("Setting Aircon = " + str(value))
def Setting_Light(value): hardware.Set_Light_Status(value) current_settings["light"] = value text.writeln("Setting Light = " + str(value))
data["aircon"] = hardware.Get_Aircon_Status() data["temp"] = hardware.Get_Temp_Status() data["fan"] = hardware.Get_Fan_Status() text.writeln("Update Status: " + str(data)) webservice.UpdateStatus(controller_id, data) except: text.error("Update Status Error " + str(sys.exc_info()[0])) ####################### MAIN ######################### msg = "Starting SmartFarm. ID=" + str(controller_id) text.writeln(msg) hardware.Set_Display_Message(msg) settings = webservice.LoadSettingData(controller_id) timers = webservice.LoadTimersData(controller_id) if (timers): for timer in timers: start_time = int(timer["start_time"]) start_duration_seconds = int(timer["start_duration_sec"]) start_time_value = "%02d:%02d:00" % (start_time / 60, start_time % 60) schedule.every().day.at(start_time_value).do(Timer_Settings_Start, data=timer)