Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add wifi channel map configuration option #960

Merged
merged 4 commits into from
Apr 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/remotecontrol.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions include/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions platformio_orig.ini
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ upload_speed = 115200 ; set by build.py and taken from hal file
lib_deps_lora =
mcci-catena/MCCI LoRaWAN LMIC library @ ^4.1.1
lib_deps_display =
bitbank2/OneBitDisplay @ ^2.3.0
bitbank2/OneBitDisplay @ ^2.3.1
bitbank2/bb_spi_lcd @ ^2.4.1
ricmoo/QRCode @ ^0.0.1
lib_deps_ledmatrix =
Expand All @@ -70,15 +70,15 @@ lib_deps_rgbled =
lib_deps_gps =
mikalhart/TinyGPSPlus @ ^1.0.3
lib_deps_sensors =
adafruit/Adafruit Unified Sensor @ ^1.1.7
adafruit/Adafruit Unified Sensor @ ^1.1.9
adafruit/Adafruit BME280 Library @ ^2.2.2
adafruit/Adafruit BMP085 Library @ ^1.2.2
boschsensortec/BSEC Software Library @ 1.8.1492
lewapek/Nova Fitness Sds dust sensors library @ ^1.5.1
lib_deps_basic =
greyrook/libpax @ ^1.1.0
https://github.com/SukkoPera/Arduino-Rokkit-Hash.git
bblanchon/ArduinoJson @ ^6.20.1
bblanchon/ArduinoJson @ ^6.21.2
makuna/RTC @ ^2.3.7
mathertel/OneButton @ ^2.0.3
lewisxhe/XPowersLib @ ^0.1.5
Expand Down
2 changes: 1 addition & 1 deletion platformio_orig_s3.ini
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ lib_deps_all =
fastled/FastLED @ ^3.5.0
greyrook/libpax @ ^1.1.0
https://github.com/SukkoPera/Arduino-Rokkit-Hash.git
bblanchon/ArduinoJson @ ^6.20.1
bblanchon/ArduinoJson @ ^6.21.2
mathertel/OneButton @ ^2.0.3
256dpi/MQTT @ ^2.5.1
ricmoo/QRCode @ ^0.0.1
Expand Down
1 change: 1 addition & 0 deletions src/configmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
1 change: 1 addition & 0 deletions src/paxcounter_orig.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/payload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
30 changes: 21 additions & 9 deletions src/rcommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(&current_config);
current_config.wifi_channel_map = cfg.wifichanmap;
libpax_update_config(&current_config);
init_libpax();
}

void set_blescantime(uint8_t val[]) {
cfg.blescantime = val[0];
libpax_counter_stop();
Expand Down Expand Up @@ -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
Expand Down