def GetConfiguration(): try: if IOHelper.IsInRaspberry(): f = urllib.request.urlopen(RemoteConfigurationFile) mybytes = f.read() configurationFileContent = mybytes.decode("utf8") else: configurationFileContent = IOHelper.ReadFromFile(LocalConfigurationFile) configuration = Configuration.from_json(json.loads(configurationFileContent)) return configuration except: raise return None
import IOHelper if not IOHelper.IsInRaspberry(): # Running on Windows from win10toast import ToastNotifier toaster = ToastNotifier() def OpenValve(): toaster.show_toast("RPIWaterSystem - GPIO", "Openning Valve") def CloseValve(): toaster.show_toast("RPIWaterSystem - GPIO", "Closing Valve") else: # Running on RaspberryPi from gpiozero import LED VALVE_GPIO = 26 valve = LED(VALVE_GPIO) def OpenValve(): valve.on() def CloseValve(): valve.off()
def SendTweet(message): if IOHelper.IsInRaspberry(): api.send_direct_message(my_twitter_id, message) else: toaster.show_toast("RPIWaterSystem - Twitter", message)