sleep cycle mode (experimental)
This commit is contained in:
parent
40a1ef1e08
commit
04a055b329
@ -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.
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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() {
|
||||
|
Loading…
Reference in New Issue
Block a user