JFrog Bintray OTA (experimental, not working yet)
This commit is contained in:
parent
cc603d4ab8
commit
0ee138b022
@ -32,14 +32,10 @@ user = cyberman54
|
|||||||
repository = paxcounter
|
repository = paxcounter
|
||||||
package = esp32-paxcounter
|
package = esp32-paxcounter
|
||||||
api_token = 9f02e2a2374c278fd79d5bcf4b4442fca9752012
|
api_token = 9f02e2a2374c278fd79d5bcf4b4442fca9752012
|
||||||
;api_token = ${env.BINTRAY_API_TOKEN}
|
|
||||||
|
|
||||||
; Wi-Fi network settings
|
|
||||||
[wifi]
|
[wifi]
|
||||||
ssid = PRENZLNET-G
|
ssid = ***
|
||||||
password = 435Huse8!?
|
password = ***
|
||||||
;ssid = ${env.PIO_WIFI_SSID}
|
|
||||||
;password = ${env.PIO_WIFI_PASSWORD}
|
|
||||||
|
|
||||||
[common]
|
[common]
|
||||||
platform = https://github.com/platformio/platform-espressif32.git
|
platform = https://github.com/platformio/platform-espressif32.git
|
||||||
|
70
src/OTA.cpp
70
src/OTA.cpp
@ -2,29 +2,61 @@
|
|||||||
|
|
||||||
const BintrayClient bintray(BINTRAY_USER, BINTRAY_REPO, BINTRAY_PACKAGE);
|
const BintrayClient bintray(BINTRAY_USER, BINTRAY_REPO, BINTRAY_PACKAGE);
|
||||||
|
|
||||||
void ota_wifi_init(void) {
|
bool Wifi_Connected = false;
|
||||||
const int RESPONSE_TIMEOUT_MS = 5000;
|
|
||||||
unsigned long timeout = millis();
|
|
||||||
|
|
||||||
ESP_ERROR_CHECK(esp_wifi_set_promiscuous(false)); // switch off monitor mode
|
static esp_err_t event_handler(void *ctx, system_event_t *event) {
|
||||||
|
switch (event->event_id) {
|
||||||
|
case SYSTEM_EVENT_STA_START:
|
||||||
|
esp_wifi_connect();
|
||||||
|
break;
|
||||||
|
case SYSTEM_EVENT_STA_GOT_IP:
|
||||||
|
Wifi_Connected = true;
|
||||||
|
break;
|
||||||
|
case SYSTEM_EVENT_STA_DISCONNECTED:
|
||||||
|
Wifi_Connected = false;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ota_wifi_init(void) {
|
||||||
|
|
||||||
|
// initialize the tcp stack
|
||||||
tcpip_adapter_init();
|
tcpip_adapter_init();
|
||||||
|
|
||||||
|
// initialize the wifi event handler
|
||||||
|
ESP_ERROR_CHECK(esp_event_loop_init(event_handler, NULL));
|
||||||
|
|
||||||
|
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
|
||||||
|
wifi_config_t sta_config = {};
|
||||||
|
|
||||||
|
strcpy((char *)sta_config.sta.ssid, WIFI_SSID);
|
||||||
|
strcpy((char *)sta_config.sta.password, WIFI_PASS);
|
||||||
|
sta_config.sta.bssid_set = false;
|
||||||
|
|
||||||
|
ESP_ERROR_CHECK(esp_wifi_set_storage(WIFI_STORAGE_RAM));
|
||||||
|
ESP_ERROR_CHECK(esp_wifi_init(&cfg));
|
||||||
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
|
ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
|
||||||
|
ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &sta_config));
|
||||||
ESP_ERROR_CHECK(esp_wifi_start());
|
ESP_ERROR_CHECK(esp_wifi_start());
|
||||||
|
|
||||||
WiFi.begin(WIFI_SSID, WIFI_PASS);
|
// print the local IP address
|
||||||
WiFi.setHostname(PROGNAME);
|
tcpip_adapter_ip_info_t ip_info;
|
||||||
|
ESP_ERROR_CHECK(tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_STA, &ip_info));
|
||||||
/*
|
ESP_LOGI(TAG, "IP %s", ip4addr_ntoa(&ip_info.ip));
|
||||||
while (WiFi.status() != WL_CONNECTED) {
|
|
||||||
ESP_LOGI(TAG, "WiFi Status %d", WiFi.status());
|
|
||||||
if (millis() - timeout > RESPONSE_TIMEOUT_MS) {
|
|
||||||
ESP_LOGE(TAG, "WiFi connection timeout. Please check your settings!");
|
|
||||||
}
|
|
||||||
|
|
||||||
delay(500);
|
|
||||||
}
|
|
||||||
|
|
||||||
configASSERT(WiFi.isConnected() == true);
|
|
||||||
*/
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void start_ota_update() {
|
||||||
|
ESP_LOGI(TAG, "Stopping Wifi task on core 0");
|
||||||
|
vTaskDelete(WifiLoopTask);
|
||||||
|
|
||||||
|
ESP_LOGI(TAG, "Stopping LORA task on core 1");
|
||||||
|
vTaskDelete(LoraTask);
|
||||||
|
|
||||||
|
ESP_LOGI(TAG, "Connecting to %s", WIFI_SSID);
|
||||||
|
ota_wifi_init();
|
||||||
|
checkFirmwareUpdates();
|
||||||
|
ESP.restart(); // reached if update was not successful
|
||||||
|
}
|
@ -5,7 +5,9 @@
|
|||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
#include <BintrayClient.h>
|
#include <BintrayClient.h>
|
||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
|
#include "ota.h"
|
||||||
|
#include "SecureOTA.h"
|
||||||
|
|
||||||
void ota_wifi_init(void);
|
void start_ota_update();
|
||||||
|
|
||||||
#endif // OTA_H
|
#endif // OTA_H
|
@ -4,6 +4,7 @@
|
|||||||
// Basic config
|
// Basic config
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
#include "senddata.h"
|
#include "senddata.h"
|
||||||
|
#include "ota.h"
|
||||||
|
|
||||||
// Local logging tag
|
// Local logging tag
|
||||||
static const char TAG[] = "main";
|
static const char TAG[] = "main";
|
||||||
@ -14,6 +15,9 @@ void doHomework() {
|
|||||||
// update uptime counter
|
// update uptime counter
|
||||||
uptime();
|
uptime();
|
||||||
|
|
||||||
|
if (ota_update)
|
||||||
|
start_ota_update();
|
||||||
|
|
||||||
// read battery voltage into global variable
|
// read battery voltage into global variable
|
||||||
#ifdef HAS_BATTERY_PROBE
|
#ifdef HAS_BATTERY_PROBE
|
||||||
batt_voltage = read_voltage();
|
batt_voltage = read_voltage();
|
||||||
|
@ -42,7 +42,8 @@ typedef struct {
|
|||||||
} MessageBuffer_t;
|
} MessageBuffer_t;
|
||||||
|
|
||||||
// global variables
|
// global variables
|
||||||
extern configData_t cfg; // current device configuration
|
extern configData_t cfg; // current device configuration
|
||||||
|
extern bool ota_update;
|
||||||
extern char display_line6[], display_line7[]; // screen buffers
|
extern char display_line6[], display_line7[]; // screen buffers
|
||||||
extern uint8_t channel; // wifi channel rotation counter
|
extern uint8_t channel; // wifi channel rotation counter
|
||||||
extern uint16_t macs_total, macs_wifi, macs_ble, batt_voltage; // display values
|
extern uint16_t macs_total, macs_wifi, macs_ble, batt_voltage; // display values
|
||||||
@ -51,7 +52,7 @@ extern hw_timer_t *channelSwitch, *sendCycle;
|
|||||||
extern portMUX_TYPE timerMux;
|
extern portMUX_TYPE timerMux;
|
||||||
extern volatile int SendCycleTimerIRQ, HomeCycleIRQ, DisplayTimerIRQ,
|
extern volatile int SendCycleTimerIRQ, HomeCycleIRQ, DisplayTimerIRQ,
|
||||||
ChannelTimerIRQ, ButtonPressedIRQ;
|
ChannelTimerIRQ, ButtonPressedIRQ;
|
||||||
//extern QueueHandle_t LoraSendQueue, SPISendQueue;
|
// extern QueueHandle_t LoraSendQueue, SPISendQueue;
|
||||||
extern TaskHandle_t WifiLoopTask;
|
extern TaskHandle_t WifiLoopTask;
|
||||||
|
|
||||||
extern std::array<uint64_t, 0xff>::iterator it;
|
extern std::array<uint64_t, 0xff>::iterator it;
|
||||||
|
@ -27,7 +27,8 @@ licenses. Refer to LICENSE.txt file in repository for more details.
|
|||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
configData_t cfg; // struct holds current device configuration
|
configData_t cfg; // struct holds current device configuration
|
||||||
|
bool ota_update = false; // triggers OTA update
|
||||||
char display_line6[16], display_line7[16]; // display buffers
|
char display_line6[16], display_line7[16]; // display buffers
|
||||||
uint8_t channel = 0; // channel rotation counter
|
uint8_t channel = 0; // channel rotation counter
|
||||||
uint16_t macs_total = 0, macs_wifi = 0, macs_ble = 0,
|
uint16_t macs_total = 0, macs_wifi = 0, macs_ble = 0,
|
||||||
@ -70,6 +71,9 @@ static const char TAG[] = "main";
|
|||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
|
||||||
|
// disable the default wifi logging
|
||||||
|
esp_log_level_set("wifi", ESP_LOG_NONE);
|
||||||
|
|
||||||
char features[100] = "";
|
char features[100] = "";
|
||||||
|
|
||||||
// disable brownout detection
|
// disable brownout detection
|
||||||
@ -92,7 +96,8 @@ void setup() {
|
|||||||
|
|
||||||
// initialize system event handler for wifi task, needed for
|
// initialize system event handler for wifi task, needed for
|
||||||
// wifi_sniffer_init()
|
// wifi_sniffer_init()
|
||||||
esp_event_loop_init(NULL, NULL);
|
// esp_event_loop_init(NULL, NULL);
|
||||||
|
//ESP_ERROR_CHECK(esp_event_loop_init(event_handler, NULL));
|
||||||
|
|
||||||
// print chip information on startup if in verbose mode
|
// print chip information on startup if in verbose mode
|
||||||
#ifdef VERBOSE
|
#ifdef VERBOSE
|
||||||
|
@ -222,17 +222,7 @@ void get_gps(uint8_t val[]) {
|
|||||||
|
|
||||||
void set_update(uint8_t val[]) {
|
void set_update(uint8_t val[]) {
|
||||||
ESP_LOGI(TAG, "Remote command: get firmware update");
|
ESP_LOGI(TAG, "Remote command: get firmware update");
|
||||||
|
ota_update = true;
|
||||||
ESP_LOGI(TAG, "Stopping Wifi task on core 0");
|
|
||||||
vTaskDelete(WifiLoopTask);
|
|
||||||
|
|
||||||
ESP_LOGI(TAG, "Stopping LORA task on core 1");
|
|
||||||
vTaskDelete(LoraTask);
|
|
||||||
|
|
||||||
ESP_LOGI(TAG, "Connecting to %s", WIFI_SSID);
|
|
||||||
ota_wifi_init();
|
|
||||||
checkFirmwareUpdates();
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// assign previously defined functions to set of numeric remote commands
|
// assign previously defined functions to set of numeric remote commands
|
||||||
|
@ -6,10 +6,6 @@
|
|||||||
#include "lorawan.h"
|
#include "lorawan.h"
|
||||||
#include "macsniff.h"
|
#include "macsniff.h"
|
||||||
#include <rom/rtc.h>
|
#include <rom/rtc.h>
|
||||||
#include "ota.h"
|
|
||||||
|
|
||||||
#include <WiFi.h>
|
|
||||||
#include "SecureOTA.h"
|
|
||||||
|
|
||||||
// table of remote commands and assigned functions
|
// table of remote commands and assigned functions
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
Loading…
Reference in New Issue
Block a user