Web-server for handling files and updating of ESP8266 and ESP32 boards.
5.1K
Web-server for handling files and updating of ESP8266 and ESP32 boards.
ESP8266 and ESP32 boards are widely popular for all kinds of tinkering projects and hacking. These boards support Over-The-Air updating, so they can be upgrade via wifi without having to physically access them.
This project provides a web-server written in Python Flask that supports this Over-The-Air updating. Furthermore, it provides a user interface where platforms can be easily managed and update binary files easily uploaded.
The main feature are:
The server is intended to run on internal network where it cannot be accessed from the internet. As such it does not offer any security mechanisms.
To run the server in a Docker container create a directory for storing binaries. Go inside this directory and execute the following command:
docker run -d -v $PWD:/esp-update-server/bin -p 5000:5000 kstobbe/esp-update-server:latest
Using the -v option ensures files are stored outside the Docker container and are thus persisted even if the container is terminated.
In a web browser, when the server is running, enter the IP address of the machine running the server and port 5000, e.g. http://192.168.0.10:5000. Now platforms can be created and deleted. Whitelists can be managed and binaries uploaded.
Devices requesting download of a binary file for upgrade must access path update and include device name and current version number in a query like below - substitute the IP address with your own.
http://192.168.0.10:5000/update?ver=v1.0.2&dev=chase
The server will respond with HTTP Error Code:
200 A new binary is available.304 No update is needed.400 or 500 An error occurred, e.g. device not whitelisted or platform name is unknown.Below if an implementation for ESP32 that works with the server. Remember to change the IP address in the code to match your own.
#include <HTTPClient.h>
#include <HTTPUpdate.h>
#include <WiFi.h>
#define VERSION "v1.0.2"
#define HOST "Chase"
const char* urlBase = "http://192.168.0.10:5000/update";
/***************************************************/
void checkForUpdates(void)
{
String checkUrl = String( urlBase);
checkUrl.concat( "?ver=" + String(VERSION) );
checkUrl.concat( "&dev=" + String(HOST) );
Serial.println("INFO: Checking for updates at URL: " + String( checkUrl ) );
WiFiClient client;
t_httpUpdate_return ret = httpUpdate.update( client, checkUrl );
switch (ret) {
default:
case HTTP_UPDATE_FAILED:
Serial.println("ERROR: HTTP_UPDATE_FAILD Error (" + String(ESPhttpUpdate.getLastError()) + "): " + ESPhttpUpdate.getLastErrorString().c_str());
break;
case HTTP_UPDATE_NO_UPDATES:
Serial.println("INFO: HTTP_UPDATE_NO_UPDATES");
break;
case HTTP_UPDATE_OK:
Serial.println("INFO status: HTTP_UPDATE_OK");
break;
}
}
For ESP8266 the implementation is very similar with a few changes. Remember to change the IP address in the code to match your own.
#include <ESP8266HTTPClient.h>
#include <ESP8266httpUpdate.h>
#include <ESP8266WiFi.h>
#define VERSION "v1.0.2"
#define HOST "Chase"
const char* urlBase = "http://192.168.0.10:5000/update";
/***************************************************/
void checkForUpdates(void)
{
String checkUrl = String( urlBase);
checkUrl.concat( "?ver=" + String(VERSION) );
checkUrl.concat( "&dev=" + String(HOST) );
Serial.println("INFO: Checking for updates at URL: " + String( checkUrl ) );
t_httpUpdate_return ret = ESPhttpUpdate.update( checkUrl );
switch (ret) {
default:
case HTTP_UPDATE_FAILED:
Serial.println("ERROR: HTTP_UPDATE_FAILD Error (" + String(ESPhttpUpdate.getLastError()) + "): " + ESPhttpUpdate.getLastErrorString().c_str());
break;
case HTTP_UPDATE_NO_UPDATES:
Serial.println("INFO: HTTP_UPDATE_NO_UPDATES");
break;
case HTTP_UPDATE_OK:
Serial.println("INFO status: HTTP_UPDATE_OK");
break;
}
}
The code for the server is available on https://github.com/kstobbe/esp-update-server.
Content type
Image
Digest
Size
33.6 MB
Last updated
over 7 years ago
docker pull kstobbe/esp-update-server