From a874e7b3cf912c713ccb3dc901b18142a50f7324 Mon Sep 17 00:00:00 2001 From: Hendrik Langer Date: Mon, 18 Jun 2018 06:49:07 +0200 Subject: [PATCH] first try at sleeping (unstable) --- src/XD0OTA.h | 4 ++++ src/main.cpp | 37 ++++++++++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/XD0OTA.h b/src/XD0OTA.h index 9fd52eb..e1a77a6 100644 --- a/src/XD0OTA.h +++ b/src/XD0OTA.h @@ -32,6 +32,10 @@ openssl req -x509 -nodes -days 18263 -newkey rsa:2048 -keyout /etc/ssl/private/x openssl x509 -noout -fingerprint -sha1 -inform pem -in /etc/ssl/certs/xd0-fwupdate-selfsigned.crt +scp .pioenvs/nodemcuv2/firmware.bin user@webserver:/var/www/fwupdate/fota/macaddress.bin +and change macaddress.version + + server { listen 444 ssl; listen [::]:444 ssl; diff --git a/src/main.cpp b/src/main.cpp index 6249282..62c79e6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,7 +8,7 @@ #include #include extern "C" { -#include +//#include #include "user_interface.h" } @@ -97,6 +97,8 @@ IPAddress ip, dns, gateway, subnet; char ssid[64]; char password[64]; +volatile bool cansleep = false; + struct __attribute__((packed)) SENSOR_DATA { float temperature; float humidity; @@ -366,12 +368,37 @@ void ICACHE_FLASH_ATTR sendValues() { WiFi.mode(WIFI_OFF); WiFi.forceSleepBegin(); delay(1); // yield(); +} +void fpm_wakup_cb_func1(void) { + ESP.wdtFeed(); + wifi_fpm_close(); +} + +void lightsleep() { + ESP.wdtFeed(); + wifi_station_disconnect(); + wifi_set_opmode(NULL_MODE); + wifi_fpm_set_sleep_type(LIGHT_SLEEP_T); + wifi_fpm_open(); // Enables force sleep + gpio_pin_wakeup_enable(GPIO_ID_PIN(GEIGER_PIN), GPIO_PIN_INTR_HILEVEL); + wifi_fpm_set_wakeup_cb(fpm_wakup_cb_func1); + wifi_fpm_do_sleep(0xFFFFFFF); // Sleep for longest possible time + //delay(1); +} + +void lightsleepwake() { + ESP.wdtFeed(); + wifi_fpm_do_wakeup(); + wifi_fpm_close(); } void ICACHE_RAM_ATTR ISR_geiger_impulse() { +// lightsleepwake(); geiger_counts++; + //DEBUG_MSG("X"); + if(cansleep) lightsleep(); } // will be called every 6 seconds @@ -390,6 +417,8 @@ void setup() { pinMode(LED_BUILTIN, OUTPUT); digitalWrite(LED_BUILTIN, HIGH); // turn OFF board led + //ESP.wdtEnable(30000); + sds.begin(SDS_TX, SDS_RX); sds.mode_mon_300(); @@ -412,7 +441,13 @@ void setup() { } void loop() { + cansleep = false; +// lightsleepwake(); //DEBUG_MSG("%d\n", millis() - last_wifi_activity); sendValues(); + DEBUG_MSG("sleeping now...\n"); + cansleep = true; + lightsleep(); delay(postingInterval); + //ESP.deepSleep(10e6); }