Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using LittleFS and improving semver.c to fix some compiler's warning #91

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ A simple library to add support for Over-The-Air (OTA) updates to your project.
- [x] Semantic versioning support
- [ ] Checking for update via bin headers [issue 15]

## Features and Improvements added by Tuan_Karma (Anthony)

- [x] Using LitleFS instead of (deprecated) [SPIFFS](https://arduino-esp8266.readthedocs.io/en/latest/filesystem.html#spiffs-and-littlefs)
- [x] Code improvements at `semver/semver.c` to eliminate the Compiler's warnings: e.g. `warning: passing argument 3 of 'concat_num' discards 'const' qualifier ...`
- ...

## How it works

This library tries to access a JSON file hosted on a webserver, and reviews it to decide if a newer firmware has been published, if so it will download it and install it.
Expand Down
8 changes: 4 additions & 4 deletions examples/HTTP/HTTPS.ino
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Setup:
Step 1 : Set your WiFi (ssid & password)
Step 2 : set esp32fota()
Step 3 : Provide SPIFFS filesystem with root_ca.pem of your webserver
Step 3 : Provide LittleFS filesystem with root_ca.pem of your webserver

Upload:
Step 1 : Menu > Sketch > Export Compiled Library. The bin file will be saved in the sketch folder (Menu > Sketch > Show Sketch folder)
Expand All @@ -20,7 +20,7 @@
#include <WiFi.h>

#include <FS.h>
#include <SPIFFS.h>
#include <LittleFS.h>
#include <esp32fota.h>


Expand Down Expand Up @@ -51,8 +51,8 @@ void setup_wifi()

void setup()
{
// Provide spiffs with root_ca.pem to validate server certificate
SPIFFS.begin(true);
// Provide LittleFS with root_ca.pem to validate server certificate
LittleFS.begin(true);

esp32FOTA.checkURL = "https://server/fota/fota.json";
Serial.begin(115200);
Expand Down
2 changes: 1 addition & 1 deletion examples/HTTP/HTTPS_without_root_cert.ino
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <WiFi.h>

#include <FS.h>
#include <SPIFFS.h>
#include <LittleFS.h>
#include <esp32fota.h>


Expand Down
6 changes: 3 additions & 3 deletions examples/HTTP/HTTP_signature_check.ino
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include <WiFi.h>

#include <FS.h>
#include <SPIFFS.h>
#include <LittleFS.h>

#include <esp32fota.h>

Expand All @@ -34,8 +34,8 @@ void setup_wifi()
Serial.print("Connecting to ");
Serial.println(ssid);

// Need to provide SPIFFS with rsa_key.pub inside.
SPIFFS.begin( true );
// Need to provide LittleFS with rsa_key.pub inside.
LittleFS.begin( true );

WiFi.begin(ssid, password);

Expand Down
66 changes: 66 additions & 0 deletions examples/headerFileKey/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
Date: 2022-08-24
Author: Nguyen Anh Tuan <https://github.com/tuan-karma>
Feature added: use the rsa_pub_key.h to embed the key into the fimrware. This feature helps:
- Preventing someone with physical access to your esp32-board altering the rsa_pub_key in the SPI flash memory
hence compromising the next firmware update.
- Being able to update the rsa_key for the next version of your firmware conveniently.

Usges:
+ Gen the rsa_key.pub as raw format from openssl.
+ Copy and paste the raw content in rsa_key.pub into the space between a "Raw string literal" as seen above.
+ `R"~~~(<your_rsa_raw_text_here_without_any_extra_space_or_newline)~~~"`
+ Include the `...rsa_pub_key.h` only in your main.cpp code. And use the API as seen in this example.

Local server using python:
- `python -m http.server --help`

*/

#include <Arduino.h>
#include <esp32fota.h>
#include <WiFi.h>
#include <LittleFS.h>
#include "ota_rsa_pub_key.h"
namespace
{
const char *ssid = "VTCC";
const char *pass = "vtcc40pbc";
const char *current_version = "0.1.2";
}

esp32FOTA mOTA("m5stack_FOTA", current_version, rsa_pub_key, sizeof(rsa_pub_key), true);

void setup_wifi()
{
delay(10);
// LittleFS.begin(false);

Serial.printf("Connecting to %s ", ssid);
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println("\nWF Connected!");
}

void setup()
{
mOTA.checkURL = "http://10.130.0.141:8000/firmwares.json";
Serial.begin(115200);
Serial.println(current_version);
setup_wifi();
}

void loop()
{
bool updateNeeded = mOTA.execHTTPcheck();
if (updateNeeded)
{
Serial.println("A newer firmware version was found --> update");
mOTA.execOTA_internal();
}
delay(2000);
}
25 changes: 25 additions & 0 deletions examples/headerFileKey/ota_rsa_pub_key.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
static const unsigned char rsa_pub_key[] = R"~~~(-----BEGIN PUBLIC KEY-----
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA04D07cMpLUVQCLeNCUB0
IcKhKUG35JExPwqo58w/BviOueU6ibOROxf63kI+yljFg8B2aV1lB5Fi8WeftF6s
dex+Y4t5i/vBC2RlIcO9cNs1yxCVKkpTqMv4j2M9gdjyM5PAsk8VmIG/siPNiI56
MMO+1aSF6aQMaUW1kvIiMQM7d7NoqSuP+DHjYWCKrU2T3eMn/zxa9jIohyQcSfdV
uPJjZuvgmST7qHAk/7YR6lcrbB25+jqrRReloZFEvH0iSMHB+ruAihsVIrLNK6iE
kBF6UN5etYBez210Huouyneb2V7WzbLvBTf3E+fmTMyrZxPL4/DWfz0hhPkWmGpI
j1xLqknr6OTSEQ3f5YWU7byGEvs5fqaMokqR73gNjP5WzTBAFWaiH1PtaezasUtr
WZ7GegTepRvXta+A3XJVnwmhZbxB7uJsRkKxUQsqEMC+RDqH9RFalGZKaP2wrIce
TYTMhbKL6Gg/w7M514yqonIfoul2iKkN3wtlDxU7NL4bAbc6NRidgvOOLVKsNN2p
Oib3h1xgJfpW3y6kODCA71ZK47DkhS/eSR3vXGMJfx2uaas6lg5KiIo0KlHxzzMj
HqoLBoiNUfXqJ6kbAwo2o8/K/pQy06pjCCAKaozJPJ3jQl1Js22SsQKFo45UsQkD
RsvhLheT146a+Cba80NApvsCAwEAAQ==
-----END PUBLIC KEY-----
)~~~";

/*
- This file is for conveniently storing rsa_public_key to use/embed in the fimrware.
- You should only include this file once and only-once in the main.cpp source file.
- ... Then use the rsa_pub_key as a global char pointer to the raw_rsa_pub_key_c_str.
- Usage:
+ Gen the rsa_key.pub as raw format from openssl.
+ Copy and paste the raw content in rsa_key.pub into the space between a "Raw string literal" as seen above.
+ `R"~~~(<your_rsa_raw_text_here_without_any_extra_space_or_newline)~~~"`
*/
10 changes: 5 additions & 5 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name=esp32FOTA
version=0.1.6
name=esp32FOTA_T
version=0.1.0
author=Chris Joyce
maintainer=Chris Joyce <chris@joyce.id.au>
sentence=A simple library for firmware OTA updates
maintainer=Anthony <anhtuan1 at gmail dot com>
tuan-karma marked this conversation as resolved.
Show resolved Hide resolved
sentence=A fork of Chris Joye's esp32FOTA library. Some improvements by Nguyen Anh Tuan (anhtuanb1@gmail.com)
paragraph=Allows for firmware to be updated from a webserver, the device can check for updates at any time. Uses a simple JSON file to outline if a new firmware is avaiable.
category=Communication
url=https://github.com/chrisjoyce911/esp32FOTA
url=https://github.com/tuan-karma/esp32FOTA.git
tuan-karma marked this conversation as resolved.
Show resolved Hide resolved
architectures=esp32,espressif32
includes=esp32fota.h
depends=ArduinoJson
Loading