Mostly running main loop and FSM. Call of sensor functions does not work yet.
This commit is contained in:
parent
0cb4212fc8
commit
0482db2f21
2 changed files with 24 additions and 10 deletions
|
@ -21,6 +21,7 @@
|
|||
#define FSM_STATE_WU 0
|
||||
#define FSM_STATE_WSE 1
|
||||
#define FSM_STATE_RS 2
|
||||
#define FSM_STATE_WC 3
|
||||
#define FSM_STATE_WS 4
|
||||
#define FSM_STATE_US 5
|
||||
#define FSM_STATE_SC 6
|
||||
|
|
|
@ -153,8 +153,8 @@ void initSensors()
|
|||
//Temperature + pressure
|
||||
if (sensor_bme280_begin(BME_ADDRESS)) {
|
||||
sensors[SENSOR_TEMPERATURE] = &bme280_temperature;
|
||||
sensors[SENSOR_HUMIDITY] = &bme280_humidity;
|
||||
sensors[SENSOR_PRESSURE] = &bme280_pressure;
|
||||
sensors[SENSOR_HUMIDITY] = &bme280_humidity;
|
||||
sensors[SENSOR_PRESSURE] = &bme280_pressure;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -163,9 +163,9 @@ void initSensors()
|
|||
#endif
|
||||
|
||||
#ifdef SENSOR_BATTERY
|
||||
sensors[SENSOR_BAT_VOLTAGE] = &battery_voltage;
|
||||
sensors[SENSOR_BAT_VOLTAGE] = &battery_voltage;
|
||||
sensors[SENSOR_BATCHARGESTATE] = &battery_charging;
|
||||
sensors[SENSOR_ESAVEMODE] = &isEnergySavingMode;
|
||||
sensors[SENSOR_ESAVEMODE] = &isEnergySavingMode;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -207,16 +207,19 @@ void wifiConnect()
|
|||
|
||||
while (!wifiManager.autoConnect(wifiName.c_str(), "DEADBEEF"))
|
||||
{
|
||||
// If autoconnect to WLAN failed and no client connected, go to deep sleep
|
||||
|
||||
#ifdef SLEEP_IF_NO_WLAN_CONNECTION
|
||||
// If autoconnect to WLAN failed and no client connected, go to deep sleep
|
||||
ESP.deepSleep(POWERSAVING_SLEEP_S * 1000000, WAKE_RF_DEFAULT);
|
||||
delay(100);
|
||||
#endif
|
||||
|
||||
#ifndef SLEEP_IF_NO_WLAN_CONNECTION
|
||||
// sleep a few seconds and go on trying to connect
|
||||
debug("WiFi connection failed, try again in 5 seconds...");
|
||||
delay(5000);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -227,7 +230,8 @@ void wifiConnect()
|
|||
void criticalBatCheck()
|
||||
{
|
||||
float volt = battery_voltage();
|
||||
if (volt <= BAT_EMERGENCY_DEEPSLEEP_VOLTAGE) {
|
||||
if (volt <= BAT_EMERGENCY_DEEPSLEEP_VOLTAGE)
|
||||
{
|
||||
debug("Bat Voltage: " + String(volt) + " V");
|
||||
debug("Low battery, going into deep sleep.");
|
||||
// Casting to an unsigned int, so it fits into the integer range
|
||||
|
@ -246,8 +250,6 @@ void loop()
|
|||
ESP.wdtFeed();
|
||||
#endif
|
||||
|
||||
wifiConnectionCheck();
|
||||
|
||||
#ifdef BATTERY_POWERED
|
||||
delay(50);
|
||||
return;
|
||||
|
@ -308,6 +310,11 @@ void _loop()
|
|||
ESP.restart();
|
||||
}
|
||||
#endif
|
||||
fsm_state = FSM_STATE_WC;
|
||||
break;
|
||||
|
||||
case FSM_STATE_WC:
|
||||
wifiConnectionCheck();
|
||||
fsm_state = FSM_STATE_WS;
|
||||
break;
|
||||
|
||||
|
@ -332,9 +339,15 @@ void _loop()
|
|||
if ((update_sensor_cnt + (UPDATE_SENSOR_INTERVAL_S * 1000)) <= millis())
|
||||
{
|
||||
debug("read sensor data " + String(sensor_cnt));
|
||||
if (sensors[sensor_cnt]) {
|
||||
currentSensorData[sensor_cnt] = sensors[sensor_cnt]();
|
||||
if (sensors[sensor_cnt])
|
||||
{
|
||||
debug("sensors[" + String(sensor_cnt) + "]=" + String((int)sensors[sensor_cnt]));
|
||||
//currentSensorData[sensor_cnt] = sensors[sensor_cnt]();
|
||||
currentSensorData[sensor_cnt] = sensor_cnt;
|
||||
|
||||
} else {
|
||||
|
||||
debug("sensors[" + String(sensor_cnt) + "]=nan");
|
||||
currentSensorData[sensor_cnt] = nan("no value");
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue