Coder Social home page Coder Social logo

giofranco / esp-update-server Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kstobbe/esp-update-server

0.0 0.0 0.0 17 KB

Webserver to handle binary files for ESP32 and ESP8266 Over-The-Air updates.

License: MIT License

Python 66.09% CSS 5.28% HTML 28.62%

esp-update-server's Introduction

ESP Update Server

Web-server for handling files and updating of ESP8266 and ESP32 boards.

What Does It Do?

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:

  • Platform Names: Each platform supported must be created on the web interface before a binary is uploaded. If an existing platform name is not found in an uploaded binary it is rejected. Multiple devices can share the same platform name and thus receive the same binary. Individual devices are controlled through whitelists described below.
  • Semantic Versioning: Updates are only done if a newer version of a binary is available compared to the version the device is already running. Semantic versioning is assumed e.g. v1.0.2. The uploaded binary must contain a version number starting with v and three version number components i.e MAJOR, MINOR, PATCH - v1.0.2. An uploaded binary is rejected if such a version number is not found in the binary or if the version number is not increased compared to the one already known.
  • Whitelists: Download control is enforced by MAC Address whitelists. On the web interface WiFi MAC Addresses can be added and removed to created platforms. Only whitelisted devices will be allowed to update.
  • Binary Upload: Uploading binaries is simple and administration is kept to a minimum by automatic detection of platform name and version number.

How Do I Use It?

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.

Start Server From Code

To run the server directly from code start it with the following command:

python3 server.py

Start Server From Docker?

Ready-made Docker images are available on Docker Hub which support running on Linux on both AMD64 and ARM32V6 architectures - i.e. desktops, laptops, and Raspberry Pis.

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.

Access Server For Management

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.

Access Server For Update

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.

ESP32 Implementation

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(httpUpdate.getLastError()) + "): " + httpUpdate.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;
    }
}

ESP8266 Implementation

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;
    }
}

Legal

Project is under the MIT License.

esp-update-server's People

Contributors

kstobbe avatar keyopt avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.