Browse Source

first try at sleeping (unstable)

lightsleep
Hendrik Langer 7 years ago
parent
commit
a874e7b3cf
  1. 4
      src/XD0OTA.h
  2. 37
      src/main.cpp

4
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 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 { server {
listen 444 ssl; listen 444 ssl;
listen [::]:444 ssl; listen [::]:444 ssl;

37
src/main.cpp

@ -8,7 +8,7 @@
#include <ESP8266WiFi.h> #include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h> #include <ESP8266WiFiMulti.h>
extern "C" { extern "C" {
#include <espnow.h> //#include <espnow.h>
#include "user_interface.h" #include "user_interface.h"
} }
@ -97,6 +97,8 @@ IPAddress ip, dns, gateway, subnet;
char ssid[64]; char ssid[64];
char password[64]; char password[64];
volatile bool cansleep = false;
struct __attribute__((packed)) SENSOR_DATA { struct __attribute__((packed)) SENSOR_DATA {
float temperature; float temperature;
float humidity; float humidity;
@ -366,12 +368,37 @@ void ICACHE_FLASH_ATTR sendValues() {
WiFi.mode(WIFI_OFF); WiFi.mode(WIFI_OFF);
WiFi.forceSleepBegin(); WiFi.forceSleepBegin();
delay(1); // yield(); 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() { void ICACHE_RAM_ATTR ISR_geiger_impulse() {
// lightsleepwake();
geiger_counts++; geiger_counts++;
//DEBUG_MSG("X");
if(cansleep) lightsleep();
} }
// will be called every 6 seconds // will be called every 6 seconds
@ -390,6 +417,8 @@ void setup() {
pinMode(LED_BUILTIN, OUTPUT); pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH); // turn OFF board led digitalWrite(LED_BUILTIN, HIGH); // turn OFF board led
//ESP.wdtEnable(30000);
sds.begin(SDS_TX, SDS_RX); sds.begin(SDS_TX, SDS_RX);
sds.mode_mon_300(); sds.mode_mon_300();
@ -412,7 +441,13 @@ void setup() {
} }
void loop() { void loop() {
cansleep = false;
// lightsleepwake();
//DEBUG_MSG("%d\n", millis() - last_wifi_activity); //DEBUG_MSG("%d\n", millis() - last_wifi_activity);
sendValues(); sendValues();
DEBUG_MSG("sleeping now...\n");
cansleep = true;
lightsleep();
delay(postingInterval); delay(postingInterval);
//ESP.deepSleep(10e6);
} }

Loading…
Cancel
Save