|
@ -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);
|
|
|
} |
|
|
} |
|
|