diff --git a/README.md b/README.md index 0241a3c4..a5f01596 100644 --- a/README.md +++ b/README.md @@ -515,6 +515,11 @@ Send for example `8386` as Downlink on Port 2 to get battery status and time/dat 0 = disabled [default] 1 = enabled +0x19 set sleep cycle + + 0 ... 255 device sleep cycle in seconds/2 + e.g. 120 -> device sleeps 240 seconds after each send cycle [default = 0] + 0x80 get device configuration Device answers with it's current configuration on Port 3. diff --git a/include/globals.h b/include/globals.h index 39a42f79..5438fa3b 100644 --- a/include/globals.h +++ b/include/globals.h @@ -84,6 +84,7 @@ typedef struct __attribute__((packed)) { uint8_t countermode; // 0=cyclic unconfirmed, 1=cumulative, 2=cyclic confirmed int16_t rssilimit; // threshold for rssilimiter, negative value! uint8_t sendcycle; // payload send cycle [seconds/2] + uint8_t sleepcycle; // sleep cycle [seconds/2] uint8_t wifichancycle; // wifi channel switch cycle [seconds/100] uint8_t blescantime; // BLE scan cycle duration [seconds] uint8_t blescan; // 0=disabled, 1=enabled diff --git a/src/configmanager.cpp b/src/configmanager.cpp index f947f383..a489801e 100644 --- a/src/configmanager.cpp +++ b/src/configmanager.cpp @@ -42,6 +42,7 @@ static void defaultConfig(configData_t *myconfig) { COUNTERMODE; // 0=cyclic, 1=cumulative, 2=cyclic confirmed myconfig->rssilimit = 0; // threshold for rssilimiter, negative value! myconfig->sendcycle = SENDCYCLE; // payload send cycle [seconds/2] + myconfig->sleepcycle = SLEEPCYCLE; // sleep cycle [seconds/2] myconfig->wifichancycle = WIFI_CHANNEL_SWITCH_INTERVAL; // wifi channel switch cycle [seconds/100] myconfig->blescantime = @@ -53,7 +54,7 @@ static void defaultConfig(configData_t *myconfig) { myconfig->vendorfilter = VENDORFILTER; // 0=disabled, 1=enabled myconfig->rgblum = RGBLUMINOSITY; // RGB Led luminosity (0..100%) myconfig->monitormode = 0; // 0=disabled, 1=enabled - myconfig->payloadmask = PAYLOADMASK; // payloads as defined in default + myconfig->payloadmask = PAYLOADMASK; // payloads as defined in default myconfig->enscount = COUNT_ENS; // 0=disabled, 1=enabled #ifdef HAS_BME680 diff --git a/src/rcommand.cpp b/src/rcommand.cpp index 75899eca..bd451d73 100644 --- a/src/rcommand.cpp +++ b/src/rcommand.cpp @@ -54,6 +54,12 @@ void set_sendcycle(uint8_t val[]) { cfg.sendcycle * 2); } +void set_sleepcycle(uint8_t val[]) { + cfg.sleepcycle = val[0]; + ESP_LOGI(TAG, "Remote command: set sleep cycle to %d seconds", + cfg.sleepcycle * 2); +} + void set_wifichancycle(uint8_t val[]) { cfg.wifichancycle = val[0]; // update Wifi channel rotation timer period @@ -365,10 +371,11 @@ static const cmd_t table[] = { {0x13, set_sensor, 2, true}, {0x14, set_payloadmask, 1, true}, {0x15, set_bme, 1, true}, {0x16, set_batt, 1, true}, {0x17, set_wifiscan, 1, true}, {0x18, set_enscount, 1, true}, - {0x80, get_config, 0, false}, {0x81, get_status, 0, false}, - {0x83, get_batt, 0, false}, {0x84, get_gps, 0, false}, - {0x85, get_bme, 0, false}, {0x86, get_time, 0, false}, - {0x87, set_time, 0, false}, {0x99, set_flush, 0, false}}; + {0x19, set_sleepcycle, 1, true}, {0x80, get_config, 0, false}, + {0x81, get_status, 0, false}, {0x83, get_batt, 0, false}, + {0x84, get_gps, 0, false}, {0x85, get_bme, 0, false}, + {0x86, get_time, 0, false}, {0x87, set_time, 0, false}, + {0x99, set_flush, 0, false}}; static const uint8_t cmdtablesize = sizeof(table) / sizeof(table[0]); // number of commands in command table diff --git a/src/reset.cpp b/src/reset.cpp index 8c52bf35..a31d2c8e 100644 --- a/src/reset.cpp +++ b/src/reset.cpp @@ -69,12 +69,12 @@ void enter_deepsleep(const int wakeup_sec, const gpio_num_t wakeup_gpio) { if ((!wakeup_sec) && (!wakeup_gpio) && (RTC_runmode == RUNMODE_NORMAL)) return; -// assure LMIC is in safe state +// wait until LMIC is in safe state before going to sleep #if (HAS_LORA) - if (os_queryTimeCriticalJobs(ms2osticks(10000))) - return; + while (os_queryTimeCriticalJobs(ms2osticks(wakeup_sec * 1000))) + vTaskDelay(pdMS_TO_TICKS(100)); - // to be done: save LoRaWAN channel configuration here + // to be done: save current LoRaWAN configuration here #endif @@ -99,10 +99,15 @@ void enter_deepsleep(const int wakeup_sec, const gpio_num_t wakeup_gpio) { dp_shutdown(); #endif -// switch off wifi & ble +/* +// switch off radio #if (BLECOUNTER) - stop_BLEscan(); + btStop(); #endif +#if (WIFICOUNTER) + switch_wifi_sniffer(0); +#endif +*/ // reduce power if has PMU #ifdef HAS_PMU diff --git a/src/senddata.cpp b/src/senddata.cpp index 1cc09503..4ac5e67a 100644 --- a/src/senddata.cpp +++ b/src/senddata.cpp @@ -188,6 +188,10 @@ void sendData() { mask <<= 1; } // while (bitmask) + // goto sleep if we have a sleep cycle + if ((cfg.sleepcycle) && (RTC_runmode == RUNMODE_NORMAL)) + enter_deepsleep(cfg.sleepcycle * 2, HAS_BUTTON); + } // sendData() void flushQueues() {