feature/http_call_send_json #3
2 changed files with 24 additions and 10 deletions
|
@ -21,6 +21,7 @@
|
||||||
#define FSM_STATE_WU 0
|
#define FSM_STATE_WU 0
|
||||||
#define FSM_STATE_WSE 1
|
#define FSM_STATE_WSE 1
|
||||||
#define FSM_STATE_RS 2
|
#define FSM_STATE_RS 2
|
||||||
|
#define FSM_STATE_WC 3
|
||||||
#define FSM_STATE_WS 4
|
#define FSM_STATE_WS 4
|
||||||
#define FSM_STATE_US 5
|
#define FSM_STATE_US 5
|
||||||
#define FSM_STATE_SC 6
|
#define FSM_STATE_SC 6
|
||||||
|
|
|
@ -207,16 +207,19 @@ void wifiConnect()
|
||||||
|
|
||||||
while (!wifiManager.autoConnect(wifiName.c_str(), "DEADBEEF"))
|
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
|
#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);
|
ESP.deepSleep(POWERSAVING_SLEEP_S * 1000000, WAKE_RF_DEFAULT);
|
||||||
delay(100);
|
delay(100);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef SLEEP_IF_NO_WLAN_CONNECTION
|
#ifndef SLEEP_IF_NO_WLAN_CONNECTION
|
||||||
// sleep a few seconds and go on trying to connect
|
// sleep a few seconds and go on trying to connect
|
||||||
debug("WiFi connection failed, try again in 5 seconds...");
|
debug("WiFi connection failed, try again in 5 seconds...");
|
||||||
delay(5000);
|
delay(5000);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -227,7 +230,8 @@ void wifiConnect()
|
||||||
void criticalBatCheck()
|
void criticalBatCheck()
|
||||||
{
|
{
|
||||||
float volt = battery_voltage();
|
float volt = battery_voltage();
|
||||||
if (volt <= BAT_EMERGENCY_DEEPSLEEP_VOLTAGE) {
|
if (volt <= BAT_EMERGENCY_DEEPSLEEP_VOLTAGE)
|
||||||
|
{
|
||||||
debug("Bat Voltage: " + String(volt) + " V");
|
debug("Bat Voltage: " + String(volt) + " V");
|
||||||
debug("Low battery, going into deep sleep.");
|
debug("Low battery, going into deep sleep.");
|
||||||
// Casting to an unsigned int, so it fits into the integer range
|
// Casting to an unsigned int, so it fits into the integer range
|
||||||
|
@ -246,8 +250,6 @@ void loop()
|
||||||
ESP.wdtFeed();
|
ESP.wdtFeed();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
wifiConnectionCheck();
|
|
||||||
|
|
||||||
#ifdef BATTERY_POWERED
|
#ifdef BATTERY_POWERED
|
||||||
delay(50);
|
delay(50);
|
||||||
return;
|
return;
|
||||||
|
@ -308,6 +310,11 @@ void _loop()
|
||||||
ESP.restart();
|
ESP.restart();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
fsm_state = FSM_STATE_WC;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case FSM_STATE_WC:
|
||||||
|
wifiConnectionCheck();
|
||||||
fsm_state = FSM_STATE_WS;
|
fsm_state = FSM_STATE_WS;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -332,9 +339,15 @@ void _loop()
|
||||||
if ((update_sensor_cnt + (UPDATE_SENSOR_INTERVAL_S * 1000)) <= millis())
|
if ((update_sensor_cnt + (UPDATE_SENSOR_INTERVAL_S * 1000)) <= millis())
|
||||||
{
|
{
|
||||||
debug("read sensor data " + String(sensor_cnt));
|
debug("read sensor data " + String(sensor_cnt));
|
||||||
if (sensors[sensor_cnt]) {
|
if (sensors[sensor_cnt])
|
||||||
currentSensorData[sensor_cnt] = 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 {
|
} else {
|
||||||
|
|
||||||
|
debug("sensors[" + String(sensor_cnt) + "]=nan");
|
||||||
currentSensorData[sensor_cnt] = nan("no value");
|
currentSensorData[sensor_cnt] = nan("no value");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue