From 8ee713b616f6b47192e3cb4078db93408c20597f Mon Sep 17 00:00:00 2001 From: Gunnar Skjold Date: Wed, 22 Jan 2020 15:26:07 +0100 Subject: [PATCH 1/3] Included some code from @dakarym to support the self powered board for testing --- src/AmsToMqttBridge.ino | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/AmsToMqttBridge.ino b/src/AmsToMqttBridge.ino index 69ce40c6..0160c227 100644 --- a/src/AmsToMqttBridge.ino +++ b/src/AmsToMqttBridge.ino @@ -4,9 +4,7 @@ Author: roarf */ - -//#define HAS_DALLAS_TEMP_SENSOR 1 // Set to zero if Dallas one wire temp sensor is not present -//#define IS_CUSTOM_AMS_BOARD 1 // Set to zero if using NodeMCU or board not designed by Roar Fredriksen +ADC_MODE(ADC_VCC); #include #include @@ -77,6 +75,15 @@ void setup() { debugger->println("Started..."); } + if (ESP.getVcc() < 3300) { + if(debugger) { + debugger->print("Voltage is too low: "); + debugger->print(ESP.getVcc()); + debugger->println("v"); + } + ESP.deepSleep(5000000); //Deep sleep for 5 seconds to allow output cap to charge up + } + // Flash the LED, to indicate we can boot as AP now pinMode(LED_PIN, OUTPUT); led_on(); From aef78962fb63b3fc62545ea424acf35480900f47 Mon Sep 17 00:00:00 2001 From: Gunnar Skjold Date: Thu, 23 Jan 2020 18:47:02 +0100 Subject: [PATCH 2/3] Some modifications to reduce power consumption i AP mode --- lib/HanConfigAp/src/HanConfigAp.cpp | 7 ++++--- src/AmsToMqttBridge.ino | 12 ++++++++++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/HanConfigAp/src/HanConfigAp.cpp b/lib/HanConfigAp/src/HanConfigAp.cpp index 8cfeef96..daa09dda 100644 --- a/lib/HanConfigAp/src/HanConfigAp.cpp +++ b/lib/HanConfigAp/src/HanConfigAp.cpp @@ -28,8 +28,8 @@ void HanConfigAp::setup(int accessPointButtonPin, Stream* debugger) // Assign pin for boot as AP pinMode(accessPointButtonPin, INPUT_PULLUP); - // Test if we're holding down the AP pin, over 5 seconds - int time = millis() + 5000; + // Test if we're holding down the AP pin, over 1 second + int time = millis() + 1000; print("Press the AP button now to boot as access point"); while (millis() < time) { @@ -55,8 +55,9 @@ void HanConfigAp::setup(int accessPointButtonPin, Stream* debugger) WiFi.mode(WIFI_OFF); delay(2000); - WiFi.softAP(AP_SSID); WiFi.mode(WIFI_AP); + WiFi.setOutputPower(0); + WiFi.softAP(AP_SSID); /* Setup the DNS server redirecting all the domains to this IP */ dnsServer.setErrorReplyCode(DNSReplyCode::NoError); diff --git a/src/AmsToMqttBridge.ino b/src/AmsToMqttBridge.ino index 0160c227..9f0c56e7 100644 --- a/src/AmsToMqttBridge.ino +++ b/src/AmsToMqttBridge.ino @@ -73,13 +73,16 @@ void setup() { while (!debugger); debugger->println(""); debugger->println("Started..."); + debugger->print("Voltage: "); + debugger->print(ESP.getVcc()); + debugger->println("mV"); } if (ESP.getVcc() < 3300) { if(debugger) { debugger->print("Voltage is too low: "); debugger->print(ESP.getVcc()); - debugger->println("v"); + debugger->println("mV"); } ESP.deepSleep(5000000); //Deep sleep for 5 seconds to allow output cap to charge up } @@ -138,8 +141,11 @@ void loop() else { // Continously flash the LED when AP mode - if (millis() / 1000 % 2 == 0) led_on(); + if (millis() / 50 % 64 == 0) led_on(); else led_off(); + + // Make sure there is enough power to run + delay(max(10, 3500-ESP.getVcc())); } ws.loop(); } @@ -229,6 +235,7 @@ void readHanPort() json["id"] = WiFi.macAddress(); json["up"] = millis(); json["t"] = time; + json["vcc"] = ((double) ESP.getVcc()) / 1000; // Add a sub-structure to the json object, // to keep the data from the meter itself @@ -372,6 +379,7 @@ void sendMqttData(String data) json["id"] = WiFi.macAddress(); json["up"] = millis(); json["data"] = data; + json["vcc"] = ((double) ESP.getVcc()) / 1000; // Stringify the json String msg; From 27cb5dd8333b8178d35227358e0169157d153948 Mon Sep 17 00:00:00 2001 From: Gunnar Skjold Date: Thu, 6 Feb 2020 19:15:06 +0100 Subject: [PATCH 3/3] Trying a large sleep when cap is not charged --- src/AmsToMqttBridge.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/AmsToMqttBridge.ino b/src/AmsToMqttBridge.ino index 1545f374..9adaddfb 100644 --- a/src/AmsToMqttBridge.ino +++ b/src/AmsToMqttBridge.ino @@ -97,7 +97,7 @@ void setup() { debugger->print(ESP.getVcc()); debugger->println("mV"); } - ESP.deepSleep(5000000); //Deep sleep for 5 seconds to allow output cap to charge up + ESP.deepSleep(10000000); //Deep sleep to allow output cap to charge up } // Flash the LED, to indicate we can boot as AP now