OTA (experimental)

This commit is contained in:
Klaus K Wilting 2018-09-15 18:59:20 +02:00
parent 01fa10e3fd
commit b12ed126b7
11 changed files with 54 additions and 42 deletions

View File

@ -278,6 +278,7 @@ Note: all settings are stored in NVRAM and will be reloaded when device starts.
1 = reset MAC counter to zero
2 = reset device to factory settings
3 = flush send queues
9 = OTA software update via Wifi
0x0A set LoRaWAN payload send cycle

View File

@ -11,8 +11,8 @@
;env_default = heltec
;env_default = ttgov1
;env_default = ttgov2
;env_default = ttgov21
env_default = ttgobeam
env_default = ttgov21
;env_default = ttgobeam
;env_default = lopy
;env_default = lopy4
;env_default = fipy
@ -29,7 +29,7 @@ package = ttgov21_old
api_token = 2e10f923df5d47b9c7e25752510322a1d65ee997
[common]
release_version = 5
release_version = 6
[ota]
; build configuration based on Bintray and Wi-Fi settings
@ -62,6 +62,7 @@ build_flags =
-D_lmic_config_h_
-include "src/paxcounter.conf"
-include "src/hal/${PIOENV}.h"
${ota.build_flags}
-w
; ---> NOTE: For production run set DEBUG_LEVEL level to NONE! <---
; otherwise device may leak RAM
@ -89,7 +90,6 @@ monitor_speed = 115200
lib_deps =
${common_env_data.lib_deps_all}
build_flags =
${ota.build_flags}
${common_env_data.build_flags}
[env:heltec]
@ -143,6 +143,9 @@ lib_deps =
${common_env_data.lib_deps_display}
build_flags =
${common_env_data.build_flags}
;upload_protocol = custom
;extra_scripts = pre:publish_firmware.py
[env:ttgobeam]
platform = ${common_env_data.platform_espressif32}
@ -155,11 +158,10 @@ lib_deps =
${common_env_data.lib_deps_all}
${common_env_data.lib_deps_gps}
build_flags =
${ota.build_flags}
${common_env_data.build_flags}
-mfix-esp32-psram-cache-issue
upload_protocol = custom
extra_scripts = pre:publish_firmware.py
;upload_protocol = custom
;extra_scripts = pre:publish_firmware.py
[env:fipy]
platform = ${common_env_data.platform_espressif32}
@ -200,7 +202,6 @@ lib_deps =
${common_env_data.lib_deps_rgbled}
${common_env_data.lib_deps_gps}
build_flags =
${ota.build_flags}
${common_env_data.build_flags}
-mfix-esp32-psram-cache-issue
@ -256,5 +257,4 @@ lib_deps =
${common_env_data.lib_deps_gps}
${common_env_data.lib_deps_display}
build_flags =
${ota.build_flags}
${common_env_data.build_flags}

View File

