From 4a3eaf62cdb3483423436567831bd8afc6a13015 Mon Sep 17 00:00:00 2001 From: Fruittips Date: Mon, 27 Nov 2023 00:45:19 +0800 Subject: [PATCH 1/3] added TODO for lambda --- lambda/lambda_function.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lambda/lambda_function.py b/lambda/lambda_function.py index 1755798..ebf3e68 100644 --- a/lambda/lambda_function.py +++ b/lambda/lambda_function.py @@ -8,7 +8,7 @@ SUPABASE_KEY = os.environ.get("SUPABASE_KEY") supabase: Client = create_client(SUPABASE_URL, SUPABASE_KEY) -PAST_RECORDS_DURATION = 5 # in minutes +PAST_RECORDS_DURATION = 5 # in minutes TODO: change such that we can sample >= 25 past records (e.g. sampling interval * 25) def lambda_handler(event, context): rowId = event.get('rowId') From f773d919254b17018e2760e25e9c0685d3f8507c Mon Sep 17 00:00:00 2001 From: Fruittips Date: Mon, 27 Nov 2023 14:14:06 +0800 Subject: [PATCH 2/3] updated mq135 lib --- sensors/lib/mq135.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/sensors/lib/mq135.py b/sensors/lib/mq135.py index 730aa7e..94f68c3 100644 --- a/sensors/lib/mq135.py +++ b/sensors/lib/mq135.py @@ -18,7 +18,6 @@ class MQ135(object): RLOAD = 10.0 # Calibration resistance at atmospheric CO2 level RZERO = 76.63 - RZERO = 10 # Parameters for calculating ppm of CO2 from sensor resistance PARA = 116.6020682 PARB = 2.769034857 @@ -73,8 +72,7 @@ def get_corrected_ppm(self, temperature, humidity): corrected for temperature/humidity""" corrected_rzero = self.get_corrected_rzero(temperature,humidity) corrected_resistance = self.get_corrected_resistance(temperature, humidity) -# return self.PARA * math.pow((self.get_corrected_resistance(temperature, humidity)/ self.RZERO), -self.PARB) - return round(self.PARA * math.pow((corrected_resistance/self.RZERO), -self.PARB),3) + return self.PARA * math.pow((self.get_corrected_resistance(temperature, humidity)/ self.RZERO), -self.PARB) def get_rzero(self): """Returns the resistance RZero of the sensor (in kOhms) for calibratioin purposes""" From c0c32dc0e616e0faadb49d933bf570e20847a404 Mon Sep 17 00:00:00 2001 From: Fruittips Date: Mon, 27 Nov 2023 14:14:31 +0800 Subject: [PATCH 3/3] update lambda function --- lambda/lambda_function.py | 17 ++++++++++++++--- node.py | 2 +- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/lambda/lambda_function.py b/lambda/lambda_function.py index ebf3e68..15ecce0 100644 --- a/lambda/lambda_function.py +++ b/lambda/lambda_function.py @@ -8,7 +8,7 @@ SUPABASE_KEY = os.environ.get("SUPABASE_KEY") supabase: Client = create_client(SUPABASE_URL, SUPABASE_KEY) -PAST_RECORDS_DURATION = 5 # in minutes TODO: change such that we can sample >= 25 past records (e.g. sampling interval * 25) +PAST_RECORDS_DURATION = 13 # in minutes TODO: change such that we can sample >= 25 past records (e.g. sampling interval * 25) def lambda_handler(event, context): rowId = event.get('rowId') @@ -37,13 +37,24 @@ def lambda_handler(event, context): r_value = None fire_probability = 0 - if len(temp_arr) != 0 or len(humidity_arr) != 0: + + if len(temp_arr) >= 0 and len(humidity_arr) > 0: r_value = get_r_value(temp_arr, humidity_arr) + + # if less than 25 records, dont calculate r value and return default fire probability + else: + return json.dumps({ + 'statusCode': 200, + 'body': json.dumps({ + 'fire_probability': fire_probability, + 'r_value': r_value, + }) + }) if len(aq_arr) != 0 and r_value != None: fire_probability = get_fire_probability(temp, aq_arr, flame, r_value) - #update row in supabase table with r_value and fire_probability + # TODO: update row in supabase table with r_value and fire_probability try: data, count = supabase.table('firecloud') \ .update({ diff --git a/node.py b/node.py index 4a75fa8..64c3e3d 100644 --- a/node.py +++ b/node.py @@ -18,7 +18,7 @@ _DEVICE_NAME = _DEVICE_NAME_PREFIX + str(_NODE_ID) # Sampling intervals -_SAMPLING_INTERVAL_LOW = 60 # change to 30s in demo +_SAMPLING_INTERVAL_LOW = 30 # Actual: 60s, Demo: 30s _SAMPLING_INTERVAL_HIGH = 5 # Frequencies