def job(str): log_util.log_info(__name__, str) GPIO.output(relay_pin, 0) sleep(3.2) GPIO.output(relay_pin, 1) # sleep(58) return
def readings_subscribe_action(client, userdata, message): log_util.log_info(__name__, 'Received a message: {}'.format(message.payload)) byte_payload = message.payload.decode('utf8').replace("'", '"') data = json.loads(byte_payload) if automatic: log_util.log_debug(__name__, "Automatic is on, checking the moisture level...") if sensors.moisture_level(data['Items']): data = {"action": "ON", "requester": "AUTOMATIC"} water.watering_invocation(data) else: log_util.log_info( __name__, 'The soil is too wet, the moisture level is {}'.format( data['Items']['moisture1']))
def status_subscribe_action(client, userdata, message): global automatic log_util.log_info(__name__, 'Received a message: {}'.format(message.payload)) byte_payload = message.payload.decode('utf8').replace("'", '"') data = json.loads(byte_payload) status = data['status'] if status == 'A': log_util.log_debug(__name__, "Turned ON automatic") automatic = True elif status == 'M': automatic = False log_util.log_debug(__name__, "Turned OFF automatic") elif status == 'F': watering = {"action": "OFF", "requester": "MANUAL"} log_util.log_debug(__name__, "Turned OFF Manual") water.watering_invocation(watering) elif status == 'O': watering = {"action": "ON", "requester": "MANUAL"} log_util.log_debug(__name__, "Turned ON Manual") water.watering_invocation(watering)
humidity_unvalidated, temperature_unvalidated = Adafruit_DHT.read_retry(DHT_SENSOR, channel) log_util.log_debug(__name__, humidity_unvalidated) log_util.log_debug(__name__, temperature_unvalidated) if humidity_unvalidated and temperature_unvalidated: data_humidity.append(humidity_unvalidated) data_temperature.append(temperature_unvalidated) i += 1 return round((sum(data_humidity) / len(data_humidity)), 2), round((sum(data_temperature) / len(data_temperature)), 2) # Keep reading the data from the Sensors while True: try: moisture = moisture_reading(moisture_pin) log_util.log_info(__name__, "Moisture reading: {}".format(moisture)) light = light_reading(ldr_pin) log_util.log_info(__name__, "Light reading: {}".format(light)) humidity, temperature = air_sensor_reading(dht_pin) log_util.log_info(__name__, "Temperature reading: {}".format(temperature)) log_util.log_info(__name__, "Humidity reading: {}".format(humidity)) message = {} message["id"] = 'id_smartgarden' now = datetime.datetime.now() message["datetimeid"] = now.isoformat() message['Items'] = {"moisture1": moisture, "temperature": temperature, "humidity": humidity, "light": light} core.publish_readings(message)
def max_data_update_action(client, userdata, message): log_util.log_info(__name__, 'Received a message: {}'.format(message.payload)) byte_payload = message.payload.decode('utf8').replace("'", '"') data = json.loads(byte_payload) validate_sensors_values.update_sensor_value(data)
def watering_subscribe_action(client, userdata, message): log_util.log_info(__name__, 'Received a message: {}'.format(message.payload)) byte_payload = message.payload.decode('utf8').replace("'", '"') data = json.loads(byte_payload) water.watering_invocation(data)
from multiprocessing import Process import log_util def script1(): while True: pass def script2(): while True: pass if __name__ == '__main__': log_util.log_info(__name__, 'Running scripts...') proc1 = Process(target=script1) proc1.start() log_util.log_info(__name__, 'Reading script running...') proc2 = Process(target=script2) proc2.start() log_util.log_info(__name__, 'Status script running...') log_util.log_info(__name__, 'Scripts running')
def stopWatering(str): log_util.log_info(__name__, str)