Skip to content

Commit

Permalink
Merge branch 'main' into prod-lambda
Browse files Browse the repository at this point in the history
  • Loading branch information
Fruittips committed Nov 27, 2023
2 parents 9e3e9be + c0c32dc commit 7650472
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
17 changes: 14 additions & 3 deletions lambda/lambda_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion node.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions sensors/lib/mq135.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"""
Expand Down

0 comments on commit 7650472

Please sign in to comment.