Skip to content

Commit

Permalink
added nodeid to rpc
Browse files Browse the repository at this point in the history
  • Loading branch information
brycegoh committed Nov 27, 2023
1 parent 6ce5bef commit b59f7be
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
7 changes: 4 additions & 3 deletions fire-cloud/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ async function connectAndSubscribe() {
const messageJson = JSON.parse(messageString);
console.log(`Message received on ${topic}:`, messageJson);

const nodeId = messageJson.id;
const temperature = messageJson.temp;
const humidity = messageJson.humidity;
const airQualityPpm = messageJson.air;
Expand All @@ -109,9 +110,8 @@ async function connectAndSubscribe() {

//invoke lambda function to calculate fire probability and update database
const rowId = data[0].id;
const lambdaRes = await invokeAnalytics(rowId, temperature, flameSensorValue);
const lambdaRes = await invokeAnalytics(nodeId, rowId, temperature, flameSensorValue);

const nodeId = messageJson.id;
const fireProbability = lambdaRes.fire_probability;

if (fireProbability === null) {
Expand Down Expand Up @@ -176,11 +176,12 @@ async function publishMessage(topic, message) {
}

// Function to invoke the Analytics lambda function to calculate the fire probability and update the database
async function invokeAnalytics(rowId, temp, flameValue) {
async function invokeAnalytics(nodeId, rowId, temp, flameValue) {
console.log("Invoking lambda function...");
const command = new InvokeCommand({
FunctionName: "greendot-analytics",
Payload: JSON.stringify({
nodeId: nodeId,
rowId: rowId,
temp: temp,
flame: flameValue,
Expand Down
3 changes: 2 additions & 1 deletion lambda/lambda_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
PAST_RECORDS_DURATION = 3 # in minutes TODO: change such that we can sample >= 25 past records (e.g. sampling interval * 25)

def lambda_handler(event, context):
nodeId = event.get('nodeId')
rowId = event.get('rowId')
temp = event.get('temp')
flame = event.get('flame')

# get past records from supabase
temp_hum_aq_res = None
try:
temp_hum_aq_res = supabase.rpc("get_past_records", {"interval_string": f"{PAST_RECORDS_DURATION} minutes", }).execute()
temp_hum_aq_res = supabase.rpc("get_past_records", {"interval_string": f"{PAST_RECORDS_DURATION} minutes", "node_id": nodeId}).execute()
except Exception as e:
print(f"Error getting past records supabase: {e}")

Expand Down

0 comments on commit b59f7be

Please sign in to comment.