def get_result(env, hour): """Get data from ThingSpeak adaptor and decide. Get the last entries on rain field and decides if it is necessary or not to irrigate. """ url, port, plantID, devID, ts_url, ts_port = functions.read_file(FILE) resource = "rain" time = "minutes" tval = str(5 * 60) # Check if it has rained in previous hours string = ("http://" + ts_url + ":" + ts_port + "/data/" + plantID + "/" + resource + "?time=" + time + "&tval=" + tval + "&plantID=" + plantID + "&devID=" + devID) print(string) data = json.loads(requests.get(string).text) data = data["data"] # Rain strategy. if data != []: m = np.mean(data) if m >= 0.6: # Rain for at least 60% of the time duration = -900000 # Do not irrigate elif (m >= 0.4) and (m < 0.6): # Rain from 40-60% of the time duration = -200 # Remove 200 seconds else: # Almost no rain duration = None # No modifications if duration is not None: functions.post_mod(plantID, hour, duration, 0, url, port)
def get_result(env, hour): """Get data from ThingSpeak adaptor and decide. Get the last entries on humidity field and decides if it is necessary or not to modify duration of irrigation. """ url, port, plantID, devID, ts_url, ts_port = functions.read_file(FILE) resource = "humidity" time = "minutes" tval = str(5 * 60) # Check humidity trending in previous hours string = ("http://" + ts_url + ":" + ts_port + "/data/" + plantID + "/" + resource + "?time=" + time + "&tval=" + tval + "&plantID=" + plantID + "&devID=" + devID) print(string) data = json.loads(requests.get(string).text) data = data["data"] # Humidity strategy. if data != []: m = np.mean(data) diff = np.abs(env["humidity"] - m) duration = 100 * np.arctan(0.05 * diff) # Add 300 seconds. duration = round(duration) else: duration = None if duration is not None: functions.post_mod(plantID, hour, duration, 0, url, port)
def get_result(env, hour, type): """Get data from ThingSpeak adaptor and decide. Get the last entries on light field and decides if it is necessary or not to modify duration of irrigation. """ url, port, plantID, devID, ts_url, ts_port = functions.read_file(FILE) resource = "light" time = "minutes" tval = str(2 * 60) # Check light trending in previous hours string = ("http://" + ts_url + ":" + ts_port + "/data/" + plantID + "/" + resource + "?time=" + time + "&tval=" + tval + "&plantID=" + plantID + "&devID=" + devID) print(string) data = json.loads(requests.get(string).text) data = data["data"] # Light strategy. delay = 0 if data != []: m = np.mean(data) print("Resistance: %d" % m) if type == 'evening': print("Checking evening light condition...") if (m >= 140) and (m < 160): # Very dark delay = -1800 # Anticipation of 30 minutes elif (m >= 110) and (m < 140): # Dark delay = -900 # Anticipation of 15 minutes elif (m >= 90 and m < 110): # Ideal delay = 0 # Ideal time, no delay elif (m >= 70 and m < 90): # Bright delay = 1800 # Posticipation of 30 minutes elif (m < 70): # Very bright delay = 3600 # Posticipation of 60 minutes elif type == 'morning': print("Checking morning light condition...") if (m >= 140) and (m < 160): # Very dark delay = 3600 # Posticipation of 60 minutes elif (m >= 110) and (m < 140): # Dark delay = 1800 # Posticipation of 30 minutes elif (m >= 90 and m < 110): # Ideal delay = 0 # Ideal time, no delay elif (m >= 70 and m < 90): # Bright delay = -900 # Anticipation of 15 minutes elif (m < 70): # Very bright delay = -1800 # Anticipation of 30 minutes if delay != 0: functions.post_mod(plantID, hour, 0, delay, url, port)
def get_result(env, hour): """Get data from ThingSpeak adaptor and decide. Get the last entries on wind field and decides if it is necessary or not to modify duration of irrigation. """ url, port, plantID, devID, ts_url, ts_port = functions.read_file(FILE) resource = "wind" time = "minutes" # Check wind trending in previous minutes (short term). tval = str(10) string = ("http://" + ts_url + ":" + ts_port + "/data/" + plantID + "/" + resource + "?time=" + time + "&tval=" + tval + "&plantID=" + plantID + "&devID=" + devID) print(string) data = json.loads(requests.get(string).text) data_short = data["data"] # Check wind trending in previous hours (long term). tval = str(10 * 60) string = ("http://" + ts_url + ":" + ts_port + "/data/" + plantID + "/" + resource + "?time=" + time + "&tval=" + tval + "&plantID=" + plantID + "&devID=" + devID) print(string) data = json.loads(requests.get(string).text) data_long = data["data"] # Wind strategy. val1 = 0 val2 = 0 # During an extended period of time. if data_long != []: m2 = np.mean(data_long) if (m2 >= 3) and (m2 <= 10): # Light wind val2 = 60 # Augment duration by 60 seconds elif m2 > 10: # Strong wind val2 = 120 # Augment duration by 120 seconds else: # No wind val2 = 0 # No modification # In real time. if data_short != []: m1 = np.mean(data_short) if (m1 >= 3) and (m1 <= 10): # Light wind val1 = 90 # Augment duration by 90 seconds elif m1 > 10: # Strong wind val1 = 150 # Augment duration by 150 seconds else: # No wind val1 = 0 # No modification duration = val1 + val2 if duration is not None: functions.post_mod(plantID, hour, duration, 0, url, port)