Skip to content

Commit

Permalink
commit files
Browse files Browse the repository at this point in the history
  • Loading branch information
joshua-8 committed Jun 4, 2024
1 parent cc3bfc7 commit f8868f1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2023 Brown University Scientists for a Sustainable World
Copyright (c) 2023-2024 Brown University Scientists for a Sustainable World

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
31 changes: 23 additions & 8 deletions src/main.ino
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ int localMinute;

boolean dailyMessageFlag = false;

float batteryPercentage = 0.0;

void setup()
{

Expand Down Expand Up @@ -95,34 +97,47 @@ void loop()
}
localHour = localtime(&utcTime)->tm_hour;
localMinute = localtime(&utcTime)->tm_min;
Serial.println(localHour);
Serial.println(localMinute);
}
/////////////////////////////////////////

if (timeAvailable && Firebase.ready() && (millis() - sendDayDataPrevMillis > 15000 || sendDayDataPrevMillis == 0)) {
sendDayDataPrevMillis = millis();

dayData.time = utcTime;
// dayData.WGen
// dayData.WUse
dayData.batPercent = batteryPercentage;

sendFirebaseDayData(dayData);
firebaseDeleteOldData("/data/dayData", 60, 2);
firebaseDeleteOldData("/data/dayData", 60 * 60 * 24, 2);
}

if (timeAvailable && Firebase.ready() && (millis() - sendMonthDataPrevMillis > 60 * 60 * 2 && localHour == 12 + 8)) {
dailyMessageFlag = true; // arm the daily message flag at 8pm
}
if (timeAvailable && Firebase.ready() && (millis() - sendMonthDataPrevMillis > 15000 || sendMonthDataPrevMillis == 0)) {
if (timeAvailable && Firebase.ready() && (millis() - sendMonthDataPrevMillis > 60 * 60 * 2 && localHour == 12 + 9)) { // send daily data at 9pm (sun has set, but hopefully battery not dead yet)
dailyMessageFlag = false;
sendMonthDataPrevMillis = millis();

monthData.time = utcTime;
// monthData.hUsed
// monthData.WhGen
// monthData.WhUse

sendFirebaseMonthData(monthData);
firebaseDeleteOldData("/data/monthData", 60, 2);
firebaseDeleteOldData("/data/monthData", 60 * 60 * 24 * 30, 2);
}
if (timeAvailable && Firebase.ready() && (millis() - sendLiveDataPrevMillis > 15000 || sendLiveDataPrevMillis == 0)) {
if (timeAvailable && Firebase.ready() && (millis() - sendLiveDataPrevMillis > 300000 || sendLiveDataPrevMillis == 0)) {
sendLiveDataPrevMillis = millis();

liveData.time = utcTime;
liveData.batPercent = batteryPercentage;
// liveData.available
// liveData.WGen
// liveData.WUse
// liveData.cumulativeWhGen

sendFirebaseLiveData(liveData);
firebaseDeleteOldData("/data/liveData", 60, 2);
}
}

Expand All @@ -133,7 +148,7 @@ boolean sendFirebaseLiveData(LiveData liveData)
json.set(F("available"), liveData.available);
json.set(F("WGen"), liveData.WGen);
json.set(F("WUse"), liveData.WUse);
json.set(F("batPercent"), liveData.batPercent);
json.set(F("bat%"), liveData.batPercent);
json.set(F("cumulativeWhGen"), liveData.cumulativeWhGen);
json.set(F("time"), liveData.time);

Expand Down

0 comments on commit f8868f1

Please sign in to comment.