manual merge
This commit is contained in:
commit
845e637c59
2 changed files with 53 additions and 19 deletions
|
@ -17,8 +17,11 @@
|
|||
#define UPDATE_WEBSERVER_INTVERVAL_S 1
|
||||
#define DELAY_LOOP_MS 50
|
||||
#define POWERSAVING_SLEEP_S 600
|
||||
#define EMERGENCY_SLEEP_S 172800 // Sleep for 2 days to recover
|
||||
#define ENERGY_SAVING_ITERATIONS 30
|
||||
|
||||
#define BAT_LOW_VOLTAGE 3.4
|
||||
#define BAT_LOW_VOLTAGE 3.6
|
||||
#define BAT_EMERGENCY_DEEPSLEEP_VOLTAGE 3.5
|
||||
|
||||
#define STATUS_LED_PIN BUILTIN_LED
|
||||
#define ANEMOMETER_PIN D7
|
||||
|
@ -29,6 +32,7 @@
|
|||
#define BME_CS 10
|
||||
|
||||
#define INITIAL_WEBSERVER_TIME 20
|
||||
#define WEBUPDATER_FEATURE 0
|
||||
|
||||
#define SEALEVELPRESSURE_HPA (1013.25)
|
||||
|
||||
|
@ -41,6 +45,4 @@ const char *INFLUXDB_DB = "weatherstation";
|
|||
const char *INFLUXDB_USER = "oko";
|
||||
const char *INFLUXDB_PASS = "de1873a0d2f8f21f17cf4d8db4f65c59";
|
||||
|
||||
String DEVICE_NAME = "klaute";
|
||||
|
||||
|
||||
String DEVICE_NAME = "aaron";
|
||||
|
|
|
@ -37,6 +37,7 @@ float currentSensorData[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
|
|||
|
||||
uint16_t update_sensor_cnt = 0;
|
||||
uint16_t update_webserver_cnt = 0;
|
||||
uint16_t energySavingIterations = 0;
|
||||
|
||||
WiFiManager wifiManager;
|
||||
Influxdb influxdb(INFLUXDB_HOST, INFLUXDB_PORT);
|
||||
|
@ -48,7 +49,6 @@ String localIP = "127.0.0.1";
|
|||
//*************************************************************************//
|
||||
|
||||
void setup() {
|
||||
|
||||
//WiFi.disconnect(); // erase the wifi credentials
|
||||
|
||||
#ifdef DEBUG
|
||||
|
@ -60,7 +60,7 @@ void setup() {
|
|||
pinMode(ANEMOMETER_PIN, INPUT_PULLUP);
|
||||
pinMode(A0, INPUT);
|
||||
|
||||
digitalWrite(STATUS_LED_PIN, HIGH);
|
||||
digitalWrite(STATUS_LED_PIN, LOW);
|
||||
|
||||
lowBatCheck(getBatteryVoltage());
|
||||
|
||||
|
@ -68,7 +68,6 @@ void setup() {
|
|||
String wifiName = "oko-weather-" + String(ESP.getChipId());
|
||||
|
||||
wifiManager.setMinimumSignalQuality(15);
|
||||
|
||||
wifiManager.setConnectTimeout(60); // the time in seconds to wait for the known wifi connection
|
||||
wifiManager.setTimeout(60); // the time in seconds to wait for the user to configure the device
|
||||
|
||||
|
@ -100,11 +99,12 @@ void setup() {
|
|||
while (1);
|
||||
}
|
||||
|
||||
#ifdef WEBUPDATER_FEATURE
|
||||
#ifndef POWERSAVING
|
||||
setupWebUpdater();
|
||||
#endif
|
||||
|
||||
localIP = WiFi.localIP().toString();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
delay(100);
|
||||
|
||||
|
@ -113,7 +113,7 @@ void setup() {
|
|||
|
||||
digitalWrite(STATUS_LED_PIN, LOW);
|
||||
|
||||
lowBatCheck(currentSensorData[SENSOR_BAT_VOLTAGE]);
|
||||
criticalBatCheck();
|
||||
|
||||
WiFi.mode(WIFI_OFF);
|
||||
WiFi.forceSleepBegin();
|
||||
|
@ -123,41 +123,66 @@ void setup() {
|
|||
delay(100);
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
//*************************************************************************//
|
||||
|
||||
void lowBatCheck(float v)
|
||||
{
|
||||
if (v <= BAT_LOW_VOLTAGE)
|
||||
{
|
||||
void criticalBatCheck() {
|
||||
if (currentSensorData[SENSOR_BAT_VOLTAGE] <= BAT_EMERGENCY_DEEPSLEEP_VOLTAGE) {
|
||||
#ifdef DEBUG
|
||||
Serial.println("Low battery, going into deep sleep.");
|
||||
#endif
|
||||
ESP.deepSleep(4294967295); // battery low, shutting down
|
||||
ESP.deepSleep(EMERGENCY_SLEEP_S * 1000000); // battery low, shutting down
|
||||
delay(100);
|
||||
}
|
||||
}
|
||||
|
||||
int energySavingMode() {
|
||||
// Give the solar panel some time to load the cell to prevent
|
||||
// flapping.
|
||||
if (energySavingIterations > 0) {
|
||||
energySavingIterations--;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Is the battery low?
|
||||
if (currentSensorData[SENSOR_BAT_VOLTAGE] <= BAT_LOW_VOLTAGE) {
|
||||
// Entering energy saving
|
||||
if (energySavingIterations == 0) {
|
||||
energySavingIterations = ENERGY_SAVING_ITERATIONS;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void loop() {
|
||||
criticalBatCheck();
|
||||
|
||||
#ifdef POWERSAVING
|
||||
delay(50);
|
||||
return;
|
||||
#endif
|
||||
|
||||
#ifdef WEBUPDATER_FEATURE
|
||||
if (UPDATE_WEBSERVER_INTVERVAL_S * 1000 / DELAY_LOOP_MS <= update_webserver_cnt) {
|
||||
update_webserver_cnt = 0;
|
||||
doWebUpdater();
|
||||
}
|
||||
#endif
|
||||
|
||||
_loop();
|
||||
|
||||
delay(DELAY_LOOP_MS);
|
||||
|
||||
|
||||
update_sensor_cnt++;
|
||||
|
||||
#ifdef WEBUPDATER_FEATURE
|
||||
update_webserver_cnt++;
|
||||
#endif
|
||||
}
|
||||
|
||||
void _loop() {
|
||||
|
@ -170,7 +195,13 @@ void _loop() {
|
|||
currentSensorData[SENSOR_TEMPERATURE] = fetchTemperature();
|
||||
currentSensorData[SENSOR_HUMIDITY] = fetchHumidity();
|
||||
currentSensorData[SENSOR_LIGHT] = fetchLight();
|
||||
currentSensorData[SENSOR_WINDSPEED] = fetchWindspeed();
|
||||
|
||||
// Disable expensive tasks
|
||||
if (energySavingMode() == 0) {
|
||||
currentSensorData[SENSOR_WINDSPEED] = fetchWindspeed();
|
||||
} else {
|
||||
currentSensorData[SENSOR_WINDSPEED] = -1;
|
||||
}
|
||||
currentSensorData[SENSOR_PRESSURE] = fetchPressure();
|
||||
currentSensorData[SENSOR_BAT_VOLTAGE] = getBatteryVoltage();
|
||||
|
||||
|
@ -188,13 +219,14 @@ void _loop() {
|
|||
delay(100);
|
||||
|
||||
pushToInfluxDB(DEVICE_NAME, currentSensorData);
|
||||
|
||||
|
||||
#ifdef WEBUPDATER_FEATURE
|
||||
#ifndef POWERSAVING
|
||||
setSensorData(DEVICE_NAME, localIP, currentSensorData);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
//*************************************************************************//
|
||||
|
||||
|
|
Loading…
Reference in a new issue