Moved index.html from SPIFFS to program memory. Removed dependencies to SPIFFS. Also, we can use a different partition scheme with much more program space instead of reserving some of it for SPIFFS.
This commit is contained in:
parent
dd9e1538c8
commit
8e15f87cd3
@ -1 +0,0 @@
|
||||
1
|
@ -20,22 +20,17 @@ read -p "Version to generate: " VERSION
|
||||
|
||||
OTA_VERSION=`grep "VERSION=" bin/update.manifest | cut -d"=" -f2`
|
||||
OTA_VERSION=$(( "$OTA_VERSION" + 1 ))
|
||||
echo "$OTA_VERSION" > data/_version.txt
|
||||
|
||||
sed -i.bak "s/#define OTA_VERSION .*/#define OTA_VERSION $OTA_VERSION/" include/config.h include/config.sample.h
|
||||
rm include/config.h.bak include/config.sample.h.bak
|
||||
|
||||
PLATFORMIO_BUILD_FLAGS='-DVERSION=\"$VERSION\"' pio run -e deploy -t buildprog || exit 1
|
||||
pio run -e deploy -t buildfs || exit 1
|
||||
|
||||
cp .pio/build/deploy/firmware.bin bin/firmware.bin || exit 1
|
||||
cp .pio/build/deploy/spiffs.bin bin/spiffs.bin || exit 1
|
||||
|
||||
sed -i.bak "s/VERSION=.*/VERSION=$OTA_VERSION/" bin/update.manifest
|
||||
MD5=`md5sum --binary bin/firmware.bin | cut -d" " -f1`
|
||||
sed -i.bak "s/IMAGE_MD5=.*/IMAGE_MD5=$MD5/" bin/update.manifest
|
||||
MD5=`md5sum --binary bin/spiffs.bin | cut -d" " -f1`
|
||||
sed -i.bak "s/SPIFFS_MD5=.*/SPIFFS_MD5=$MD5/" bin/update.manifest
|
||||
rm bin/update.manifest.bak
|
||||
|
||||
echo; echo; echo; echo; echo
|
||||
@ -44,7 +39,7 @@ git diff
|
||||
|
||||
read -p "Press ENTER to continue, Ctrl-C to abort. " foo
|
||||
|
||||
git add bin/firmware.bin bin/spiffs.bin bin/update.manifest
|
||||
git add bin/firmware.bin bin/update.manifest
|
||||
git commit -m "Deploying version $VERSION."
|
||||
git tag -a -m "Deploying version $VERSION" $VERSION
|
||||
git push --follow-tags
|
||||
|
@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
extern uint16_t spiffs_version;
|
||||
void wifi_connect();
|
||||
|
||||
extern const uint8_t file_index_html_start[] asm("_binary_src_index_html_start");
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
class Updater {
|
||||
public:
|
||||
static void run(uint16_t spiffs_version = 0);
|
||||
static void run();
|
||||
static bool do_update(int cmd, String url, String expected_md5);
|
||||
static bool read_line(String* dst, HTTPClientWrapper* http, String expected_key);
|
||||
};
|
||||
|
6
partitions.csv
Normal file
6
partitions.csv
Normal file
@ -0,0 +1,6 @@
|
||||
# Custom partition table without SPIFFS.
|
||||
# Name, Type, SubType, Offset, Size, Flags
|
||||
nvs, data, nvs, 0x9000, 0x5000,
|
||||
otadata, data, ota, 0xe000, 0x2000,
|
||||
app0, app, ota_0, 0x10000, 0x220000,
|
||||
app1, app, ota_1, 0x230000,0x220000,
|
|
@ -27,6 +27,8 @@ build_flags=!./build_version.sh
|
||||
lib_deps = ${extra.lib_deps}
|
||||
upload_port = /dev/cu.SLAB_USBtoUART
|
||||
monitor_speed = 74480
|
||||
board_build.embed_txtfiles = src/index.html
|
||||
board_build.partitions = partitions.csv
|
||||
;monitor_port = /dev/cu.wchusbserial1420
|
||||
|
||||
[env:deploy]
|
||||
@ -34,3 +36,5 @@ platform = espressif32
|
||||
board = esp-wrover-kit
|
||||
framework = arduino
|
||||
lib_deps = ${extra.lib_deps}
|
||||
board_build.embed_txtfiles = src/index.html
|
||||
board_build.partitions = partitions.csv
|
||||
|
@ -378,7 +378,6 @@ String Controller::json() {
|
||||
json["uptime"] = millis() / 1000;
|
||||
json["free_heap"] = ESP.getFreeHeap();
|
||||
JsonObject versions = json.createNestedObject("versions");
|
||||
versions["spiffs"] = spiffs_version;
|
||||
versions["ota"] = OTA_VERSION;
|
||||
#ifdef VERSION
|
||||
versions["release"] = VERSION;
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include "http_server.h"
|
||||
#include "main.h"
|
||||
#include "spi_master.h"
|
||||
#include <ESPmDNS.h>
|
||||
#include <SPIFFS.h>
|
||||
|
||||
HTTPServer::HTTPServer(Player* p, Controller* c) {
|
||||
_player = p;
|
||||
@ -12,7 +12,7 @@ HTTPServer::HTTPServer(Player* p, Controller* c) {
|
||||
ws->onEvent([&](AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventType type, void * arg, uint8_t *data, size_t len){this->_onEvent(server, client, type, arg, data, len);});
|
||||
|
||||
_server->on("/", HTTP_GET, [&](AsyncWebServerRequest* req) {
|
||||
req->send(SPIFFS, "/index.html", "text/html");
|
||||
req->send(200, "text/html", (const char*)file_index_html_start);
|
||||
});
|
||||
_server->on("/upload", HTTP_POST, [](AsyncWebServerRequest* req) {
|
||||
req->send(200);
|
||||
|
24
src/main.cpp
24
src/main.cpp
@ -3,7 +3,6 @@
|
||||
#include <SD.h>
|
||||
#include <WiFi.h>
|
||||
#include <ESPmDNS.h>
|
||||
#include <SPIFFS.h>
|
||||
#include "main.h"
|
||||
#include "config.h"
|
||||
#include "controller.h"
|
||||
@ -20,8 +19,6 @@ HTTPServer* http_server;
|
||||
|
||||
uint8_t SPIMaster::state = 0;
|
||||
|
||||
uint16_t spiffs_version = 0;
|
||||
|
||||
bool connect_to_wifi(String ssid, String pass) {
|
||||
TRACE("Connecting to wifi \"%s\"...\n", ssid.c_str());
|
||||
WiFi.mode(WIFI_AP_STA);
|
||||
@ -101,17 +98,6 @@ void setup() {
|
||||
}
|
||||
spi->select_sd(false);
|
||||
|
||||
DEBUG("Starting SPIFFS...\n");
|
||||
SPIFFS.begin(true);
|
||||
if (SPIFFS.exists("/_version.txt")) {
|
||||
File f = SPIFFS.open("/_version.txt", "r");
|
||||
spiffs_version = f.readString().toInt();
|
||||
f.close();
|
||||
DEBUG("SPIFFS filesystem version is %d.\n", spiffs_version);
|
||||
} else {
|
||||
DEBUG("No SPIFFS filesystem version found - setting spiffs_version to 0.\n");
|
||||
}
|
||||
|
||||
DEBUG("Initializing PlaylistManager...\n");
|
||||
pm = new PlaylistManager();
|
||||
|
||||
@ -122,10 +108,6 @@ void setup() {
|
||||
|
||||
wifi_connect();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
MDNS.begin("esmp3");
|
||||
|
||||
DEBUG("Setting up HTTP server...\n");
|
||||
@ -144,12 +126,6 @@ void setup() {
|
||||
INFO("Could not fetch current time via NTP.\n");
|
||||
}
|
||||
|
||||
#ifdef OTA_UPDATE_URL
|
||||
if (spiffs_version < OTA_VERSION) {
|
||||
Updater::run(spiffs_version);
|
||||
}
|
||||
#endif
|
||||
|
||||
INFO("Initialization completed.\n");
|
||||
}
|
||||
|
||||
|
@ -4,8 +4,7 @@
|
||||
#include "updater.h"
|
||||
#include "http_client_wrapper.h"
|
||||
|
||||
void Updater::run(uint16_t spiffs_version) {
|
||||
bool update_image = true;
|
||||
void Updater::run() {
|
||||
DEBUG("Updater is running...\n");
|
||||
HTTPClientWrapper* http = new HTTPClientWrapper();
|
||||
DEBUG("Requesting update info...\n");
|
||||
@ -26,13 +25,8 @@ void Updater::run(uint16_t spiffs_version) {
|
||||
}
|
||||
DEBUG("Found version %d. My version is %d.\n", version, OTA_VERSION);
|
||||
if (version <= OTA_VERSION) {
|
||||
if (spiffs_version>0 && spiffs_version < version) {
|
||||
update_image = false;
|
||||
DEBUG("SPIFFS needs an update. Continuing.\n");
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
String image_path = "";
|
||||
if (!read_line(&image_path, http, "IMAGE_PATH")) {
|
||||
@ -44,27 +38,15 @@ void Updater::run(uint16_t spiffs_version) {
|
||||
return;
|
||||
}
|
||||
|
||||
String spiffs_path = "";
|
||||
if (!read_line(&spiffs_path, http, "SPIFFS_PATH")) {
|
||||
return;
|
||||
}
|
||||
|
||||
String spiffs_md5 = "";
|
||||
if (!read_line(&spiffs_md5, http, "SPIFFS_MD5")) {
|
||||
return;
|
||||
}
|
||||
|
||||
http->close();
|
||||
delete http;
|
||||
|
||||
result = true;
|
||||
if (update_image) {
|
||||
result = do_update(U_FLASH, image_path, image_md5);
|
||||
if(do_update(U_FLASH, image_path, image_md5)) {
|
||||
DEBUG("Update done. Rebooting...\n");
|
||||
} else {
|
||||
DEBUG("Update failed. Rebooting...\n");
|
||||
}
|
||||
if (result) {
|
||||
do_update(U_SPIFFS, spiffs_path, spiffs_md5);
|
||||
}
|
||||
DEBUG("Done. Rebooting...\n");
|
||||
delay(1000);
|
||||
ESP.restart();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user