diff --git a/lambda/lambda_function.py b/lambda/lambda_function.py index 1755798..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 +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 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"""