|
|
@ -8,7 +8,7 @@ |
|
|
|
#include <ESP8266WiFi.h> |
|
|
|
#include <ESP8266WiFiMulti.h> |
|
|
|
extern "C" { |
|
|
|
#include <espnow.h> |
|
|
|
//#include <espnow.h>
|
|
|
|
#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);
|
|
|
|
} |
|
|
|