Browse Source

working sleep (breaks millis())

lightsleep
Hendrik Langer 7 years ago
parent
commit
001ff0e41b
  1. 43
      src/main.cpp

43
src/main.cpp

@ -36,7 +36,7 @@ const char* mqttserver = "home.xd0.de";
const char* mqttusername = "esp-weatherstation";
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;
int loop_count = 0;
@ -97,7 +97,7 @@ IPAddress ip, dns, gateway, subnet;
char ssid[64];
char password[64];
volatile bool cansleep = false;
unsigned long previousMillis = 0;
struct __attribute__((packed)) SENSOR_DATA {
float temperature;
@ -371,8 +371,11 @@ void ICACHE_FLASH_ATTR sendValues() {
}
void fpm_wakup_cb_func1(void) {
ESP.wdtFeed();
//gpio_pin_wakeup_disable();
//ESP.wdtFeed();
//wifi_fpm_do_wakeup();
wifi_fpm_close();
geiger_counts++;
}
void lightsleep() {
@ -381,24 +384,17 @@ void lightsleep() {
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);
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 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
@ -430,24 +426,27 @@ void setup() {
dht.begin();
pinMode(GEIGER_PIN, INPUT);
attachInterrupt(digitalPinToInterrupt(GEIGER_PIN), ISR_geiger_impulse, FALLING);
// attachInterrupt(digitalPinToInterrupt(GEIGER_PIN), ISR_geiger_impulse, FALLING);
geigeraverage.clear();
geigeraverage.addValue(2);
os_timer_setfn(&Timer1, timerCallback, NULL);
os_timer_arm(&Timer1, 6000, true);
// os_timer_setfn(&Timer1, timerCallback, NULL);
// os_timer_arm(&Timer1, 6000, true);
previousMillis = millis();
DEBUG_MSG("ready.\n"); Serial.flush();
}
void loop() {
cansleep = false;
// lightsleepwake();
//DEBUG_MSG("%d\n", millis() - last_wifi_activity);
if (millis() - previousMillis >= postingInterval) {
sendValues();
DEBUG_MSG("sleeping now...\n");
cansleep = true;
previousMillis = millis();
}
DEBUG_MSG("sleeping now... previousMillis:%u, millis():%u\n", previousMillis, millis());
delay(10);
lightsleep();
delay(postingInterval);
delay(10);
// delay(postingInterval);
//ESP.deepSleep(10e6);
}

Loading…
Cancel
Save