|
@ -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,7 +97,7 @@ IPAddress ip, dns, gateway, subnet; |
|
|
char ssid[64]; |
|
|
char ssid[64]; |
|
|
char password[64]; |
|
|
char password[64]; |
|
|
|
|
|
|
|
|
volatile bool cansleep = false; |
|
|
unsigned long previousMillis = 0; |
|
|
|
|
|
|
|
|
struct __attribute__((packed)) SENSOR_DATA { |
|
|
struct __attribute__((packed)) SENSOR_DATA { |
|
|
float temperature; |
|
|
float temperature; |
|
@ -371,8 +371,11 @@ void ICACHE_FLASH_ATTR sendValues() { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void fpm_wakup_cb_func1(void) { |
|
|
void fpm_wakup_cb_func1(void) { |
|
|
ESP.wdtFeed(); |
|
|
//gpio_pin_wakeup_disable();
|
|
|
|
|
|
//ESP.wdtFeed();
|
|
|
|
|
|
//wifi_fpm_do_wakeup();
|
|
|
wifi_fpm_close(); |
|
|
wifi_fpm_close(); |
|
|
|
|
|
geiger_counts++; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void lightsleep() { |
|
|
void lightsleep() { |
|
@ -381,24 +384,17 @@ void lightsleep() { |
|
|
wifi_set_opmode(NULL_MODE); |
|
|
wifi_set_opmode(NULL_MODE); |
|
|
wifi_fpm_set_sleep_type(LIGHT_SLEEP_T); |
|
|
wifi_fpm_set_sleep_type(LIGHT_SLEEP_T); |
|
|
wifi_fpm_open(); // Enables force sleep
|
|
|
wifi_fpm_open(); // Enables force sleep
|
|
|
gpio_pin_wakeup_enable(GPIO_ID_PIN(GEIGER_PIN), GPIO_PIN_INTR_HILEVEL); |
|
|
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_set_wakeup_cb(fpm_wakup_cb_func1); |
|
|
wifi_fpm_do_sleep(0xFFFFFFF); // Sleep for longest possible time
|
|
|
wifi_fpm_do_sleep(0xFFFFFFF); // Sleep for longest possible time
|
|
|
//delay(1);
|
|
|
//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");
|
|
|
//DEBUG_MSG("X");
|
|
|
if(cansleep) lightsleep(); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// will be called every 6 seconds
|
|
|
// will be called every 6 seconds
|
|
@ -430,24 +426,27 @@ 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() { |
|
|
cansleep = false; |
|
|
if (millis() - previousMillis >= postingInterval) { |
|
|
// lightsleepwake();
|
|
|
sendValues(); |
|
|
//DEBUG_MSG("%d\n", millis() - last_wifi_activity);
|
|
|
previousMillis = millis(); |
|
|
sendValues(); |
|
|
} |
|
|
DEBUG_MSG("sleeping now...\n"); |
|
|
DEBUG_MSG("sleeping now... previousMillis:%u, millis():%u\n", previousMillis, millis()); |
|
|
cansleep = true; |
|
|
delay(10); |
|
|
lightsleep(); |
|
|
lightsleep(); |
|
|
delay(postingInterval); |
|
|
delay(10); |
|
|
|
|
|
// delay(postingInterval);
|
|
|
//ESP.deepSleep(10e6);
|
|
|
//ESP.deepSleep(10e6);
|
|
|
} |
|
|
} |
|
|