@ -36,16 +36,8 @@ volatile bool isValidContentType = false;
static const char TAG[] = "main";
void start_ota_update() {
ota_update = false; // clear ota trigger switch
ESP_LOGI(TAG, "Stopping Wifi scanner");
vTaskDelete(WifiLoopTask);
ESP_LOGI(TAG, "Starting Wifi OTA update");
// switch off monitor more
ESP_ERROR_CHECK(
esp_wifi_set_promiscuous(false)); // now switch on monitor mode
ESP_ERROR_CHECK(esp_wifi_set_promiscuous_rx_cb(NULL));
WiFi.begin(WIFI_SSID, WIFI_PASS);
@ -56,7 +48,7 @@ void start_ota_update() {
ESP_LOGI(TAG, "connected to %s", WIFI_SSID);
checkFirmwareUpdates();
checkFirmwareUpdates(); // gets and flashes new firmware and restarts
ESP.restart(); // reached only if update was not successful
} // start_ota_update

View File

@ -4,7 +4,6 @@
#include <Arduino.h>
#include <WiFi.h>
#include "globals.h"
#include "wifiscan.h"
void checkFirmwareUpdates();
void processOTAUpdate(const String &version);

View File

@ -31,6 +31,7 @@ void defaultConfig() {
cfg.rgblum = RGBLUMINOSITY; // RGB Led luminosity (0..100%)
cfg.gpsmode = 1; // 0=disabled, 1=enabled
cfg.monitormode = 0; // 0=disabled, 1=enabled
cfg.runmode = 0; // 0=normal, 1=update
strncpy(cfg.version, PROGVERSION, sizeof(cfg.version) - 1);
}
@ -143,6 +144,10 @@ void saveConfig() {
flash8 != cfg.monitormode)
nvs_set_i8(my_handle, "monitormode", cfg.monitormode);
if (nvs_get_i8(my_handle, "runmode", &flash8) != ESP_OK ||
flash8 != cfg.runmode)
nvs_set_i8(my_handle, "runmode", cfg.runmode);
if (nvs_get_i16(my_handle, "rssilimit", &flash16) != ESP_OK ||
flash16 != cfg.rssilimit)
nvs_set_i16(my_handle, "rssilimit", cfg.rssilimit);
@ -326,6 +331,14 @@ void loadConfig() {
saveConfig();
}
if (nvs_get_i8(my_handle, "runmode", &flash8) == ESP_OK) {
cfg.runmode = flash8;
ESP_LOGI(TAG, "Run mode = %d", flash8);
} else {
ESP_LOGI(TAG, "Run mode set to default %d", cfg.runmode);
saveConfig();
}
nvs_close(my_handle);
ESP_LOGI(TAG, "Done");
}

View File

