From a52a087fb93751667284ddb6ad0df95189ea0d2a Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Fri, 28 Apr 2023 17:24:12 +0200 Subject: [PATCH] add wifi channel map configuration option --- docs/remotecontrol.md | 5 +++++ include/globals.h | 1 + src/configmanager.cpp | 1 + src/main.cpp | 2 +- src/paxcounter_orig.conf | 1 + src/payload.cpp | 2 ++ src/rcommand.cpp | 30 +++++++++++++++++++++--------- 7 files changed, 32 insertions(+), 10 deletions(-) diff --git a/docs/remotecontrol.md b/docs/remotecontrol.md index d573ca12..4b5e3380 100644 --- a/docs/remotecontrol.md +++ b/docs/remotecontrol.md @@ -111,6 +111,11 @@ Send for example `83` `86` as Downlink on Port 2 to get battery status and time/ 0 ... 100 percentage of luminosity (100% = full light) e.g. 50 -> 50% of luminosity [default] +#### 0x11 set Wifi scanner channel map bitmask + + bytes 1..2 = wifi channel map bitmask (MSB), 0..8191 + e.g. 0b1010000001001 sets channels 1, 4, 11, 13 + #### 0x13 set user sensor mode byte 1 = user sensor number (1..3) diff --git a/include/globals.h b/include/globals.h index 0b042d50..78e633b5 100644 --- a/include/globals.h +++ b/include/globals.h @@ -66,6 +66,7 @@ typedef struct __attribute__((packed)) { uint16_t sleepcycle; // sleep cycle [seconds/10] uint16_t wakesync; // time window [seconds] to sync wakeup on top-of-hour uint8_t wifichancycle; // wifi channel switch cycle [seconds/100] + uint16_t wifichanmap; // wifi channel hopping scheme uint8_t blescantime; // BLE scan cycle duration [seconds] uint8_t blescan; // 0=disabled, 1=enabled uint8_t wifiscan; // 0=disabled, 1=enabled diff --git a/src/configmanager.cpp b/src/configmanager.cpp index 3360a4ef..aa14109b 100644 --- a/src/configmanager.cpp +++ b/src/configmanager.cpp @@ -40,6 +40,7 @@ static void defaultConfig(configData_t *myconfig) { myconfig->wakesync = SYNCWAKEUP; // wakeup sync window [seconds] myconfig->wifichancycle = WIFI_CHANNEL_SWITCH_INTERVAL; // wifi channel switch cycle [seconds/100] + myconfig->wifichanmap = WIFI_CHANNEL_MAP; // wifi channel hopping scheme myconfig->blescantime = BLESCANINTERVAL / 10; // BT channel scan cycle [seconds/100], default 1 (= 10ms) diff --git a/src/main.cpp b/src/main.cpp index 3d6783fe..be0fd612 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -282,7 +282,7 @@ void setup() { // configure WIFI sniffing strcpy(configuration.wifi_my_country_str, WIFI_MY_COUNTRY); configuration.wificounter = cfg.wifiscan; - configuration.wifi_channel_map = WIFI_CHANNEL_ALL; + configuration.wifi_channel_map = cfg.wifichanmap; configuration.wifi_channel_switch_interval = cfg.wifichancycle; configuration.wifi_rssi_threshold = cfg.rssilimit; ESP_LOGI(TAG, "WIFISCAN: %s", cfg.wifiscan ? "on" : "off"); diff --git a/src/paxcounter_orig.conf b/src/paxcounter_orig.conf index 01d8e53a..9469a459 100644 --- a/src/paxcounter_orig.conf +++ b/src/paxcounter_orig.conf @@ -53,6 +53,7 @@ // WiFi scan parameters #define WIFI_MY_COUNTRY "01" // select 2-letter locale for Wifi RF settings, e.g. "DE"; use "01" for world safe mode #define WIFI_CHANNEL_SWITCH_INTERVAL 50 // [seconds/100] -> 0,5 sec. +#define WIFI_CHANNEL_MAP WIFI_CHANNEL_ALL // possible values see libpax_api.h // LoRa payload default parameters #define MEM_LOW 2048 // [Bytes] low memory threshold triggering a send cycle diff --git a/src/payload.cpp b/src/payload.cpp index d601f9f5..d18f01a5 100644 --- a/src/payload.cpp +++ b/src/payload.cpp @@ -44,6 +44,7 @@ void PayloadConvert::addConfig(configData_t value) { buffer[cursor++] = lowByte(value.rssilimit); buffer[cursor++] = value.sendcycle; buffer[cursor++] = value.wifichancycle; + //buffer[cursor++] = value.wifichanmap; buffer[cursor++] = value.blescantime; buffer[cursor++] = value.blescan; buffer[cursor++] = value.wifiant; @@ -170,6 +171,7 @@ void PayloadConvert::addConfig(configData_t value) { writeUint16(value.rssilimit); writeUint8(value.sendcycle); writeUint8(value.wifichancycle); + //writeUint8(value.wifichanmap); writeUint8(value.blescantime); writeUint16(value.sleepcycle); writeBitmap(value.adrmode ? true : false, value.screensaver ? true : false, diff --git a/src/rcommand.cpp b/src/rcommand.cpp index 21639cf7..5d64f7eb 100644 --- a/src/rcommand.cpp +++ b/src/rcommand.cpp @@ -106,6 +106,17 @@ void set_wifichancycle(uint8_t val[]) { init_libpax(); } +void set_wifichanmap(uint8_t val[]) { + // swap byte order from msb to lsb, note: this is a platform dependent hack + cfg.wifichanmap = __builtin_bswap16(*(uint16_t *)(val)); + libpax_counter_stop(); + libpax_config_t current_config; + libpax_get_current_config(¤t_config); + current_config.wifi_channel_map = cfg.wifichanmap; + libpax_update_config(¤t_config); + init_libpax(); +} + void set_blescantime(uint8_t val[]) { cfg.blescantime = val[0]; libpax_counter_stop(); @@ -406,15 +417,16 @@ static const cmd_t table[] = { {0x0b, set_wifichancycle, 1}, {0x0c, set_blescantime, 1}, {0x0d, set_wakesync, 2}, {0x0e, set_blescan, 1}, {0x0f, set_wifiant, 1}, {0x10, set_rgblum, 1}, - {0x13, set_sensor, 2}, {0x14, set_payloadmask, 1}, - {0x15, set_bme, 1}, {0x16, set_batt, 1}, - {0x17, set_wifiscan, 1}, {0x18, set_flush, 0}, - {0x19, set_sleepcycle, 2}, {0x20, set_loadconfig, 0}, - {0x21, set_saveconfig, 0}, {0x80, get_config, 0}, - {0x81, get_status, 0}, {0x83, get_batt, 0}, - {0x84, get_gps, 0}, {0x85, get_bme, 0}, - {0x86, get_time, 0}, {0x87, set_timesync, 0}, - {0x88, set_time, 4}, {0x99, set_flush, 0}}; + {0x11, set_wifichanmap, 2}, {0x13, set_sensor, 2}, + {0x14, set_payloadmask, 1}, {0x15, set_bme, 1}, + {0x16, set_batt, 1}, {0x17, set_wifiscan, 1}, + {0x18, set_flush, 0}, {0x19, set_sleepcycle, 2}, + {0x20, set_loadconfig, 0}, {0x21, set_saveconfig, 0}, + {0x80, get_config, 0}, {0x81, get_status, 0}, + {0x83, get_batt, 0}, {0x84, get_gps, 0}, + {0x85, get_bme, 0}, {0x86, get_time, 0}, + {0x87, set_timesync, 0}, {0x88, set_time, 4}, + {0x99, set_flush, 0}}; static const uint8_t cmdtablesize = sizeof(table) / sizeof(table[0]); // number of commands in command table