mirror of
https://github.com/UtilitechAS/amsreader-firmware.git
synced 2026-01-28 13:08:57 +00:00
Fixed ESP32 crash with RemoteDebug and unformatted SPIFFS. Added battery voltage for Lolin D32 and moved ESP_VCC_CALIB_FACTOR to cover all boards
This commit is contained in:
@@ -71,18 +71,10 @@ void setup() {
|
||||
Serial.begin(115200);
|
||||
#endif
|
||||
|
||||
if(config.hasConfig()) {
|
||||
if(config.getAuthSecurity() > 0) {
|
||||
Debug.setPassword(config.getAuthPassword());
|
||||
}
|
||||
if(config.hasConfig() && config.isDebugSerial()) {
|
||||
Debug.setSerialEnabled(config.isDebugSerial());
|
||||
Debug.begin(config.getWifiHostname(), (uint8_t) config.getDebugLevel());
|
||||
if(!config.isDebugTelnet()) {
|
||||
Debug.stop();
|
||||
}
|
||||
} else {
|
||||
#if DEBUG_MODE
|
||||
Debug.begin("localhost", RemoteDebug::DEBUG);
|
||||
Debug.setSerialEnabled(true);
|
||||
#endif
|
||||
}
|
||||
@@ -94,7 +86,7 @@ void setup() {
|
||||
debugI("Voltage: %.2fV", vcc);
|
||||
}
|
||||
|
||||
if (vcc > 0 && vcc < 3.25) {
|
||||
if (vcc > 2.5 && vcc < 3.25) { // Only sleep if voltage is realistic and too low
|
||||
if(Debug.isActive(RemoteDebug::INFO)) {
|
||||
debugI("Votltage is too low, sleeping");
|
||||
Serial.flush();
|
||||
@@ -117,7 +109,16 @@ void setup() {
|
||||
WiFi.softAPdisconnect(true);
|
||||
WiFi.mode(WIFI_OFF);
|
||||
|
||||
if(SPIFFS.begin()) {
|
||||
bool spiffs = false;
|
||||
#if defined(ESP32)
|
||||
debugD("ESP32 SPIFFS");
|
||||
spiffs = SPIFFS.begin(true);
|
||||
#else
|
||||
debugD("ESP8266 SPIFFS");
|
||||
spiffs = SPIFFS.begin();
|
||||
#endif
|
||||
|
||||
if(spiffs) {
|
||||
bool flashed = false;
|
||||
if(SPIFFS.exists("/firmware.bin")) {
|
||||
if(Debug.isActive(RemoteDebug::INFO)) debugI("Found firmware");
|
||||
@@ -295,10 +296,18 @@ void loop() {
|
||||
|
||||
if (WiFi.status() != WL_CONNECTED) {
|
||||
wifiConnected = false;
|
||||
Debug.stop();
|
||||
WiFi_connect();
|
||||
} else {
|
||||
if(!wifiConnected) {
|
||||
wifiConnected = true;
|
||||
if(config.getAuthSecurity() > 0) {
|
||||
Debug.setPassword(config.getAuthPassword());
|
||||
}
|
||||
Debug.begin(config.getWifiHostname(), (uint8_t) config.getDebugLevel());
|
||||
if(!config.isDebugTelnet()) {
|
||||
Debug.stop();
|
||||
}
|
||||
if(Debug.isActive(RemoteDebug::INFO)) {
|
||||
debugI("Successfully connected to WiFi!");
|
||||
debugI("IP: %s", WiFi.localIP().toString().c_str());
|
||||
|
||||
@@ -1,16 +1,20 @@
|
||||
#include "HwTools.h"
|
||||
|
||||
double HwTools::getVcc() {
|
||||
double volts = 0.0;
|
||||
#if defined(ARDUINO_ESP8266_WEMOS_D1MINI)
|
||||
return (((double) ESP.getVcc()) / 900); // This board has a voltage divider on VCC. Yes, 900 is correct
|
||||
volts = (((double) ESP.getVcc()) / 900.0); // This board has a voltage divider on VCC.
|
||||
#elif defined(ARDUINO_LOLIN_D32)
|
||||
volts = (analogRead(GPIO_NUM_35) / 4095.0) * 3.3 * 2.25; // We are actually reading battery voltage here
|
||||
#elif defined(ESP8266)
|
||||
#if defined(ESP_VCC_CALIB_FACTOR)
|
||||
return ((double) ESP.getVcc()) / 1024 * ESP_VCC_CALIB_FACTOR;
|
||||
#else
|
||||
return ((double) ESP.getVcc()) / 1024;
|
||||
#endif
|
||||
volts = ((double) ESP.getVcc()) / 1024.0;
|
||||
#endif
|
||||
|
||||
#if defined(ESP_VCC_CALIB_FACTOR)
|
||||
return volts * ESP_VCC_CALIB_FACTOR;
|
||||
#else
|
||||
return volts;
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
|
||||
double HwTools::getTemperature() {
|
||||
|
||||
@@ -31,6 +31,9 @@ public:
|
||||
int getWifiRssi();
|
||||
|
||||
HwTools() {
|
||||
#if defined(ARDUINO_LOLIN_D32)
|
||||
pinMode(GPIO_NUM_35, INPUT);
|
||||
#endif
|
||||
oneWire = new OneWire(TEMP_SENSOR_PIN);
|
||||
tempSensor = new DallasTemperature(this->oneWire);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user