@ -15,8 +15,9 @@ void doHomework() {
// update uptime counter
uptime();
if (ota_update)
start_ota_update();
// check if update mode trigger switch was set
if (cfg.runmode == 1)
ESP.restart();
// read battery voltage into global variable
#ifdef HAS_BATTERY_PROBE

View File

@ -5,7 +5,7 @@
#include <Arduino.h>
// attn: increment version after modifications to configData_t truct!
#define PROGVERSION "1.4.23" // use max 10 chars here!
#define PROGVERSION "1.4.30" // use max 10 chars here!
#define PROGNAME "PAXCNT"
// std::set for unified array functions
@ -31,6 +31,7 @@ typedef struct {
uint8_t rgblum; // RGB Led luminosity (0..100%)
uint8_t gpsmode; // 0=disabled, 1=enabled
uint8_t monitormode; // 0=disabled, 1=enabled
uint8_t runmode; // 0=normal, 1=update
char version[10]; // Firmware version
} configData_t;
@ -43,7 +44,6 @@ typedef struct {
// global variables
extern configData_t cfg; // current device configuration
extern bool ota_update;
extern char display_line6[], display_line7[]; // screen buffers
extern uint8_t channel; // wifi channel rotation counter
extern uint16_t macs_total, macs_wifi, macs_ble, batt_voltage; // display values

View File

@ -196,11 +196,9 @@ void onEvent(ev_t ev) {
if (LMIC.dataLen) {
ESP_LOGI(TAG, "Received %d bytes of payload, RSSI %d SNR %d",
LMIC.dataLen, LMIC.rssi, (signed char)LMIC.snr / 4);
// LMIC.snr = SNR twos compliment [dB] * 4
// LMIC.rssi = RSSI [dBm] (-196...+63)
LMIC.dataLen, LMIC.rssi, (signed char)LMIC.snr);
sprintf(display_line6, "RSSI %d SNR %d", LMIC.rssi,
(signed char)LMIC.snr / 4);
(signed char)LMIC.snr);
// check if command is received on command port, then call interpreter
if ((LMIC.txrxFlags & TXRX_PORT) &&

View File

@ -27,8 +27,7 @@ licenses. Refer to LICENSE.txt file in repository for more details.
#include "globals.h"
#include "main.h"
configData_t cfg; // struct holds current device configuration
bool ota_update = false; // triggers OTA update
configData_t cfg; // struct holds current device configuration
char display_line6[16], display_line7[16]; // display buffers
uint8_t channel = 0; // channel rotation counter
uint16_t macs_total = 0, macs_wifi = 0, macs_ble = 0,
@ -97,7 +96,7 @@ void setup() {
// initialize system event handler for wifi task, needed for
// wifi_sniffer_init()
// esp_event_loop_init(NULL, NULL);
//ESP_ERROR_CHECK(esp_event_loop_init(event_handler, NULL));
// ESP_ERROR_CHECK(esp_event_loop_init(event_handler, NULL));
// print chip information on startup if in verbose mode
#ifdef VERBOSE
@ -123,6 +122,13 @@ void setup() {
// read settings from NVRAM
loadConfig(); // includes initialize if necessary
// reboot to firmware update mode if ota trigger switch is set
if (cfg.runmode == 1) {
cfg.runmode = 0;
saveConfig();
start_ota_update();
}
#ifdef VENDORFILTER
strcat_P(features, " OUIFLT");
#endif
@ -302,8 +308,8 @@ void setup() {
ESP_LOGI(TAG, "Starting Wifi task on core 0");
wifi_sniffer_init();
// initialize salt value using esp_random() called by random() in
// arduino-esp32 core. Note: do this *after* wifi has started, since function
// gets it's seed from RF noise
// arduino-esp32 core. Note: do this *after* wifi has started, since
// function gets it's seed from RF noise
reset_salt(); // get new 16bit for salting hashes
xTaskCreatePinnedToCore(wifi_channel_loop, "wifiloop", 2048, (void *)1, 1,
&WifiLoopTask, 0);
@ -318,7 +324,8 @@ void setup() {
void loop() {
while (1) {
// state machine for switching display, LED, button, housekeeping, senddata
// state machine for switching display, LED, button, housekeeping,
// senddata
#if (HAS_LED != NOT_A_PIN) || defined(HAS_RGB_LED)
led_loop();

View File

@ -8,6 +8,7 @@
#include "senddata.h"
#include "cyclic.h"
#include "beacon_array.h"
#include "ota.h"
#include <esp_spi_flash.h> // needed for reading ESP32 chip attributes
#include <esp_event_loop.h> // needed for Wifi event handler

View File

@ -31,6 +31,11 @@ void set_reset(uint8_t val[]) {
sprintf(display_line6, "Queue reset");
flushQueues();
break;
case 9: // reset and ask for software update via Wifi OTA
ESP_LOGI(TAG, "Remote command: software update via Wifi");
sprintf(display_line6, "Software update");
cfg.runmode = 1;
break;
default:
ESP_LOGW(TAG, "Remote command: reset called with invalid parameter(s)");
}
@ -220,27 +225,22 @@ void get_gps(uint8_t val[]) {
#endif
};
void set_update(uint8_t val[]) {
ESP_LOGI(TAG, "Remote command: get firmware update");
ota_update = true;
};
// assign previously defined functions to set of numeric remote commands
// format: opcode, function, #bytes params,
// flag (1 = do make settings persistent / 0 = don't)
// flag (true = do make settings persistent / false = don't)
//
cmd_t table[] = {
{0x01, set_rssi, 1, true}, {0x02, set_countmode, 1, true},
{0x03, set_gps, 1, true}, {0x04, set_display, 1, true},
{0x05, set_lorasf, 1, true}, {0x06, set_lorapower, 1, true},
{0x07, set_loraadr, 1, true}, {0x08, set_screensaver, 1, true},
{0x09, set_reset, 1, false}, {0x0a, set_sendcycle, 1, true},
{0x09, set_reset, 1, true}, {0x0a, set_sendcycle, 1, true},
{0x0b, set_wifichancycle, 1, true}, {0x0c, set_blescantime, 1, true},
{0x0d, set_vendorfilter, 1, false}, {0x0e, set_blescan, 1, true},
{0x0f, set_wifiant, 1, true}, {0x10, set_rgblum, 1, true},
{0x11, set_monitor, 1, true}, {0x12, set_beacon, 7, false},
{0x20, set_update, 0, false}, {0x80, get_config, 0, false},
{0x81, get_status, 0, false}, {0x84, get_gps, 0, false}};
{0x80, get_config, 0, false}, {0x81, get_status, 0, false},
{0x84, get_gps, 0, false}};
const uint8_t cmdtablesize =
sizeof(table) / sizeof(table[0]); // number of commands in command table