OTA (experimental)
This commit is contained in:
1 parent
0667ee5744
commit
fb7c32e5c8
7 files changed
+31
-22
No files matched your search
+14
-11
@@ -15,10 +15,7 @@
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
#include <WiFiClientSecure.h>
|
||||
#include <Update.h>
|
||||
#include <BintrayClient.h>
|
||||
#include "ota.h"
|
||||
#include "OTA.h"
|
||||
|
||||
const BintrayClient bintray(BINTRAY_USER, BINTRAY_REPO, BINTRAY_PACKAGE);
|
||||
|
||||
@@ -41,15 +38,20 @@ void start_ota_update() {
|
||||
|
||||
WiFi.begin(WIFI_SSID, WIFI_PASS);
|
||||
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
delay(2000);
|
||||
int i = WIFI_MAX_TRY;
|
||||
while (i--) {
|
||||
ESP_LOGI(TAG, "trying to connect to %s", WIFI_SSID);
|
||||
if (WiFi.status() == WL_CONNECTED)
|
||||
break;
|
||||
delay(5000);
|
||||
}
|
||||
if (i >= 0) {
|
||||
ESP_LOGI(TAG, "connected to %s", WIFI_SSID);
|
||||
checkFirmwareUpdates(); // gets and flashes new firmware and restarts
|
||||
} else
|
||||
ESP_LOGI(TAG, "could not connect to %s, rebooting.", WIFI_SSID);
|
||||
|
||||
ESP_LOGI(TAG, "connected to %s", WIFI_SSID);
|
||||
|
||||
checkFirmwareUpdates(); // gets and flashes new firmware and restarts
|
||||
ESP.restart(); // reached only if update was not successful
|
||||
ESP.restart(); // reached only if update was not successful or no wifi connect
|
||||
|
||||
} // start_ota_update
|
||||
|
||||
@@ -191,7 +193,8 @@ void processOTAUpdate(const String &version) {
|
||||
if (written == contentLength) {
|
||||
ESP_LOGI(TAG, "Written %d bytes successfully", written);
|
||||
} else {
|
||||
ESP_LOGI(TAG, "Written only %d of %d bytes, OTA update cancelled.", written, contentLength);
|
||||
ESP_LOGI(TAG, "Written only %d of %d bytes, OTA update cancelled.",
|
||||
written, contentLength);
|
||||
// Retry??
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
#ifndef OTA_H
|
||||
#define OTA_H
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <WiFi.h>
|
||||
#include "globals.h"
|
||||
#include <WiFiClientSecure.h>
|
||||
#include <Update.h>
|
||||
#include <BintrayClient.h>
|
||||
|
||||
void checkFirmwareUpdates();
|
||||
void processOTAUpdate(const String &version);
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@
|
||||
// Basic config
|
||||
#include "globals.h"
|
||||
#include "senddata.h"
|
||||
#include "ota.h"
|
||||
#include "OTA.h"
|
||||
|
||||
// Local logging tag
|
||||
static const char TAG[] = "main";
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@
|
||||
#include "senddata.h"
|
||||
#include "cyclic.h"
|
||||
#include "beacon_array.h"
|
||||
#include "ota.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
|
||||
|
||||
@@ -63,6 +63,9 @@
|
||||
#define DISPLAYREFRESH_MS 40 // OLED refresh cycle in ms [default = 40] -> 1000/40 = 25 frames per second
|
||||
#define HOMECYCLE 30 // house keeping cycle in seconds [default = 30 secs]
|
||||
|
||||
// OTA settings
|
||||
#define WIFI_MAX_TRY 20 // maximum number of wifi connect attempts for OTA update [default = 20]
|
||||
|
||||
// LMIC settings
|
||||
// define hardware independent LMIC settings here, settings of standard library in /lmic/config.h will be ignored
|
||||
// define hardware specifics settings in platformio.ini as build_flag for hardware environment
|
||||
|
||||
Reference in new issue
Block a user