Browse Source

implement ota (still not working)

lightsleep
Hendrik Langer 7 years ago
parent
commit
6bd2443f03
  1. 13
      src/XD0OTA.cpp
  2. 3
      src/XD0OTA.h
  3. 10
      src/main.cpp

13
src/XD0OTA.cpp

@ -18,6 +18,11 @@ void XD0OTA::update(void) {
int newVersion = checkForUpdates(); int newVersion = checkForUpdates();
if (newVersion < 1) {
Serial.println("[update] connection error");
return;
}
if( newVersion > FW_VERSION ) { if( newVersion > FW_VERSION ) {
Serial.println( "Preparing to update." ); Serial.println( "Preparing to update." );
@ -27,7 +32,10 @@ void XD0OTA::update(void) {
String fwImageURL = fwURL; String fwImageURL = fwURL;
fwImageURL.concat( ".bin" ); 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) { switch(ret) {
case HTTP_UPDATE_FAILED: case HTTP_UPDATE_FAILED:
@ -61,7 +69,8 @@ int XD0OTA::checkForUpdates() {
Serial.println( fwVersionURL ); Serial.println( fwVersionURL );
HTTPClient httpClient; HTTPClient httpClient;
httpClient.begin( fwVersionURL ); httpClient.setTimeout(5000);
httpClient.begin( fwVersionURL, httpsFingerprint );
int httpCode = httpClient.GET(); int httpCode = httpClient.GET();
if( httpCode == 200 ) { if( httpCode == 200 ) {
String newFWVersion = httpClient.getString(); String newFWVersion = httpClient.getString();

3
src/XD0OTA.h

@ -7,7 +7,6 @@
#include <ESP8266httpUpdate.h> #include <ESP8266httpUpdate.h>
const int FW_VERSION = 10; 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 { class XD0OTA {
public: public:
@ -16,6 +15,7 @@ class XD0OTA {
int checkForUpdates(); int checkForUpdates();
private: private:
const char* fwUrlBase = "https://fwupdate.xd0.de/fota/"; 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(); String getMAC();
}; };
@ -37,6 +37,7 @@ server {
# SSL configuration # SSL configuration
ssl_certificate /etc/ssl/certs/xd0-fwupdate-selfsigned.crt; ssl_certificate /etc/ssl/certs/xd0-fwupdate-selfsigned.crt;
ssl_certificate_key /etc/ssl/private/xd0-fwupdate-selfsigned.key; ssl_certificate_key /etc/ssl/private/xd0-fwupdate-selfsigned.key;
#ssl_buffer_size 4k;
root /var/www/fwupdate; root /var/www/fwupdate;

10
src/main.cpp

@ -26,6 +26,8 @@ extern "C" {
#include <SDS011.h> #include <SDS011.h>
#include <XD0OTA.h>
const char* server = "ingress.opensensemap.org"; const char* server = "ingress.opensensemap.org";
#define MQTT_MAX_PACKET_SIZE 512 #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 postingInterval = 60000; //Uploadintervall in Millisekunden
constexpr unsigned int dhcp_interval = 60*60*1000; constexpr unsigned int dhcp_interval = 60*60*1000;
int loop_count = 0;
#define EXTERNAL_POWER 1 #define EXTERNAL_POWER 1
//senseBox ID //senseBox ID
@ -350,6 +354,12 @@ void ICACHE_FLASH_ATTR sendValues() {
mqttclient.loop(); mqttclient.loop();
mqttclient.disconnect(); mqttclient.disconnect();
if (loop_count == 1) {
XD0OTA ota;
ota.update();
}
loop_count++;
last_wifi_activity = millis(); last_wifi_activity = millis();
WiFi.disconnect(); WiFi.disconnect();
WiFi.mode(WIFI_OFF); WiFi.mode(WIFI_OFF);

Loading…
Cancel
Save