-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
3 changed files
with
61 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
|
||
*.ini | ||
desktop.ini | ||
scmc/secret.h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,12 +6,10 @@ | |
Made by members of Brown University club "Scientists for a Sustainable World" ([email protected]) 2021 https://github.com/brown-SSW/brown-solar-charger | ||
*/ | ||
|
||
#include <Arduino.h> | ||
#include <WiFi.h> //used for sending stuff over the wifi radio within the esp32 | ||
#include <CircularBuffer.h> //used for having fixed size buffers that discard the oldest data https://github.com/rlogiacco/CircularBuffer | ||
#include <PubSubClient.h> //https://github.com/knolleary/pubsubclient | ||
#include <ESP_Mail_Client.h> //library for sending email https://github.com/mobizt/ESP-Mail-Client | ||
#include <Dusk2Dawn.h> //sunrise sunset lookup https://github.com/dmkishi/Dusk2Dawn remove "static" from library as needed to fix compiling error | ||
#include <Dusk2Dawn.h> //sunrise sunset lookup https://github.com/dmkishi/Dusk2Dawn DOWNLOAD ZIP OF MASTER AND INSTALL MANUALLY SINCE THE RELEASE (1.0.1) IS OUTDATED AND DOESN'T COMPILE! | ||
#include <Firebase_ESP_Client.h> //firebase library https://github.com/mobizt/Firebase-ESP-Client | ||
|
||
#include "secret.h" //passwords and things we don't want public can be kept in this file since it doesn't upload to github (in gitignore) The file should be kept somewhat secure. | ||
|
@@ -22,10 +20,19 @@ boolean timeAvailable = false; | |
boolean firebaseAvailable = false; | ||
boolean firebaseStarted = false; | ||
|
||
boolean muteAllAlerts = false; | ||
boolean firebaseAvailSettings = true; | ||
boolean firebaseAvailSendDebug = true; | ||
boolean firebaseAvailRecvDebug = true; | ||
boolean firebaseAvailSendLive = true; | ||
boolean firebaseAvailDeleteDay = true; | ||
boolean firebaseAvailDay = true; | ||
boolean firebaseAvailDeleteMonth = true; | ||
boolean firebaseAvailMonth = true; | ||
|
||
|
||
boolean muteAllAlerts = true; | ||
boolean firebaseAvailableAlerted = true; | ||
|
||
boolean firebaseAvailableHelper = true; | ||
boolean firebaseRanSomething = false; | ||
|
||
boolean otaEnable = true; | ||
|
@@ -50,19 +57,19 @@ float dayGenWh = 0.0; | |
float dayHoursUsed = 0; | ||
|
||
unsigned long lastLiveUpdateMillis = 0; | ||
long lastLiveUpdateMillisInterval = 30000; | ||
long liveDataUpdateMillisInterval = 30000; | ||
|
||
unsigned long lastDayDataUpdateMillis = 0; | ||
long lastDayDataUpdateMillisInterval = 30000; | ||
long dayDataUpdateMillisInterval = 30000; | ||
|
||
unsigned long lastMonthDataUpdateMillis = 0; | ||
long lastMonthDataUpdateMillisInterval = 100000; | ||
long monthDataUpdateMillisInterval = 100000; //change to daily timer | ||
|
||
unsigned long lastCalcUpdateMillis = 0; | ||
long lastCalcUpdateMillisInterval = 1000; | ||
long calcUpdateMillisInterval = 1000; | ||
|
||
unsigned long lastLoadSettingsMillis = 0; | ||
long lastLoadSettingsMillisInterval = 10000; | ||
long loadSettingsMillisInterval = 10000; | ||
|
||
long wifiCheckIntervalMillis = 5000; | ||
|
||
|
@@ -90,13 +97,20 @@ void loop() { | |
connectFirebase(); | ||
firebaseStarted = true; | ||
} | ||
firebaseAvailableHelper = (timeAvailable && firebaseStarted && wifiAvailable); | ||
runLiveUpdate(); | ||
runDayDataUpdate(); | ||
runMonthDataUpdate(); | ||
runSettingsDebugUpdate(); | ||
if (firebaseRanSomething) { | ||
firebaseAvailable = firebaseAvailableHelper; | ||
if (firebaseRanSomething && firebaseStarted) { | ||
firebaseAvailable = | ||
firebaseAvailSettings && | ||
firebaseAvailSendDebug && | ||
firebaseAvailRecvDebug && | ||
firebaseAvailSendLive && | ||
firebaseAvailDeleteDay && | ||
firebaseAvailDay && | ||
firebaseAvailDeleteMonth && | ||
firebaseAvailMonth; | ||
} | ||
|
||
if (firebaseAvailable) { | ||
|
@@ -121,7 +135,7 @@ void setSafe() { | |
} | ||
|
||
void runCalc() { | ||
if (millis() - lastCalcUpdateMillis > lastCalcUpdateMillisInterval) { | ||
if (millis() - lastCalcUpdateMillis > calcUpdateMillisInterval) { | ||
cumuWhGenHelper += 1.0 * liveGenW * (millis() - lastCalcUpdateMillis) / (1000 * 60 * 60); | ||
cumulativeWhGen += long(cumuWhGenHelper); | ||
cumuWhGenHelper -= long(cumuWhGenHelper); | ||
|
@@ -130,45 +144,32 @@ void runCalc() { | |
} | ||
|
||
void runLiveUpdate() { | ||
if (millis() - lastLiveUpdateMillis > lastLiveUpdateMillisInterval) { | ||
if (millis() - lastLiveUpdateMillis > liveDataUpdateMillisInterval) { | ||
lastLiveUpdateMillis = millis(); | ||
firebaseRanSomething = true; | ||
if (timeAvailable) { // don't want to give inaccurate timestamps | ||
if (!firebaseSendLiveData()) { | ||
firebaseAvailableHelper = false; | ||
} | ||
firebaseAvailSendLive = firebaseSendLiveData(); | ||
} | ||
} | ||
} | ||
|
||
void runSettingsDebugUpdate() { | ||
if (millis() - lastLoadSettingsMillis > lastLoadSettingsMillisInterval) { | ||
if (millis() - lastLoadSettingsMillis > loadSettingsMillisInterval) { | ||
lastLoadSettingsMillis = millis(); | ||
firebaseRanSomething = true; | ||
if (!firebaseGetSettings()) { | ||
firebaseAvailableHelper = false; | ||
} | ||
if (!firebaseRecvDebug()) { | ||
firebaseAvailableHelper = false; | ||
} | ||
if (!firebaseSendDebug()) { | ||
firebaseAvailableHelper = false; | ||
} | ||
firebaseAvailSettings = firebaseGetSettings(); | ||
firebaseAvailRecvDebug = firebaseRecvDebug(); | ||
firebaseAvailSendDebug = firebaseSendDebug(); | ||
} | ||
} | ||
|
||
void runDayDataUpdate() { | ||
|
||
if (millis() - lastDayDataUpdateMillis > lastDayDataUpdateMillisInterval) { | ||
if (millis() - lastDayDataUpdateMillis > dayDataUpdateMillisInterval) { | ||
lastDayDataUpdateMillis = millis(); | ||
firebaseRanSomething = true; | ||
if (timeAvailable) { | ||
if (!firebaseSendDayData()) { | ||
firebaseAvailableHelper = false; | ||
} | ||
if (!firebaseDeleteOldData("/data/dayData/", 24 * 60 * 60, 2)) { | ||
firebaseAvailableHelper = false; | ||
} | ||
firebaseAvailDay = firebaseSendDayData(); | ||
firebaseAvailDeleteDay = firebaseDeleteOldData("/data/dayData/", 24 * 60 * 60, 2); | ||
} | ||
|
||
liveGenW = 10000; | ||
|
@@ -179,16 +180,12 @@ void runDayDataUpdate() { | |
|
||
void runMonthDataUpdate() { | ||
|
||
if (millis() - lastMonthDataUpdateMillis > lastMonthDataUpdateMillisInterval) { | ||
if (millis() - lastMonthDataUpdateMillis > monthDataUpdateMillisInterval) { | ||
lastMonthDataUpdateMillis = millis(); | ||
firebaseRanSomething = true; | ||
if (timeAvailable) { | ||
if (!firebaseSendMonthData()) { | ||
firebaseAvailableHelper = false; | ||
} | ||
if (!firebaseDeleteOldData("/data/monthData/", 31 * 24 * 60 * 60, 2)) { | ||
firebaseAvailableHelper = false; | ||
} | ||
firebaseAvailMonth = firebaseSendMonthData(); | ||
firebaseAvailDeleteMonth = firebaseDeleteOldData("/data/monthData/", 31 * 24 * 60 * 60, 2); | ||
} | ||
//after testing, these variables should actually be reset to 0 for the next day | ||
dayGenWh = random(1400, 2000); | ||
|