|
@ -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" |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -36,7 +36,7 @@ const char* mqttserver = "home.xd0.de"; |
|
|
const char* mqttusername = "esp-weatherstation"; |
|
|
const char* mqttusername = "esp-weatherstation"; |
|
|
const char* mqttpassword = "password4"; |
|
|
const char* mqttpassword = "password4"; |
|
|
|
|
|
|
|
|
constexpr unsigned int postingInterval = 60000; //Uploadintervall in Millisekunden
|
|
|
constexpr long postingInterval = 60000; //Uploadintervall in Millisekunden
|
|
|
constexpr unsigned int dhcp_interval = 60*60*1000; |
|
|
constexpr unsigned int dhcp_interval = 60*60*1000; |
|
|
|
|
|
|
|
|
int loop_count = 0; |
|
|
int loop_count = 0; |
|
@ -97,6 +97,8 @@ IPAddress ip, dns, gateway, subnet; |
|
|
char ssid[64]; |
|
|
char ssid[64]; |
|
|
char password[64]; |
|
|
char password[64]; |
|
|
|
|
|
|
|
|
|
|
|
unsigned long previousMillis = 0; |
|
|
|
|
|
|
|
|
struct __attribute__((packed)) SENSOR_DATA { |
|
|
struct __attribute__((packed)) SENSOR_DATA { |
|
|
float temperature; |
|
|
float temperature; |
|
|
float humidity; |
|
|
float humidity; |
|
@ -366,12 +368,43 @@ void ICACHE_FLASH_ATTR sendValues() { |
|
|
WiFi.mode(WIFI_OFF); |
|
|
WiFi.mode(WIFI_OFF); |
|
|
WiFi.forceSleepBegin(); |
|
|
WiFi.forceSleepBegin(); |
|
|
delay(1); // yield();
|
|
|
delay(1); // yield();
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// WARNING: SOME TIME THE CALIBRATION VALUE CHANGES AND IT WILL RETURN A LOWER VALUE THAN BEFORE, BREAKING INTERVAL CHECKS!!!
|
|
|
|
|
|
unsigned long getTime() { |
|
|
|
|
|
uint64_t rtc_t = system_get_rtc_time(); |
|
|
|
|
|
uint32_t cal = system_rtc_clock_cali_proc(); |
|
|
|
|
|
// uint32_t timemicrosec = rtc_t*((uint64) ((cal * 1000) >> 12));
|
|
|
|
|
|
// Serial.printf("cal: %d.%d \r\n", ((cal*1000)>>12)/1000, ((cal*1000)>>12)%1000 );
|
|
|
|
|
|
// Serial.printf("cal: %u\n", cal);
|
|
|
|
|
|
return ((uint64_t)(rtc_t*(uint64_t)cal) >> 12)/1000; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void fpm_wakup_cb_func1(void) { |
|
|
|
|
|
//gpio_pin_wakeup_disable();
|
|
|
|
|
|
//ESP.wdtFeed();
|
|
|
|
|
|
//wifi_fpm_do_wakeup();
|
|
|
|
|
|
wifi_fpm_close(); |
|
|
|
|
|
geiger_counts++; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
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_DIS_OUTPUT(GPIO_ID_PIN(GEIGER_PIN)); |
|
|
|
|
|
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTCK_U,FUNC_GPIO13); // PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDI_U,FUNC_GPIO13);
|
|
|
|
|
|
gpio_pin_wakeup_enable(GPIO_ID_PIN(GEIGER_PIN), GPIO_PIN_INTR_LOLEVEL); |
|
|
|
|
|
wifi_fpm_set_wakeup_cb(fpm_wakup_cb_func1); |
|
|
|
|
|
wifi_fpm_do_sleep(0xFFFFFFF); // Sleep for longest possible time
|
|
|
|
|
|
//delay(1);
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
void ICACHE_RAM_ATTR ISR_geiger_impulse() { |
|
|
void ICACHE_RAM_ATTR ISR_geiger_impulse() { |
|
|
geiger_counts++; |
|
|
geiger_counts++; |
|
|
|
|
|
//DEBUG_MSG("X");
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// will be called every 6 seconds
|
|
|
// will be called every 6 seconds
|
|
@ -390,6 +423,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(); |
|
|
|
|
|
|
|
@ -401,18 +436,29 @@ void setup() { |
|
|
dht.begin(); |
|
|
dht.begin(); |
|
|
|
|
|
|
|
|
pinMode(GEIGER_PIN, INPUT); |
|
|
pinMode(GEIGER_PIN, INPUT); |
|
|
attachInterrupt(digitalPinToInterrupt(GEIGER_PIN), ISR_geiger_impulse, FALLING); |
|
|
// attachInterrupt(digitalPinToInterrupt(GEIGER_PIN), ISR_geiger_impulse, FALLING);
|
|
|
|
|
|
|
|
|
geigeraverage.clear(); |
|
|
geigeraverage.clear(); |
|
|
geigeraverage.addValue(2); |
|
|
geigeraverage.addValue(2); |
|
|
os_timer_setfn(&Timer1, timerCallback, NULL); |
|
|
// os_timer_setfn(&Timer1, timerCallback, NULL);
|
|
|
os_timer_arm(&Timer1, 6000, true); |
|
|
// os_timer_arm(&Timer1, 6000, true);
|
|
|
|
|
|
|
|
|
|
|
|
previousMillis = millis(); |
|
|
|
|
|
|
|
|
DEBUG_MSG("ready.\n"); Serial.flush(); |
|
|
DEBUG_MSG("ready.\n"); Serial.flush(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void loop() { |
|
|
void loop() { |
|
|
//DEBUG_MSG("%d\n", millis() - last_wifi_activity);
|
|
|
unsigned long currentMillis = getTime(); |
|
|
sendValues(); |
|
|
if ((long)(currentMillis - previousMillis) >= postingInterval) { |
|
|
delay(postingInterval); |
|
|
DEBUG_MSG("sending values... previousMillis:%u, millis():%u, difference:%d\n", previousMillis, currentMillis, currentMillis-previousMillis); |
|
|
|
|
|
sendValues(); |
|
|
|
|
|
previousMillis = getTime(); |
|
|
|
|
|
} |
|
|
|
|
|
DEBUG_MSG("sleeping now...\n"); |
|
|
|
|
|
delay(10); |
|
|
|
|
|
lightsleep(); |
|
|
|
|
|
delay(10); |
|
|
|
|
|
// delay(postingInterval);
|
|
|
|
|
|
//ESP.deepSleep(10e6);
|
|
|
} |
|
|
} |
|
|