Sqeeze every byte

pull/3783/head
Blaz Kristan 2024-02-25 17:08:01 +01:00
rodzic a28d2c869f
commit 41129cf379
11 zmienionych plików z 82 dodań i 58 usunięć

Wyświetl plik

@ -57,7 +57,10 @@ class UsermodTemperature : public Usermod {
static const char _parasite[]; static const char _parasite[];
static const char _parasitePin[]; static const char _parasitePin[];
static const char _domoticzIDX[]; static const char _domoticzIDX[];
static const char _sensor[];
static const char _temperature[];
static const char _Temperature[];
//Dallas sensor quick (& dirty) reading. Credit to - Author: Peter Scargill, August 17th, 2013 //Dallas sensor quick (& dirty) reading. Credit to - Author: Peter Scargill, August 17th, 2013
float readDallas(); float readDallas();
void requestTemperatures(); void requestTemperatures();
@ -191,9 +194,9 @@ void UsermodTemperature::publishHomeAssistantAutodiscovery() {
sprintf_P(buf, PSTR("%s Temperature"), serverDescription); sprintf_P(buf, PSTR("%s Temperature"), serverDescription);
json[F("name")] = buf; json[F("name")] = buf;
strcpy(buf, mqttDeviceTopic); strcpy(buf, mqttDeviceTopic);
strcat_P(buf, PSTR("/temperature")); strcat_P(buf, _Temperature);
json[F("state_topic")] = buf; json[F("state_topic")] = buf;
json[F("device_class")] = F("temperature"); json[F("device_class")] = FPSTR(_temperature);
json[F("unique_id")] = escapedMac.c_str(); json[F("unique_id")] = escapedMac.c_str();
json[F("unit_of_measurement")] = F("°C"); json[F("unit_of_measurement")] = F("°C");
payload_size = serializeJson(json, json_str); payload_size = serializeJson(json, json_str);
@ -272,7 +275,7 @@ void UsermodTemperature::loop() {
// dont publish super low temperature as the graph will get messed up // dont publish super low temperature as the graph will get messed up
// the DallasTemperature library returns -127C or -196.6F when problem // the DallasTemperature library returns -127C or -196.6F when problem
// reading the sensor // reading the sensor
strcat_P(subuf, PSTR("/temperature")); strcat_P(subuf, _Temperature);
mqtt->publish(subuf, 0, false, String(getTemperatureC()).c_str()); mqtt->publish(subuf, 0, false, String(getTemperatureC()).c_str());
strcat_P(subuf, PSTR("_f")); strcat_P(subuf, PSTR("_f"));
mqtt->publish(subuf, 0, false, String(getTemperatureF()).c_str()); mqtt->publish(subuf, 0, false, String(getTemperatureF()).c_str());
@ -335,9 +338,9 @@ void UsermodTemperature::addToJsonInfo(JsonObject& root) {
temp.add(getTemperature()); temp.add(getTemperature());
temp.add(getTemperatureUnit()); temp.add(getTemperatureUnit());
JsonObject sensor = root[F("sensor")]; JsonObject sensor = root[FPSTR(_sensor)];
if (sensor.isNull()) sensor = root.createNestedObject(F("sensor")); if (sensor.isNull()) sensor = root.createNestedObject(FPSTR(_sensor));
temp = sensor.createNestedArray(F("temperature")); temp = sensor.createNestedArray(FPSTR(_temperature));
temp.add(getTemperature()); temp.add(getTemperature());
temp.add(getTemperatureUnit()); temp.add(getTemperatureUnit());
} }
@ -367,7 +370,7 @@ void UsermodTemperature::addToConfig(JsonObject &root) {
JsonObject top = root.createNestedObject(FPSTR(_name)); // usermodname JsonObject top = root.createNestedObject(FPSTR(_name)); // usermodname
top[FPSTR(_enabled)] = enabled; top[FPSTR(_enabled)] = enabled;
top["pin"] = temperaturePin; // usermodparam top["pin"] = temperaturePin; // usermodparam
top["degC"] = degC; // usermodparam top[F("degC")] = degC; // usermodparam
top[FPSTR(_readInterval)] = readingInterval / 1000; top[FPSTR(_readInterval)] = readingInterval / 1000;
top[FPSTR(_parasite)] = parasite; top[FPSTR(_parasite)] = parasite;
top[FPSTR(_parasitePin)] = parasitePin; top[FPSTR(_parasitePin)] = parasitePin;
@ -393,7 +396,7 @@ bool UsermodTemperature::readFromConfig(JsonObject &root) {
enabled = top[FPSTR(_enabled)] | enabled; enabled = top[FPSTR(_enabled)] | enabled;
newTemperaturePin = top["pin"] | newTemperaturePin; newTemperaturePin = top["pin"] | newTemperaturePin;
degC = top["degC"] | degC; degC = top[F("degC")] | degC;
readingInterval = top[FPSTR(_readInterval)] | readingInterval/1000; readingInterval = top[FPSTR(_readInterval)] | readingInterval/1000;
readingInterval = min(120,max(10,(int)readingInterval)) * 1000; // convert to ms readingInterval = min(120,max(10,(int)readingInterval)) * 1000; // convert to ms
parasite = top[FPSTR(_parasite)] | parasite; parasite = top[FPSTR(_parasite)] | parasite;
@ -444,3 +447,6 @@ const char UsermodTemperature::_readInterval[] PROGMEM = "read-interval-s";
const char UsermodTemperature::_parasite[] PROGMEM = "parasite-pwr"; const char UsermodTemperature::_parasite[] PROGMEM = "parasite-pwr";
const char UsermodTemperature::_parasitePin[] PROGMEM = "parasite-pwr-pin"; const char UsermodTemperature::_parasitePin[] PROGMEM = "parasite-pwr-pin";
const char UsermodTemperature::_domoticzIDX[] PROGMEM = "domoticz-idx"; const char UsermodTemperature::_domoticzIDX[] PROGMEM = "domoticz-idx";
const char UsermodTemperature::_sensor[] PROGMEM = "sensor";
const char UsermodTemperature::_temperature[] PROGMEM = "temperature";
const char UsermodTemperature::_Temperature[] PROGMEM = "/temperature";

Wyświetl plik

@ -104,6 +104,9 @@ class MultiRelay : public Usermod {
static const char _HAautodiscovery[]; static const char _HAautodiscovery[];
static const char _pcf8574[]; static const char _pcf8574[];
static const char _pcfAddress[]; static const char _pcfAddress[];
static const char _switch[];
static const char _toggle[];
static const char _Command[];
void handleOffTimer(); void handleOffTimer();
void InitHtmlAPIHandle(); void InitHtmlAPIHandle();
@ -261,7 +264,7 @@ void MultiRelay::handleOffTimer() {
void MultiRelay::InitHtmlAPIHandle() { // https://github.com/me-no-dev/ESPAsyncWebServer void MultiRelay::InitHtmlAPIHandle() { // https://github.com/me-no-dev/ESPAsyncWebServer
DEBUG_PRINTLN(F("Relays: Initialize HTML API")); DEBUG_PRINTLN(F("Relays: Initialize HTML API"));
server.on("/relays", HTTP_GET, [this](AsyncWebServerRequest *request) { server.on(SET_F("/relays"), HTTP_GET, [this](AsyncWebServerRequest *request) {
DEBUG_PRINTLN(F("Relays: HTML API")); DEBUG_PRINTLN(F("Relays: HTML API"));
String janswer; String janswer;
String error = ""; String error = "";
@ -271,9 +274,9 @@ void MultiRelay::InitHtmlAPIHandle() { // https://github.com/me-no-dev/ESPAsync
if (getActiveRelayCount()) { if (getActiveRelayCount()) {
// Commands // Commands
if(request->hasParam("switch")) { if (request->hasParam(FPSTR(_switch))) {
/**** Switch ****/ /**** Switch ****/
AsyncWebParameter* p = request->getParam("switch"); AsyncWebParameter* p = request->getParam(FPSTR(_switch));
// Get Values // Get Values
for (int i=0; i<MULTI_RELAY_MAX_RELAYS; i++) { for (int i=0; i<MULTI_RELAY_MAX_RELAYS; i++) {
int value = getValue(p->value(), ',', i); int value = getValue(p->value(), ',', i);
@ -284,9 +287,9 @@ void MultiRelay::InitHtmlAPIHandle() { // https://github.com/me-no-dev/ESPAsync
if (_relay[i].external) switchRelay(i, (bool)value); if (_relay[i].external) switchRelay(i, (bool)value);
} }
} }
} else if(request->hasParam("toggle")) { } else if (request->hasParam(FPSTR(_toggle))) {
/**** Toggle ****/ /**** Toggle ****/
AsyncWebParameter* p = request->getParam("toggle"); AsyncWebParameter* p = request->getParam(FPSTR(_toggle));
// Get Values // Get Values
for (int i=0;i<MULTI_RELAY_MAX_RELAYS;i++) { for (int i=0;i<MULTI_RELAY_MAX_RELAYS;i++) {
int value = getValue(p->value(), ',', i); int value = getValue(p->value(), ',', i);
@ -314,7 +317,7 @@ void MultiRelay::InitHtmlAPIHandle() { // https://github.com/me-no-dev/ESPAsync
janswer += error; janswer += error;
janswer += F("\","); janswer += F("\",");
janswer += F("\"SW Version\":\""); janswer += F("\"SW Version\":\"");
janswer += String(GEOGABVERSION); janswer += String(F(GEOGABVERSION));
janswer += F("\"}"); janswer += F("\"}");
request->send(200, "application/json", janswer); request->send(200, "application/json", janswer);
}); });
@ -420,7 +423,7 @@ uint8_t MultiRelay::getActiveRelayCount() {
* topic should look like: /relay/X/command; where X is relay number, 0 based * topic should look like: /relay/X/command; where X is relay number, 0 based
*/ */
bool MultiRelay::onMqttMessage(char* topic, char* payload) { bool MultiRelay::onMqttMessage(char* topic, char* payload) {
if (strlen(topic) > 8 && strncmp_P(topic, PSTR("/relay/"), 7) == 0 && strncmp_P(topic+8, PSTR("/command"), 8) == 0) { if (strlen(topic) > 8 && strncmp_P(topic, PSTR("/relay/"), 7) == 0 && strncmp_P(topic+8, _Command, 8) == 0) {
uint8_t relay = strtoul(topic+7, NULL, 10); uint8_t relay = strtoul(topic+7, NULL, 10);
if (relay<MULTI_RELAY_MAX_RELAYS) { if (relay<MULTI_RELAY_MAX_RELAYS) {
String action = payload; String action = payload;
@ -430,7 +433,7 @@ bool MultiRelay::onMqttMessage(char* topic, char* payload) {
} else if (action == "off") { } else if (action == "off") {
if (_relay[relay].external) switchRelay(relay, false); if (_relay[relay].external) switchRelay(relay, false);
return true; return true;
} else if (action == "toggle") { } else if (action == FPSTR(_toggle)) {
if (_relay[relay].external) toggleRelay(relay); if (_relay[relay].external) toggleRelay(relay);
return true; return true;
} }
@ -470,7 +473,7 @@ void MultiRelay::publishHomeAssistantAutodiscovery() {
sprintf_P(buf, PSTR("%s/relay/%d"), mqttDeviceTopic, i); //max length: 33 + 7 + 3 = 43 sprintf_P(buf, PSTR("%s/relay/%d"), mqttDeviceTopic, i); //max length: 33 + 7 + 3 = 43
json["~"] = buf; json["~"] = buf;
strcat_P(buf, PSTR("/command")); strcat_P(buf, _Command);
mqtt->subscribe(buf, 0); mqtt->subscribe(buf, 0);
json[F("stat_t")] = "~"; json[F("stat_t")] = "~";
@ -675,8 +678,8 @@ void MultiRelay::addToJsonInfo(JsonObject &root) {
uiDomString += F(",on:"); uiDomString += F(",on:");
uiDomString += _relay[i].state ? "false" : "true"; uiDomString += _relay[i].state ? "false" : "true";
uiDomString += F("}});\">"); uiDomString += F("}});\">");
uiDomString += F("<i class=\"icons"); uiDomString += F("<i class=\"icons ");
uiDomString += _relay[i].state ? F(" on") : F(" off"); uiDomString += _relay[i].state ? "on" : "off";
uiDomString += F("\">&#xe08f;</i></button>"); uiDomString += F("\">&#xe08f;</i></button>");
infoArr.add(uiDomString); infoArr.add(uiDomString);
} }
@ -836,3 +839,6 @@ const char MultiRelay::_broadcast[] PROGMEM = "broadcast-sec";
const char MultiRelay::_HAautodiscovery[] PROGMEM = "HA-autodiscovery"; const char MultiRelay::_HAautodiscovery[] PROGMEM = "HA-autodiscovery";
const char MultiRelay::_pcf8574[] PROGMEM = "use-PCF8574"; const char MultiRelay::_pcf8574[] PROGMEM = "use-PCF8574";
const char MultiRelay::_pcfAddress[] PROGMEM = "PCF8574-address"; const char MultiRelay::_pcfAddress[] PROGMEM = "PCF8574-address";
const char MultiRelay::_switch[] PROGMEM = "switch";
const char MultiRelay::_toggle[] PROGMEM = "toggle";
const char MultiRelay::_Command[] PROGMEM = "/command";

Wyświetl plik

@ -112,6 +112,10 @@ bool readObjectFromFileUsingId(const char* file, uint16_t id, JsonDocument* dest
bool readObjectFromFile(const char* file, const char* key, JsonDocument* dest); bool readObjectFromFile(const char* file, const char* key, JsonDocument* dest);
void updateFSInfo(); void updateFSInfo();
void closeFile(); void closeFile();
inline bool writeObjectToFileUsingId(const String &file, uint16_t id, JsonDocument* content) { return writeObjectToFileUsingId(file.c_str(), id, content); };
inline bool writeObjectToFile(const String &file, const char* key, JsonDocument* content) { return writeObjectToFile(file.c_str(), key, content); };
inline bool readObjectFromFileUsingId(const String &file, uint16_t id, JsonDocument* dest) { return readObjectFromFileUsingId(file.c_str(), id, dest); };
inline bool readObjectFromFile(const String &file, const char* key, JsonDocument* dest) { return readObjectFromFile(file.c_str(), key, dest); };
//hue.cpp //hue.cpp
void handleHue(); void handleHue();
@ -225,6 +229,7 @@ void handlePlaylist();
void serializePlaylist(JsonObject obj); void serializePlaylist(JsonObject obj);
//presets.cpp //presets.cpp
const char *getPresetsFileName(bool persistent = true);
void initPresetsFile(); void initPresetsFile();
void handlePresets(); void handlePresets();
bool applyPreset(byte index, byte callMode = CALL_MODE_DIRECT_CHANGE); bool applyPreset(byte index, byte callMode = CALL_MODE_DIRECT_CHANGE);

Wyświetl plik

@ -416,7 +416,7 @@ static const uint8_t *getPresetCache(size_t &size) {
} }
if (!presetsCached) { if (!presetsCached) {
File file = WLED_FS.open("/presets.json", "r"); File file = WLED_FS.open(FPSTR(getPresetsFileName()), "r");
if (file) { if (file) {
presetsCachedTime = presetsModifiedTime; presetsCachedTime = presetsModifiedTime;
presetsCachedSize = 0; presetsCachedSize = 0;
@ -446,7 +446,7 @@ bool handleFileRead(AsyncWebServerRequest* request, String path){
return true; return true;
}*/ }*/
#if defined(BOARD_HAS_PSRAM) && defined(WLED_USE_PSRAM) #if defined(BOARD_HAS_PSRAM) && defined(WLED_USE_PSRAM)
if (path.endsWith("/presets.json")) { if (path.endsWith(FPSTR(getPresetsFileName()))) {
size_t psize; size_t psize;
const uint8_t *presets = getPresetCache(psize); const uint8_t *presets = getPresetCache(psize);
if (presets) { if (presets) {

Wyświetl plik

@ -317,7 +317,8 @@ void getTimeString(char* out)
sprintf_P(out,PSTR("%i-%i-%i, %02d:%02d:%02d"),year(localTime), month(localTime), day(localTime), hr, minute(localTime), second(localTime)); sprintf_P(out,PSTR("%i-%i-%i, %02d:%02d:%02d"),year(localTime), month(localTime), day(localTime), hr, minute(localTime), second(localTime));
if (useAMPM) if (useAMPM)
{ {
strcat(out,(hour(localTime) > 11)? " PM":" AM"); strcat_P(out,PSTR(" "));
strcat(out,(hour(localTime) > 11)? "PM":"AM");
} }
} }

Wyświetl plik

@ -109,7 +109,7 @@ bool PinManagerClass::allocateMultiplePins(const managed_pin_type * mptArray, by
#ifdef WLED_DEBUG #ifdef WLED_DEBUG
DEBUG_PRINT(F("PIN ALLOC: Invalid pin attempted to be allocated: GPIO ")); DEBUG_PRINT(F("PIN ALLOC: Invalid pin attempted to be allocated: GPIO "));
DEBUG_PRINT(gpio); DEBUG_PRINT(gpio);
DEBUG_PRINT(F(" as ")); DEBUG_PRINT(mptArray[i].isOutput ? "output": "input"); DEBUG_PRINT(F(" as ")); DEBUG_PRINT(mptArray[i].isOutput ? F("output"): F("input"));
DEBUG_PRINTLN(F("")); DEBUG_PRINTLN(F(""));
#endif #endif
shouldFail = true; shouldFail = true;

Wyświetl plik

@ -16,13 +16,14 @@ static char quickLoad[9];
static char saveName[33]; static char saveName[33];
static bool includeBri = true, segBounds = true, selectedOnly = false, playlistSave = false;; static bool includeBri = true, segBounds = true, selectedOnly = false, playlistSave = false;;
static const char *getFileName(bool persist = true) { static const char presets_json[] PROGMEM = "/presets.json";
return persist ? "/presets.json" : "/tmp.json"; static const char tmp_json[] PROGMEM = "/tmp.json";
const char *getPresetsFileName(bool persistent) {
return persistent ? presets_json : tmp_json;
} }
static void doSaveState() { static void doSaveState() {
bool persist = (presetToSave < 251); bool persist = (presetToSave < 251);
const char *filename = getFileName(persist);
unsigned long start = millis(); unsigned long start = millis();
while (strip.isUpdating() && millis()-start < (2*FRAMETIME_FIXED)+1) yield(); // wait 2 frames while (strip.isUpdating() && millis()-start < (2*FRAMETIME_FIXED)+1) yield(); // wait 2 frames
@ -63,11 +64,11 @@ static void doSaveState() {
if (tmpRAMbuffer!=nullptr) { if (tmpRAMbuffer!=nullptr) {
serializeJson(*fileDoc, tmpRAMbuffer, len); serializeJson(*fileDoc, tmpRAMbuffer, len);
} else { } else {
writeObjectToFileUsingId(filename, presetToSave, fileDoc); writeObjectToFileUsingId(FPSTR(getPresetsFileName(persist)), presetToSave, fileDoc);
} }
} else } else
#endif #endif
writeObjectToFileUsingId(filename, presetToSave, fileDoc); writeObjectToFileUsingId(FPSTR(getPresetsFileName(persist)), presetToSave, fileDoc);
if (persist) presetsModifiedTime = toki.second(); //unix time if (persist) presetsModifiedTime = toki.second(); //unix time
releaseJSONBufferLock(); releaseJSONBufferLock();
@ -85,8 +86,7 @@ bool getPresetName(byte index, String& name)
{ {
if (!requestJSONBufferLock(19)) return false; if (!requestJSONBufferLock(19)) return false;
bool presetExists = false; bool presetExists = false;
if (readObjectFromFileUsingId(getFileName(), index, pDoc)) if (readObjectFromFileUsingId(FPSTR(getPresetsFileName()), index, pDoc)) {
{
JsonObject fdo = pDoc->as<JsonObject>(); JsonObject fdo = pDoc->as<JsonObject>();
if (fdo["n"]) { if (fdo["n"]) {
name = (const char*)(fdo["n"]); name = (const char*)(fdo["n"]);
@ -99,12 +99,12 @@ bool getPresetName(byte index, String& name)
void initPresetsFile() void initPresetsFile()
{ {
if (WLED_FS.exists(getFileName())) return; if (WLED_FS.exists(FPSTR(getPresetsFileName()))) return;
StaticJsonDocument<64> doc; StaticJsonDocument<64> doc;
JsonObject sObj = doc.to<JsonObject>(); JsonObject sObj = doc.to<JsonObject>();
sObj.createNestedObject("0"); sObj.createNestedObject("0");
File f = WLED_FS.open(getFileName(), "w"); File f = WLED_FS.open(FPSTR(getPresetsFileName()), "w");
if (!f) { if (!f) {
errorFlag = ERR_FS_GENERAL; errorFlag = ERR_FS_GENERAL;
return; return;
@ -147,7 +147,6 @@ void handlePresets()
uint8_t tmpMode = callModeToApply; uint8_t tmpMode = callModeToApply;
JsonObject fdo; JsonObject fdo;
const char *filename = getFileName(tmpPreset < 255);
// allocate buffer // allocate buffer
if (!requestJSONBufferLock(9)) return; // will also assign fileDoc if (!requestJSONBufferLock(9)) return; // will also assign fileDoc
@ -165,7 +164,7 @@ void handlePresets()
} else } else
#endif #endif
{ {
errorFlag = readObjectFromFileUsingId(filename, tmpPreset, fileDoc) ? ERR_NONE : ERR_FS_PLOAD; errorFlag = readObjectFromFileUsingId(FPSTR(getPresetsFileName(tmpPreset < 255)), tmpPreset, fileDoc) ? ERR_NONE : ERR_FS_PLOAD;
} }
fdo = fileDoc->as<JsonObject>(); fdo = fileDoc->as<JsonObject>();
@ -234,7 +233,7 @@ void savePreset(byte index, const char* pname, JsonObject sObj)
sObj.remove(F("psave")); sObj.remove(F("psave"));
if (sObj["n"].isNull()) sObj["n"] = saveName; if (sObj["n"].isNull()) sObj["n"] = saveName;
initPresetsFile(); // just in case if someone deleted presets.json using /edit initPresetsFile(); // just in case if someone deleted presets.json using /edit
writeObjectToFileUsingId(getFileName(index<255), index, fileDoc); writeObjectToFileUsingId(FPSTR(getPresetsFileName()), index, fileDoc);
presetsModifiedTime = toki.second(); //unix time presetsModifiedTime = toki.second(); //unix time
updateFSInfo(); updateFSInfo();
} else { } else {
@ -248,7 +247,7 @@ void savePreset(byte index, const char* pname, JsonObject sObj)
void deletePreset(byte index) { void deletePreset(byte index) {
StaticJsonDocument<24> empty; StaticJsonDocument<24> empty;
writeObjectToFileUsingId(getFileName(), index, &empty); writeObjectToFileUsingId(FPSTR(getPresetsFileName()), index, &empty);
presetsModifiedTime = toki.second(); //unix time presetsModifiedTime = toki.second(); //unix time
updateFSInfo(); updateFSInfo();
} }

Wyświetl plik

@ -328,7 +328,7 @@ void WLED::setup()
DEBUG_PRINTLN(); DEBUG_PRINTLN();
DEBUG_PRINT(F("---WLED ")); DEBUG_PRINT(F("---WLED "));
DEBUG_PRINT(versionString); DEBUG_PRINT(versionString);
DEBUG_PRINT(" "); DEBUG_PRINT(F(" "));
DEBUG_PRINT(VERSION); DEBUG_PRINT(VERSION);
DEBUG_PRINTLN(F(" INIT---")); DEBUG_PRINTLN(F(" INIT---"));
#ifdef ARDUINO_ARCH_ESP32 #ifdef ARDUINO_ARCH_ESP32

Wyświetl plik

@ -8,7 +8,7 @@
*/ */
// version code in format yymmddb (b = daily build) // version code in format yymmddb (b = daily build)
#define VERSION 2402170 #define VERSION 2402250
//uncomment this if you have a "my_config.h" file you'd like to use //uncomment this if you have a "my_config.h" file you'd like to use
//#define WLED_USE_MY_CONFIG //#define WLED_USE_MY_CONFIG

Wyświetl plik

@ -365,7 +365,7 @@ void applyMacro(byte index) {
// De-EEPROM routine, upgrade from previous versions to v0.11 // De-EEPROM routine, upgrade from previous versions to v0.11
void deEEP() { void deEEP() {
if (WLED_FS.exists("/presets.json")) return; if (WLED_FS.exists(FPSTR(getPresetsFileName()))) return;
DEBUG_PRINTLN(F("Preset file not found, attempting to load from EEPROM")); DEBUG_PRINTLN(F("Preset file not found, attempting to load from EEPROM"));
DEBUGFS_PRINTLN(F("Allocating saving buffer for dEEP")); DEBUGFS_PRINTLN(F("Allocating saving buffer for dEEP"));
@ -442,7 +442,7 @@ void deEEP() {
EEPROM.end(); EEPROM.end();
File f = WLED_FS.open("/presets.json", "w"); File f = WLED_FS.open(FPSTR(getPresetsFileName()), "w");
if (!f) { if (!f) {
errorFlag = ERR_FS_GENERAL; errorFlag = ERR_FS_GENERAL;
releaseJSONBufferLock(); releaseJSONBufferLock();

Wyświetl plik

@ -170,7 +170,7 @@ static void handleUpload(AsyncWebServerRequest *request, const String& filename,
request->_tempFile = WLED_FS.open(finalname, "w"); request->_tempFile = WLED_FS.open(finalname, "w");
DEBUG_PRINT(F("Uploading ")); DEBUG_PRINT(F("Uploading "));
DEBUG_PRINTLN(finalname); DEBUG_PRINTLN(finalname);
if (finalname.equals(F("/presets.json"))) presetsModifiedTime = toki.second(); if (finalname.equals(FPSTR(getPresetsFileName()))) presetsModifiedTime = toki.second();
} }
if (len) { if (len) {
request->_tempFile.write(data,len); request->_tempFile.write(data,len);
@ -249,17 +249,19 @@ void initServer()
}); });
// "/settings/settings.js&p=x" request also handled by serveSettings() // "/settings/settings.js&p=x" request also handled by serveSettings()
static const char _style_css[] PROGMEM = "/style.css";
server.on(SET_F("/style.css"), HTTP_GET, [](AsyncWebServerRequest *request) { server.on(_style_css, HTTP_GET, [](AsyncWebServerRequest *request) {
handleStaticContent(request, F("/style.css"), 200, FPSTR(s_css), PAGE_settingsCss, PAGE_settingsCss_length); handleStaticContent(request, FPSTR(_style_css), 200, FPSTR(s_css), PAGE_settingsCss, PAGE_settingsCss_length);
}); });
server.on(SET_F("/favicon.ico"), HTTP_GET, [](AsyncWebServerRequest *request) { static const char _favicon_ico[] PROGMEM = "/favicon.ico";
handleStaticContent(request, F("/favicon.ico"), 200, F("image/x-icon"), favicon, favicon_length, false); server.on(_favicon_ico, HTTP_GET, [](AsyncWebServerRequest *request) {
handleStaticContent(request, FPSTR(_favicon_ico), 200, F("image/x-icon"), favicon, favicon_length, false);
}); });
server.on(SET_F("/skin.css"), HTTP_GET, [](AsyncWebServerRequest *request) { static const char _skin_css[] PROGMEM = "/skin.css";
if (handleFileRead(request, F("/skin.css"))) return; server.on(_skin_css, HTTP_GET, [](AsyncWebServerRequest *request) {
if (handleFileRead(request, FPSTR(_skin_css))) return;
AsyncWebServerResponse *response = request->beginResponse(200, FPSTR(s_css)); AsyncWebServerResponse *response = request->beginResponse(200, FPSTR(s_css));
request->send(response); request->send(response);
}); });
@ -363,15 +365,17 @@ void initServer()
createEditHandler(correctPIN); createEditHandler(correctPIN);
#ifndef WLED_DISABLE_OTA #ifndef WLED_DISABLE_OTA
static const char _update[] PROGMEM = "/update";
//init ota page //init ota page
server.on(SET_F("/update"), HTTP_GET, [](AsyncWebServerRequest *request){ server.on(_update, HTTP_GET, [](AsyncWebServerRequest *request){
if (otaLock) { if (otaLock) {
serveMessage(request, 401, FPSTR(s_accessdenied), FPSTR(s_unlock_ota), 254); serveMessage(request, 401, FPSTR(s_accessdenied), FPSTR(s_unlock_ota), 254);
} else } else
serveSettings(request); // checks for "upd" in URL and handles PIN serveSettings(request); // checks for "upd" in URL and handles PIN
}); });
server.on(SET_F("/update"), HTTP_POST, [](AsyncWebServerRequest *request){ server.on(_update, HTTP_POST, [](AsyncWebServerRequest *request){
if (!correctPIN) { if (!correctPIN) {
serveSettings(request, true); // handle PIN page POST request serveSettings(request, true); // handle PIN page POST request
return; return;
@ -417,7 +421,7 @@ void initServer()
} }
}); });
#else #else
server.on(SET_F("/update"), HTTP_GET, [](AsyncWebServerRequest *request){ server.on(_update, HTTP_GET, [](AsyncWebServerRequest *request){
serveMessage(request, 501, FPSTR(s_notimplemented), F("OTA updating is disabled in this build."), 254); serveMessage(request, 501, FPSTR(s_notimplemented), F("OTA updating is disabled in this build."), 254);
}); });
#endif #endif
@ -443,19 +447,22 @@ void initServer()
}); });
#ifdef WLED_ENABLE_PIXART #ifdef WLED_ENABLE_PIXART
server.on(SET_F("/pixart.htm"), HTTP_GET, [](AsyncWebServerRequest *request) { static const char _pixart_htm[] PROGMEM = "/pixart.htm";
handleStaticContent(request, F("/pixart.htm"), 200, FPSTR(s_html), PAGE_pixart, PAGE_pixart_L); server.on(_pixart_htm, HTTP_GET, [](AsyncWebServerRequest *request) {
handleStaticContent(request, FPSTR(_pixart_htm), 200, FPSTR(s_html), PAGE_pixart, PAGE_pixart_L);
}); });
#endif #endif
#ifndef WLED_DISABLE_PXMAGIC #ifndef WLED_DISABLE_PXMAGIC
server.on(SET_F("/pxmagic.htm"), HTTP_GET, [](AsyncWebServerRequest *request) { static const char _pxmagic_htm[] PROGMEM = "/pxmagic.htm";
handleStaticContent(request, F("/pxmagic.htm"), 200, FPSTR(s_html), PAGE_pxmagic, PAGE_pxmagic_L); server.on(_pxmagic_htm, HTTP_GET, [](AsyncWebServerRequest *request) {
handleStaticContent(request, FPSTR(_pxmagic_htm), 200, FPSTR(s_html), PAGE_pxmagic, PAGE_pxmagic_L);
}); });
#endif #endif
server.on(SET_F("/cpal.htm"), HTTP_GET, [](AsyncWebServerRequest *request) { static const char _cpal_htm[] PROGMEM = "/cpal.htm";
handleStaticContent(request, F("/cpal.htm"), 200, FPSTR(s_html), PAGE_cpal, PAGE_cpal_L); server.on(_cpal_htm, HTTP_GET, [](AsyncWebServerRequest *request) {
handleStaticContent(request, FPSTR(_cpal_htm), 200, FPSTR(s_html), PAGE_cpal, PAGE_cpal_L);
}); });
#ifdef WLED_ENABLE_WEBSOCKETS #ifdef WLED_ENABLE_WEBSOCKETS