Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
brycegoh committed Nov 4, 2023
1 parent 6e54d13 commit f54923c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
rpi/cloud/*
node_modules
node_modules
.env
8 changes: 3 additions & 5 deletions fire-cloud/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,9 @@ if (!process.env.AWS_ACCESS_KEY_ID || !process.env.AWS_SECRET_ACCESS_KEY) {

const supabase = createClient(SUPABASE_URL, SUPABASE_API_KEY)

function convertEpochToSGT(epochTime) {
function convertEpochToUTC(epochTime) {
const date = new Date(epochTime * 1000);
const utc = date.getTime() + (date.getTimezoneOffset() * 60000);
const singaporeTime = new Date(utc + (3600000 * TIMEZONE_OFFSET));
return singaporeTime.toISOString();
return date.toISOString();
}

function establishConnection() {
Expand Down Expand Up @@ -64,7 +62,7 @@ async function connectAndSubscribe() {
console.log(`Message received on ${topic}:`, messageJson);
let {error} = await supabase.from('firecloud').insert({
node_id: messageJson.id,
timestamp: convertEpochToSGT(messageJson.timestamp),
timestamp: convertEpochToUTC(messageJson.timestamp),
temperature: messageJson.temp,
humidity: messageJson.humidity,
air_quality_ppm: messageJson.air,
Expand Down

0 comments on commit f54923c

Please sign in to comment.