From 6bd2443f03d7765167c3e5b77b7907050673f016 Mon Sep 17 00:00:00 2001 From: Hendrik Langer Date: Sat, 16 Jun 2018 14:57:18 +0200 Subject: [PATCH] implement ota (still not working) --- src/XD0OTA.cpp | 13 +++++++++++-- src/XD0OTA.h | 3 ++- src/main.cpp | 10 ++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/XD0OTA.cpp b/src/XD0OTA.cpp index 565dbc7..91705b8 100644 --- a/src/XD0OTA.cpp +++ b/src/XD0OTA.cpp @@ -18,6 +18,11 @@ void XD0OTA::update(void) { int newVersion = checkForUpdates(); + if (newVersion < 1) { + Serial.println("[update] connection error"); + return; + } + if( newVersion > FW_VERSION ) { Serial.println( "Preparing to update." ); @@ -27,7 +32,10 @@ void XD0OTA::update(void) { String fwImageURL = fwURL; fwImageURL.concat( ".bin" ); - t_httpUpdate_return ret = ESPhttpUpdate.update( fwImageURL ); + Serial.print( "Firmware image URL: " ); + Serial.println( fwImageURL ); + + t_httpUpdate_return ret = ESPhttpUpdate.update( fwImageURL, String(FW_VERSION), httpsFingerprint ); switch(ret) { case HTTP_UPDATE_FAILED: @@ -61,7 +69,8 @@ int XD0OTA::checkForUpdates() { Serial.println( fwVersionURL ); HTTPClient httpClient; - httpClient.begin( fwVersionURL ); + httpClient.setTimeout(5000); + httpClient.begin( fwVersionURL, httpsFingerprint ); int httpCode = httpClient.GET(); if( httpCode == 200 ) { String newFWVersion = httpClient.getString(); diff --git a/src/XD0OTA.h b/src/XD0OTA.h index ac9f137..21a527a 100644 --- a/src/XD0OTA.h +++ b/src/XD0OTA.h @@ -7,7 +7,6 @@ #include const int FW_VERSION = 10; -const char* httpsFingerprint = "37 42 61 B9 E6 EE 22 36 D1 59 67 7D 55 53 6E A4 C7 AA 60 26"; class XD0OTA { public: @@ -16,6 +15,7 @@ class XD0OTA { int checkForUpdates(); private: const char* fwUrlBase = "https://fwupdate.xd0.de/fota/"; + const char* httpsFingerprint = "37 42 61 B9 E6 EE 22 36 D1 59 67 7D 55 53 6E A4 C7 AA 60 26"; String getMAC(); }; @@ -37,6 +37,7 @@ server { # SSL configuration ssl_certificate /etc/ssl/certs/xd0-fwupdate-selfsigned.crt; ssl_certificate_key /etc/ssl/private/xd0-fwupdate-selfsigned.key; + #ssl_buffer_size 4k; root /var/www/fwupdate; diff --git a/src/main.cpp b/src/main.cpp index 0007d37..3db3a1c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -26,6 +26,8 @@ extern "C" { #include +#include + const char* server = "ingress.opensensemap.org"; #define MQTT_MAX_PACKET_SIZE 512 @@ -36,6 +38,8 @@ const char* mqttpassword = "password4"; constexpr unsigned int postingInterval = 60000; //Uploadintervall in Millisekunden constexpr unsigned int dhcp_interval = 60*60*1000; +int loop_count = 0; + #define EXTERNAL_POWER 1 //senseBox ID @@ -350,6 +354,12 @@ void ICACHE_FLASH_ATTR sendValues() { mqttclient.loop(); mqttclient.disconnect(); + if (loop_count == 1) { + XD0OTA ota; + ota.update(); + } + loop_count++; + last_wifi_activity = millis(); WiFi.disconnect(); WiFi.mode(WIFI_OFF);