class Watcher: """ PiMotics core watcher """ def __init__(self): self.module = __name__ self.system = System() def check_services(self): """ Checks the status of required services :returns: status of the services :rtype: bool """ logging = LogHandler(System().get_watcher_log_dir()) # Checking the API sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) result = sock.connect_ex((self.system.get_grid_ip(), self.system.get_api_port())) if result == 0: api_status = True logging.logger("Status of API: ACTIVE", 4, module) else: api_status = False logging.logger("Status of API: INACTIVE", 4, module) # Checking the LOCAL_NET if ServiceManager().get_service_status("pimotics-local-net"): local_net_status = True logging.logger("Status of LOCAL_NET: ACTIVE", 4, module) else: local_net_status = False logging.logger("Status of LOCAL_NET: INACTIVE", 4, module) # Output result if api_status and local_net_status: return True else: return False
ledState = not bool(GPIO.input(LED)) GPIO.output(LED, ledState) return str({'success': True, 'status': ledState}) @app.route("{0}/toggle/7".format(API_BASEDIR)) def led2(): LED = 10 GPIO.setup(LED, GPIO.OUT) ledState = not bool(GPIO.input(LED)) GPIO.output(LED, ledState) return str({'success': True, 'status': ledState}) @app.route("{0}/temperature/2".format(API_BASEDIR)) def sensor(): TEMP = 5 SENSOR = 2302 result = SensorController.get_temperature_and_humidity(SENSOR, TEMP) return str(result) if __name__ == "__main__": system = System() app.run(host=system.get_grid_ip(), port=system.get_api_port(), debug=system.get_debug_mode())