Merge branch 'master' into combine-lora-msg

This commit is contained in:
Verkehrsrot 2019-11-27 22:16:07 +01:00 committed by GitHub
commit 773f506940
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 367 additions and 367 deletions

View File

@ -46,7 +46,7 @@ description = Paxcounter is a device for metering passenger flows in realtime. I
release_version = 1.9.82 release_version = 1.9.82
; DEBUG LEVEL: For production run set to 0, otherwise device will leak RAM while running! ; DEBUG LEVEL: For production run set to 0, otherwise device will leak RAM while running!
; 0=None, 1=Error, 2=Warn, 3=Info, 4=Debug, 5=Verbose ; 0=None, 1=Error, 2=Warn, 3=Info, 4=Debug, 5=Verbose
debug_level = 4 debug_level = 3
extra_scripts = pre:build.py extra_scripts = pre:build.py
otakeyfile = ota.conf otakeyfile = ota.conf
lorakeyfile = loraconf.h lorakeyfile = loraconf.h

View File

@ -1,364 +1,364 @@
/* configmanager persists runtime configuration using NVRAM of ESP32*/ /* configmanager persists runtime configuration using NVRAM of ESP32*/
#include "globals.h" #include "globals.h"
// Local logging tag // Local logging tag
static const char TAG[] = "flash"; static const char TAG[] = "flash";
nvs_handle my_handle; nvs_handle my_handle;
esp_err_t err; esp_err_t err;
#define PAYLOADMASK \ #define PAYLOADMASK \
((GPS_DATA | ALARM_DATA | MEMS_DATA | COUNT_DATA | \ ((GPS_DATA | ALARM_DATA | MEMS_DATA | COUNT_DATA | \
SENSOR1_DATA | SENSOR2_DATA | SENSOR3_DATA) & \ SENSOR1_DATA | SENSOR2_DATA | SENSOR3_DATA) & \
(~BATT_DATA) ) (~BATT_DATA) )
// populate cfg vars with factory settings // populate cfg vars with factory settings
void defaultConfig() { void defaultConfig() {
cfg.loradr = LORADRDEFAULT; // 0-15, lora datarate, see paxcounter.conf cfg.loradr = LORADRDEFAULT; // 0-15, lora datarate, see paxcounter.conf
cfg.txpower = LORATXPOWDEFAULT; // 0-15, lora tx power cfg.txpower = LORATXPOWDEFAULT; // 0-15, lora tx power
cfg.adrmode = 1; // 0=disabled, 1=enabled cfg.adrmode = 1; // 0=disabled, 1=enabled
cfg.screensaver = 0; // 0=disabled, 1=enabled cfg.screensaver = 0; // 0=disabled, 1=enabled
cfg.screenon = 1; // 0=disabled, 1=enabled cfg.screenon = 1; // 0=disabled, 1=enabled
cfg.countermode = COUNTERMODE; // 0=cyclic, 1=cumulative, 2=cyclic confirmed cfg.countermode = COUNTERMODE; // 0=cyclic, 1=cumulative, 2=cyclic confirmed
cfg.rssilimit = 0; // threshold for rssilimiter, negative value! cfg.rssilimit = 0; // threshold for rssilimiter, negative value!
cfg.sendcycle = SENDCYCLE; // payload send cycle [seconds/2] cfg.sendcycle = SENDCYCLE; // payload send cycle [seconds/2]
cfg.wifichancycle = cfg.wifichancycle =
WIFI_CHANNEL_SWITCH_INTERVAL; // wifi channel switch cycle [seconds/100] WIFI_CHANNEL_SWITCH_INTERVAL; // wifi channel switch cycle [seconds/100]
cfg.blescantime = cfg.blescantime =
BLESCANINTERVAL / BLESCANINTERVAL /
10; // BT channel scan cycle [seconds/100], default 1 (= 10ms) 10; // BT channel scan cycle [seconds/100], default 1 (= 10ms)
cfg.blescan = BLECOUNTER; // 0=disabled, 1=enabled cfg.blescan = BLECOUNTER; // 0=disabled, 1=enabled
cfg.wifiscan = WIFICOUNTER; // 0=disabled, 1=enabled cfg.wifiscan = WIFICOUNTER; // 0=disabled, 1=enabled
cfg.wifiant = 0; // 0=internal, 1=external (for LoPy/LoPy4) cfg.wifiant = 0; // 0=internal, 1=external (for LoPy/LoPy4)
cfg.vendorfilter = VENDORFILTER; // 0=disabled, 1=enabled cfg.vendorfilter = VENDORFILTER; // 0=disabled, 1=enabled
cfg.rgblum = RGBLUMINOSITY; // RGB Led luminosity (0..100%) cfg.rgblum = RGBLUMINOSITY; // RGB Led luminosity (0..100%)
cfg.monitormode = 0; // 0=disabled, 1=enabled cfg.monitormode = 0; // 0=disabled, 1=enabled
cfg.payloadmask = PAYLOADMASK; // all payload switched on cfg.payloadmask = PAYLOADMASK; // all payload switched on
cfg.bsecstate[BSEC_MAX_STATE_BLOB_SIZE] = { cfg.bsecstate[BSEC_MAX_STATE_BLOB_SIZE] = {
0}; // init BSEC state for BME680 sensor 0}; // init BSEC state for BME680 sensor
strncpy(cfg.version, PROGVERSION, sizeof(cfg.version) - 1); strncpy(cfg.version, PROGVERSION, sizeof(cfg.version) - 1);
} }
void open_storage() { void open_storage() {
err = nvs_flash_init(); err = nvs_flash_init();
if (err == ESP_ERR_NVS_NO_FREE_PAGES) { if (err == ESP_ERR_NVS_NO_FREE_PAGES) {
// NVS partition was truncated and needs to be erased // NVS partition was truncated and needs to be erased
// Retry nvs_flash_init // Retry nvs_flash_init
ESP_ERROR_CHECK(nvs_flash_erase()); ESP_ERROR_CHECK(nvs_flash_erase());
err = nvs_flash_init(); err = nvs_flash_init();
} }
ESP_ERROR_CHECK(err); ESP_ERROR_CHECK(err);
// Open // Open
ESP_LOGI(TAG, "Opening NVS"); ESP_LOGI(TAG, "Opening NVS");
err = nvs_open("config", NVS_READWRITE, &my_handle); err = nvs_open("config", NVS_READWRITE, &my_handle);
if (err != ESP_OK) if (err != ESP_OK)
ESP_LOGI(TAG, "Error (%d) opening NVS handle", err); ESP_LOGI(TAG, "Error (%d) opening NVS handle", err);
else else
ESP_LOGI(TAG, "Done"); ESP_LOGI(TAG, "Done");
} }
// erase all keys and values in NVRAM // erase all keys and values in NVRAM
void eraseConfig() { void eraseConfig() {
ESP_LOGI(TAG, "Clearing settings in NVS"); ESP_LOGI(TAG, "Clearing settings in NVS");
open_storage(); open_storage();
if (err == ESP_OK) { if (err == ESP_OK) {
nvs_erase_all(my_handle); nvs_erase_all(my_handle);
nvs_commit(my_handle); nvs_commit(my_handle);
nvs_close(my_handle); nvs_close(my_handle);
ESP_LOGI(TAG, "Done"); ESP_LOGI(TAG, "Done");
} else { } else {
ESP_LOGW(TAG, "NVS erase failed"); ESP_LOGW(TAG, "NVS erase failed");
} }
} }
// save current configuration from RAM to NVRAM // save current configuration from RAM to NVRAM
void saveConfig() { void saveConfig() {
ESP_LOGI(TAG, "Storing settings in NVS"); ESP_LOGI(TAG, "Storing settings in NVS");
open_storage(); open_storage();
if (err == ESP_OK) { if (err == ESP_OK) {
int8_t flash8 = 0; int8_t flash8 = 0;
int16_t flash16 = 0; int16_t flash16 = 0;
size_t required_size; size_t required_size;
uint8_t bsecstate_buffer[BSEC_MAX_STATE_BLOB_SIZE + 1]; uint8_t bsecstate_buffer[BSEC_MAX_STATE_BLOB_SIZE + 1];
char storedversion[10]; char storedversion[10];
if (nvs_get_blob(my_handle, "bsecstate", bsecstate_buffer, if (nvs_get_blob(my_handle, "bsecstate", bsecstate_buffer,
&required_size) != ESP_OK || &required_size) != ESP_OK ||
memcmp(bsecstate_buffer, cfg.bsecstate, BSEC_MAX_STATE_BLOB_SIZE + 1) != memcmp(bsecstate_buffer, cfg.bsecstate, BSEC_MAX_STATE_BLOB_SIZE + 1) !=
0) 0)
nvs_set_blob(my_handle, "bsecstate", cfg.bsecstate, nvs_set_blob(my_handle, "bsecstate", cfg.bsecstate,
BSEC_MAX_STATE_BLOB_SIZE + 1); BSEC_MAX_STATE_BLOB_SIZE + 1);
if (nvs_get_str(my_handle, "version", storedversion, &required_size) != if (nvs_get_str(my_handle, "version", storedversion, &required_size) !=
ESP_OK || ESP_OK ||
strcmp(storedversion, cfg.version) != 0) strcmp(storedversion, cfg.version) != 0)
nvs_set_str(my_handle, "version", cfg.version); nvs_set_str(my_handle, "version", cfg.version);
if (nvs_get_i8(my_handle, "loradr", &flash8) != ESP_OK || if (nvs_get_i8(my_handle, "loradr", &flash8) != ESP_OK ||
flash8 != cfg.loradr) flash8 != cfg.loradr)
nvs_set_i8(my_handle, "loradr", cfg.loradr); nvs_set_i8(my_handle, "loradr", cfg.loradr);
if (nvs_get_i8(my_handle, "txpower", &flash8) != ESP_OK || if (nvs_get_i8(my_handle, "txpower", &flash8) != ESP_OK ||
flash8 != cfg.txpower) flash8 != cfg.txpower)
nvs_set_i8(my_handle, "txpower", cfg.txpower); nvs_set_i8(my_handle, "txpower", cfg.txpower);
if (nvs_get_i8(my_handle, "adrmode", &flash8) != ESP_OK || if (nvs_get_i8(my_handle, "adrmode", &flash8) != ESP_OK ||
flash8 != cfg.adrmode) flash8 != cfg.adrmode)
nvs_set_i8(my_handle, "adrmode", cfg.adrmode); nvs_set_i8(my_handle, "adrmode", cfg.adrmode);
if (nvs_get_i8(my_handle, "screensaver", &flash8) != ESP_OK || if (nvs_get_i8(my_handle, "screensaver", &flash8) != ESP_OK ||
flash8 != cfg.screensaver) flash8 != cfg.screensaver)
nvs_set_i8(my_handle, "screensaver", cfg.screensaver); nvs_set_i8(my_handle, "screensaver", cfg.screensaver);
if (nvs_get_i8(my_handle, "screenon", &flash8) != ESP_OK || if (nvs_get_i8(my_handle, "screenon", &flash8) != ESP_OK ||
flash8 != cfg.screenon) flash8 != cfg.screenon)
nvs_set_i8(my_handle, "screenon", cfg.screenon); nvs_set_i8(my_handle, "screenon", cfg.screenon);
if (nvs_get_i8(my_handle, "countermode", &flash8) != ESP_OK || if (nvs_get_i8(my_handle, "countermode", &flash8) != ESP_OK ||
flash8 != cfg.countermode) flash8 != cfg.countermode)
nvs_set_i8(my_handle, "countermode", cfg.countermode); nvs_set_i8(my_handle, "countermode", cfg.countermode);
if (nvs_get_i8(my_handle, "sendcycle", &flash8) != ESP_OK || if (nvs_get_i8(my_handle, "sendcycle", &flash8) != ESP_OK ||
flash8 != cfg.sendcycle) flash8 != cfg.sendcycle)
nvs_set_i8(my_handle, "sendcycle", cfg.sendcycle); nvs_set_i8(my_handle, "sendcycle", cfg.sendcycle);
if (nvs_get_i8(my_handle, "wifichancycle", &flash8) != ESP_OK || if (nvs_get_i8(my_handle, "wifichancycle", &flash8) != ESP_OK ||
flash8 != cfg.wifichancycle) flash8 != cfg.wifichancycle)
nvs_set_i8(my_handle, "wifichancycle", cfg.wifichancycle); nvs_set_i8(my_handle, "wifichancycle", cfg.wifichancycle);
if (nvs_get_i8(my_handle, "blescantime", &flash8) != ESP_OK || if (nvs_get_i8(my_handle, "blescantime", &flash8) != ESP_OK ||
flash8 != cfg.blescantime) flash8 != cfg.blescantime)
nvs_set_i8(my_handle, "blescantime", cfg.blescantime); nvs_set_i8(my_handle, "blescantime", cfg.blescantime);
if (nvs_get_i8(my_handle, "blescanmode", &flash8) != ESP_OK || if (nvs_get_i8(my_handle, "blescanmode", &flash8) != ESP_OK ||
flash8 != cfg.blescan) flash8 != cfg.blescan)
nvs_set_i8(my_handle, "blescanmode", cfg.blescan); nvs_set_i8(my_handle, "blescanmode", cfg.blescan);
if (nvs_get_i8(my_handle, "wifiscanmode", &flash8) != ESP_OK || if (nvs_get_i8(my_handle, "wifiscanmode", &flash8) != ESP_OK ||
flash8 != cfg.wifiscan) flash8 != cfg.wifiscan)
nvs_set_i8(my_handle, "wifiscanmode", cfg.wifiscan); nvs_set_i8(my_handle, "wifiscanmode", cfg.wifiscan);
if (nvs_get_i8(my_handle, "wifiant", &flash8) != ESP_OK || if (nvs_get_i8(my_handle, "wifiant", &flash8) != ESP_OK ||
flash8 != cfg.wifiant) flash8 != cfg.wifiant)
nvs_set_i8(my_handle, "wifiant", cfg.wifiant); nvs_set_i8(my_handle, "wifiant", cfg.wifiant);
if (nvs_get_i8(my_handle, "vendorfilter", &flash8) != ESP_OK || if (nvs_get_i8(my_handle, "vendorfilter", &flash8) != ESP_OK ||
flash8 != cfg.vendorfilter) flash8 != cfg.vendorfilter)
nvs_set_i8(my_handle, "vendorfilter", cfg.vendorfilter); nvs_set_i8(my_handle, "vendorfilter", cfg.vendorfilter);
if (nvs_get_i8(my_handle, "rgblum", &flash8) != ESP_OK || if (nvs_get_i8(my_handle, "rgblum", &flash8) != ESP_OK ||
flash8 != cfg.rgblum) flash8 != cfg.rgblum)
nvs_set_i8(my_handle, "rgblum", cfg.rgblum); nvs_set_i8(my_handle, "rgblum", cfg.rgblum);
if (nvs_get_i8(my_handle, "payloadmask", &flash8) != ESP_OK || if (nvs_get_i8(my_handle, "payloadmask", &flash8) != ESP_OK ||
flash8 != cfg.payloadmask) flash8 != cfg.payloadmask)
nvs_set_i8(my_handle, "payloadmask", cfg.payloadmask); nvs_set_i8(my_handle, "payloadmask", cfg.payloadmask);
if (nvs_get_i8(my_handle, "monitormode", &flash8) != ESP_OK || if (nvs_get_i8(my_handle, "monitormode", &flash8) != ESP_OK ||
flash8 != cfg.monitormode) flash8 != cfg.monitormode)
nvs_set_i8(my_handle, "monitormode", cfg.monitormode); nvs_set_i8(my_handle, "monitormode", cfg.monitormode);
if (nvs_get_i16(my_handle, "rssilimit", &flash16) != ESP_OK || if (nvs_get_i16(my_handle, "rssilimit", &flash16) != ESP_OK ||
flash16 != cfg.rssilimit) flash16 != cfg.rssilimit)
nvs_set_i16(my_handle, "rssilimit", cfg.rssilimit); nvs_set_i16(my_handle, "rssilimit", cfg.rssilimit);
err = nvs_commit(my_handle); err = nvs_commit(my_handle);
nvs_close(my_handle); nvs_close(my_handle);
if (err == ESP_OK) { if (err == ESP_OK) {
ESP_LOGI(TAG, "Done"); ESP_LOGI(TAG, "Done");
} else { } else {
ESP_LOGW(TAG, "NVS config write failed"); ESP_LOGW(TAG, "NVS config write failed");
} }
} else { } else {
ESP_LOGW(TAG, "Error (%d) opening NVS handle", err); ESP_LOGW(TAG, "Error (%d) opening NVS handle", err);
} }
} }
// set and save cfg.version // set and save cfg.version
void migrateVersion() { void migrateVersion() {
snprintf(cfg.version, 10, "%s", PROGVERSION); snprintf(cfg.version, 10, "%s", PROGVERSION);
ESP_LOGI(TAG, "version set to %s", cfg.version); ESP_LOGI(TAG, "version set to %s", cfg.version);
saveConfig(); saveConfig();
} }
// load configuration from NVRAM into RAM and make it current // load configuration from NVRAM into RAM and make it current
void loadConfig() { void loadConfig() {
defaultConfig(); // start with factory settings defaultConfig(); // start with factory settings
ESP_LOGI(TAG, "Reading settings from NVS"); ESP_LOGI(TAG, "Reading settings from NVS");
open_storage(); open_storage();
if (err != ESP_OK) { if (err != ESP_OK) {
ESP_LOGW(TAG, "Error (%d) opening NVS handle, storing defaults", err); ESP_LOGW(TAG, "Error (%d) opening NVS handle, storing defaults", err);
saveConfig(); saveConfig();
} // saves factory settings to NVRAM } // saves factory settings to NVRAM
else { else {
int8_t flash8 = 0; int8_t flash8 = 0;
int16_t flash16 = 0; int16_t flash16 = 0;
size_t required_size; size_t required_size;
// check if configuration stored in NVRAM matches PROGVERSION // check if configuration stored in NVRAM matches PROGVERSION
if (nvs_get_str(my_handle, "version", NULL, &required_size) == ESP_OK) { if (nvs_get_str(my_handle, "version", NULL, &required_size) == ESP_OK) {
nvs_get_str(my_handle, "version", cfg.version, &required_size); nvs_get_str(my_handle, "version", cfg.version, &required_size);
ESP_LOGI(TAG, "NVRAM settings version = %s", cfg.version); ESP_LOGI(TAG, "NVRAM settings version = %s", cfg.version);
if (strcmp(cfg.version, PROGVERSION)) { if (strcmp(cfg.version, PROGVERSION)) {
ESP_LOGI(TAG, "migrating NVRAM settings to new version %s", ESP_LOGI(TAG, "migrating NVRAM settings to new version %s",
PROGVERSION); PROGVERSION);
nvs_close(my_handle); nvs_close(my_handle);
migrateVersion(); migrateVersion();
} }
} else { } else {
ESP_LOGI(TAG, "new version %s, deleting NVRAM settings", PROGVERSION); ESP_LOGI(TAG, "new version %s, deleting NVRAM settings", PROGVERSION);
nvs_close(my_handle); nvs_close(my_handle);
eraseConfig(); eraseConfig();
migrateVersion(); migrateVersion();
} }
// populate pre set defaults with current values from NVRAM // populate pre set defaults with current values from NVRAM
if (nvs_get_blob(my_handle, "bsecstate", NULL, &required_size) == ESP_OK) { if (nvs_get_blob(my_handle, "bsecstate", NULL, &required_size) == ESP_OK) {
nvs_get_blob(my_handle, "bsecstate", cfg.bsecstate, &required_size); nvs_get_blob(my_handle, "bsecstate", cfg.bsecstate, &required_size);
ESP_LOGI(TAG, "bsecstate = %d", cfg.bsecstate[BSEC_MAX_STATE_BLOB_SIZE]); ESP_LOGI(TAG, "bsecstate = %d", cfg.bsecstate[BSEC_MAX_STATE_BLOB_SIZE]);
}; };
if (nvs_get_i8(my_handle, "loradr", &flash8) == ESP_OK) { if (nvs_get_i8(my_handle, "loradr", &flash8) == ESP_OK) {
cfg.loradr = flash8; cfg.loradr = flash8;
ESP_LOGI(TAG, "loradr = %d", flash8); ESP_LOGI(TAG, "loradr = %d", flash8);
} else { } else {
ESP_LOGI(TAG, "loradr set to default %d", cfg.loradr); ESP_LOGI(TAG, "loradr set to default %d", cfg.loradr);
saveConfig(); saveConfig();
} }
if (nvs_get_i8(my_handle, "txpower", &flash8) == ESP_OK) { if (nvs_get_i8(my_handle, "txpower", &flash8) == ESP_OK) {
cfg.txpower = flash8; cfg.txpower = flash8;
ESP_LOGI(TAG, "txpower = %d", flash8); ESP_LOGI(TAG, "txpower = %d", flash8);
} else { } else {
ESP_LOGI(TAG, "txpower set to default %d", cfg.txpower); ESP_LOGI(TAG, "txpower set to default %d", cfg.txpower);
saveConfig(); saveConfig();
} }
if (nvs_get_i8(my_handle, "adrmode", &flash8) == ESP_OK) { if (nvs_get_i8(my_handle, "adrmode", &flash8) == ESP_OK) {
cfg.adrmode = flash8; cfg.adrmode = flash8;
ESP_LOGI(TAG, "adrmode = %d", flash8); ESP_LOGI(TAG, "adrmode = %d", flash8);
} else { } else {
ESP_LOGI(TAG, "adrmode set to default %d", cfg.adrmode); ESP_LOGI(TAG, "adrmode set to default %d", cfg.adrmode);
saveConfig(); saveConfig();
} }
if (nvs_get_i8(my_handle, "screensaver", &flash8) == ESP_OK) { if (nvs_get_i8(my_handle, "screensaver", &flash8) == ESP_OK) {
cfg.screensaver = flash8; cfg.screensaver = flash8;
ESP_LOGI(TAG, "screensaver = %d", flash8); ESP_LOGI(TAG, "screensaver = %d", flash8);
} else { } else {
ESP_LOGI(TAG, "screensaver set to default %d", cfg.screensaver); ESP_LOGI(TAG, "screensaver set to default %d", cfg.screensaver);
saveConfig(); saveConfig();
} }
if (nvs_get_i8(my_handle, "screenon", &flash8) == ESP_OK) { if (nvs_get_i8(my_handle, "screenon", &flash8) == ESP_OK) {
cfg.screenon = flash8; cfg.screenon = flash8;
ESP_LOGI(TAG, "screenon = %d", flash8); ESP_LOGI(TAG, "screenon = %d", flash8);
} else { } else {
ESP_LOGI(TAG, "screenon set to default %d", cfg.screenon); ESP_LOGI(TAG, "screenon set to default %d", cfg.screenon);
saveConfig(); saveConfig();
} }
if (nvs_get_i8(my_handle, "countermode", &flash8) == ESP_OK) { if (nvs_get_i8(my_handle, "countermode", &flash8) == ESP_OK) {
cfg.countermode = flash8; cfg.countermode = flash8;
ESP_LOGI(TAG, "countermode = %d", flash8); ESP_LOGI(TAG, "countermode = %d", flash8);
} else { } else {
ESP_LOGI(TAG, "countermode set to default %d", cfg.countermode); ESP_LOGI(TAG, "countermode set to default %d", cfg.countermode);
saveConfig(); saveConfig();
} }
if (nvs_get_i8(my_handle, "sendcycle", &flash8) == ESP_OK) { if (nvs_get_i8(my_handle, "sendcycle", &flash8) == ESP_OK) {
cfg.sendcycle = flash8; cfg.sendcycle = flash8;
ESP_LOGI(TAG, "sendcycle = %d", flash8); ESP_LOGI(TAG, "sendcycle = %d", flash8);
} else { } else {
ESP_LOGI(TAG, "Payload send cycle set to default %d", cfg.sendcycle); ESP_LOGI(TAG, "Payload send cycle set to default %d", cfg.sendcycle);
saveConfig(); saveConfig();
} }
if (nvs_get_i8(my_handle, "wifichancycle", &flash8) == ESP_OK) { if (nvs_get_i8(my_handle, "wifichancycle", &flash8) == ESP_OK) {
cfg.wifichancycle = flash8; cfg.wifichancycle = flash8;
ESP_LOGI(TAG, "wifichancycle = %d", flash8); ESP_LOGI(TAG, "wifichancycle = %d", flash8);
} else { } else {
ESP_LOGI(TAG, "WIFI channel cycle set to default %d", cfg.wifichancycle); ESP_LOGI(TAG, "WIFI channel cycle set to default %d", cfg.wifichancycle);
saveConfig(); saveConfig();
} }
if (nvs_get_i8(my_handle, "wifiant", &flash8) == ESP_OK) { if (nvs_get_i8(my_handle, "wifiant", &flash8) == ESP_OK) {
cfg.wifiant = flash8; cfg.wifiant = flash8;
ESP_LOGI(TAG, "wifiantenna = %d", flash8); ESP_LOGI(TAG, "wifiantenna = %d", flash8);
} else { } else {
ESP_LOGI(TAG, "WIFI antenna switch set to default %d", cfg.wifiant); ESP_LOGI(TAG, "WIFI antenna switch set to default %d", cfg.wifiant);
saveConfig(); saveConfig();
} }
if (nvs_get_i8(my_handle, "vendorfilter", &flash8) == ESP_OK) { if (nvs_get_i8(my_handle, "vendorfilter", &flash8) == ESP_OK) {
cfg.vendorfilter = flash8; cfg.vendorfilter = flash8;
ESP_LOGI(TAG, "vendorfilter = %d", flash8); ESP_LOGI(TAG, "vendorfilter = %d", flash8);
} else { } else {
ESP_LOGI(TAG, "Vendorfilter mode set to default %d", cfg.vendorfilter); ESP_LOGI(TAG, "Vendorfilter mode set to default %d", cfg.vendorfilter);
saveConfig(); saveConfig();
} }
if (nvs_get_i8(my_handle, "rgblum", &flash8) == ESP_OK) { if (nvs_get_i8(my_handle, "rgblum", &flash8) == ESP_OK) {
cfg.rgblum = flash8; cfg.rgblum = flash8;
ESP_LOGI(TAG, "rgbluminosity = %d", flash8); ESP_LOGI(TAG, "rgbluminosity = %d", flash8);
} else { } else {
ESP_LOGI(TAG, "RGB luminosity set to default %d", cfg.rgblum); ESP_LOGI(TAG, "RGB luminosity set to default %d", cfg.rgblum);
saveConfig(); saveConfig();
} }
if (nvs_get_i8(my_handle, "blescantime", &flash8) == ESP_OK) { if (nvs_get_i8(my_handle, "blescantime", &flash8) == ESP_OK) {
cfg.blescantime = flash8; cfg.blescantime = flash8;
ESP_LOGI(TAG, "blescantime = %d", flash8); ESP_LOGI(TAG, "blescantime = %d", flash8);
} else { } else {
ESP_LOGI(TAG, "BLEscantime set to default %d", cfg.blescantime); ESP_LOGI(TAG, "BLEscantime set to default %d", cfg.blescantime);
saveConfig(); saveConfig();
} }
if (nvs_get_i8(my_handle, "blescanmode", &flash8) == ESP_OK) { if (nvs_get_i8(my_handle, "blescanmode", &flash8) == ESP_OK) {
cfg.blescan = flash8; cfg.blescan = flash8;
ESP_LOGI(TAG, "BLEscanmode = %d", flash8); ESP_LOGI(TAG, "BLEscanmode = %d", flash8);
} else { } else {
ESP_LOGI(TAG, "BLEscanmode set to default %d", cfg.blescan); ESP_LOGI(TAG, "BLEscanmode set to default %d", cfg.blescan);
saveConfig(); saveConfig();
} }
if (nvs_get_i8(my_handle, "wifiscanmode", &flash8) == ESP_OK) { if (nvs_get_i8(my_handle, "wifiscanmode", &flash8) == ESP_OK) {
cfg.wifiscan = flash8; cfg.wifiscan = flash8;
ESP_LOGI(TAG, "WIFIscanmode = %d", flash8); ESP_LOGI(TAG, "WIFIscanmode = %d", flash8);
} else { } else {
ESP_LOGI(TAG, "WIFIscanmode set to default %d", cfg.wifiscan); ESP_LOGI(TAG, "WIFIscanmode set to default %d", cfg.wifiscan);
saveConfig(); saveConfig();
} }
if (nvs_get_i16(my_handle, "rssilimit", &flash16) == ESP_OK) { if (nvs_get_i16(my_handle, "rssilimit", &flash16) == ESP_OK) {
cfg.rssilimit = flash16; cfg.rssilimit = flash16;
ESP_LOGI(TAG, "rssilimit = %d", flash16); ESP_LOGI(TAG, "rssilimit = %d", flash16);
} else { } else {
ESP_LOGI(TAG, "rssilimit set to default %d", cfg.rssilimit); ESP_LOGI(TAG, "rssilimit set to default %d", cfg.rssilimit);
saveConfig(); saveConfig();
} }
if (nvs_get_i8(my_handle, "payloadmask", &flash8) == ESP_OK) { if (nvs_get_i8(my_handle, "payloadmask", &flash8) == ESP_OK) {
cfg.payloadmask = flash8; cfg.payloadmask = flash8;
ESP_LOGI(TAG, "payloadmask = %hhu", flash8); ESP_LOGI(TAG, "payloadmask = %hhu", flash8);
} else { } else {
ESP_LOGI(TAG, "payloadmask set to default %hhu", cfg.payloadmask); ESP_LOGI(TAG, "payloadmask set to default %hhu", cfg.payloadmask);
saveConfig(); saveConfig();
} }
if (nvs_get_i8(my_handle, "monitormode", &flash8) == ESP_OK) { if (nvs_get_i8(my_handle, "monitormode", &flash8) == ESP_OK) {
cfg.monitormode = flash8; cfg.monitormode = flash8;
ESP_LOGI(TAG, "Monitor mode = %d", flash8); ESP_LOGI(TAG, "Monitor mode = %d", flash8);
} else { } else {
ESP_LOGI(TAG, "Monitor mode set to default %d", cfg.monitormode); ESP_LOGI(TAG, "Monitor mode set to default %d", cfg.monitormode);
saveConfig(); saveConfig();
} }
nvs_close(my_handle); nvs_close(my_handle);
ESP_LOGI(TAG, "Done"); ESP_LOGI(TAG, "Done");
} }
} // loadConfig() } // loadConfig()

View File

@ -34,9 +34,9 @@ IDLE 0 0 ESP32 arduino scheduler -> runs wifi sniffer
lmictask 1 2 MCCI LMiC LORAWAN stack lmictask 1 2 MCCI LMiC LORAWAN stack
clockloop 1 4 generates realtime telegrams for external clock clockloop 1 4 generates realtime telegrams for external clock
timesync_req 1 3 processes realtime time sync requests timesync_req 1 3 processes realtime time sync requests
irqhandler 1 1 display, timesync, gps, etc. triggered by timers irqhandler 1 1 cyclic tasks (i.e. displayrefresh) triggered by timers
gpsloop 1 1 reads data from GPS via serial or i2c gpsloop 1 1 reads data from GPS via serial or i2c
lorasendtask 1 1 feed data from lora sendqueue to lmcic lorasendtask 1 1 feeds data from lora sendqueue to lmcic
IDLE 1 0 ESP32 arduino scheduler -> runs wifi channel rotator IDLE 1 0 ESP32 arduino scheduler -> runs wifi channel rotator
Low priority numbers denote low priority tasks. Low priority numbers denote low priority tasks.