Commit 3a9ec97d authored by Eric Duminil's avatar Eric Duminil
Browse files

Trying http update. Works with HTTP on ESP8266

parent 7a296269
Pipeline #5928 failed with stage
in 2 minutes and 10 seconds
#include "sensor_console.h"
namespace sensor_console {
const uint8_t MAX_COMMANDS = 26;
const uint8_t MAX_COMMANDS = 27;
//TODO: Check if it's really needed? Is it including parameter???
const uint8_t MAX_COMMAND_SIZE = 40;
......
......@@ -8,6 +8,8 @@
#if defined(ESP8266)
# include <ESP8266WiFi.h>
# include <ESP8266HTTPClient.h>
# include <ESP8266httpUpdate.h>
#elif defined(ESP32)
# include <WiFi.h>
#endif
......@@ -15,6 +17,50 @@
namespace wifi {
char local_ip[16]; // "255.255.255.255\0"
void update_started() {
Serial.println("CALLBACK: HTTP update process started");
}
void update_finished() {
Serial.println("CALLBACK: HTTP update process finished");
}
void update_progress(int cur, int total) {
Serial.printf("CALLBACK: HTTP update process at %d of %d bytes...\n", cur, total);
}
void update_error(int err) {
Serial.printf("CALLBACK: HTTP update fatal error code %d\n", err);
}
void update() {
ESPhttpUpdate.onStart(update_started);
ESPhttpUpdate.onEnd(update_finished);
ESPhttpUpdate.onProgress(update_progress);
ESPhttpUpdate.onError(update_error);
WiFiClient client;
t_httpUpdate_return ret = ESPhttpUpdate.update(client,
"http://servfbp1.fbp.hft-stuttgart.de/simstadt_doc/firmware.bin");
// Or:
//t_httpUpdate_return ret = ESPhttpUpdate.update(client, "server", 80, "file.bin");
//TODO: https://github.com/programmer131/ESP8266_ESP32_SelfUpdate
switch (ret) {
case HTTP_UPDATE_FAILED:
Serial.printf("HTTP_UPDATE_FAILD Error (%d): %s\n", ESPhttpUpdate.getLastError(),
ESPhttpUpdate.getLastErrorString().c_str());
break;
case HTTP_UPDATE_NO_UPDATES:
Serial.println("HTTP_UPDATE_NO_UPDATES");
break;
case HTTP_UPDATE_OK:
Serial.println("HTTP_UPDATE_OK");
break;
}
}
bool connected() {
return WiFi.status() == WL_CONNECTED;
}
......@@ -76,6 +122,7 @@ namespace wifi {
void defineCommands() {
sensor_console::defineCommand("wifi_scan", scanNetworks, F("(Scans available WiFi networks)"));
sensor_console::defineCommand("local_ip", showLocalIp, F("(Displays local IP and current SSID)"));
sensor_console::defineCommand("update!", update, F("(Updates to latest firmware)"));
//TODO: Add "update!" command? https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266httpUpdate/examples/httpUpdate/httpUpdate.ino
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment