diff --git a/wled00/fcn_declare.h b/wled00/fcn_declare.h
index a95064a2a..6ce30facf 100644
--- a/wled00/fcn_declare.h
+++ b/wled00/fcn_declare.h
@@ -302,7 +302,7 @@ class Usermod {
virtual bool handleButton(uint8_t b) { return false; } // button overrides are possible here
virtual bool getUMData(um_data_t **data) { if (data) *data = nullptr; return false; }; // usermod data exchange [see examples for audio effects]
virtual void connected() {} // called when WiFi is (re)connected
- virtual void appendConfigData() {} // helper function called from usermod settings page to add metadata for entry fields
+ virtual void appendConfigData(Print&) {} // helper function called from usermod settings page to add metadata for entry fields
virtual void addToJsonState(JsonObject& obj) {} // add JSON objects for WLED state
virtual void addToJsonInfo(JsonObject& obj) {} // add JSON objects for UI Info page
virtual void readFromJsonState(JsonObject& obj) {} // process JSON messages received from web server
@@ -328,7 +328,7 @@ class UsermodManager {
bool getUMData(um_data_t **um_data, uint8_t mod_id = USERMOD_ID_RESERVED); // USERMOD_ID_RESERVED will poll all usermods
void setup();
void connected();
- void appendConfigData();
+ void appendConfigData(Print&);
void addToJsonState(JsonObject& obj);
void addToJsonInfo(JsonObject& obj);
void readFromJsonState(JsonObject& obj);
@@ -362,10 +362,8 @@ void parseNumber(const char* str, byte* val, byte minv=0, byte maxv=255);
bool getVal(JsonVariant elem, byte* val, byte minv=0, byte maxv=255);
bool getBoolVal(JsonVariant elem, bool dflt);
bool updateVal(const char* req, const char* key, byte* val, byte minv=0, byte maxv=255);
-bool oappend(const char* txt); // append new c string to temp buffer efficiently
-bool oappendi(int i); // append new number to temp buffer efficiently
-void sappend(char stype, const char* key, int val);
-void sappends(char stype, const char* key, char* val);
+void sappend(Print& dest, char stype, const char* key, int val);
+void sappends(Print& dest, char stype, const char* key, char* val);
void prepareHostname(char* hostname);
bool isAsterisksOnly(const char* str, byte maxLen);
bool requestJSONBufferLock(uint8_t module=255);
@@ -444,7 +442,7 @@ void wsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventTyp
void sendDataWs(AsyncWebSocketClient * client = nullptr);
//xml.cpp
-void XML_response(AsyncWebServerRequest *request, char* dest = nullptr);
-void getSettingsJS(byte subPage, char* dest);
+void XML_response(Print& dest);
+void getSettingsJS(byte subPage, Print& dest);
#endif
diff --git a/wled00/mqtt.cpp b/wled00/mqtt.cpp
index 833e6eb7d..6694be07d 100644
--- a/wled00/mqtt.cpp
+++ b/wled00/mqtt.cpp
@@ -124,6 +124,32 @@ static void onMqttMessage(char* topic, char* payload, AsyncMqttClientMessageProp
payloadStr = nullptr;
}
+// Print adapter for flat buffers
+namespace {
+class bufferPrint : public Print {
+ char* _buf;
+ size_t _size, _offset;
+ public:
+
+ bufferPrint(char* buf, size_t size) : _buf(buf), _size(size), _offset(0) {};
+
+ size_t write(const uint8_t *buffer, size_t size) {
+ size = std::min(size, _size - _offset);
+ memcpy(_buf + _offset, buffer, size);
+ _offset += size;
+ return size;
+ }
+
+ size_t write(uint8_t c) {
+ return this->write(&c, 1);
+ }
+
+ char* data() const { return _buf; }
+ size_t size() const { return _offset; }
+ size_t capacity() const { return _size; }
+};
+}; // anonymous namespace
+
void publishMqtt()
{
@@ -148,11 +174,13 @@ void publishMqtt()
strcat_P(subuf, PSTR("/status"));
mqtt->publish(subuf, 0, true, "online"); // retain message for a LWT
- char apires[1024]; // allocating 1024 bytes from stack can be risky
- XML_response(nullptr, apires);
+ // TODO: use a DynamicBufferList. Requires a list-read-capable MQTT client API.
+ DynamicBuffer buf(1024);
+ bufferPrint pbuf(buf.data(), buf.size());
+ XML_response(pbuf);
strlcpy(subuf, mqttDeviceTopic, 33);
strcat_P(subuf, PSTR("/v"));
- mqtt->publish(subuf, 0, retainMqttMsg, apires); // optionally retain message (#2263)
+ mqtt->publish(subuf, 0, retainMqttMsg, buf.data(), pbuf.size()); // optionally retain message (#2263)
#endif
}
diff --git a/wled00/set.cpp b/wled00/set.cpp
index 812bcc52f..05b5b3181 100644
--- a/wled00/set.cpp
+++ b/wled00/set.cpp
@@ -1191,7 +1191,11 @@ bool handleSet(AsyncWebServerRequest *request, const String& req, bool apply)
// internal call, does not send XML response
pos = req.indexOf(F("IN"));
- if (pos < 1) XML_response(request);
+ if (pos < 1) {
+ auto response = request->beginResponseStream("text/xml");
+ XML_response(*response);
+ request->send(response);
+ }
return true;
}
diff --git a/wled00/um_manager.cpp b/wled00/um_manager.cpp
index 2db29c3cd..3970e7af4 100644
--- a/wled00/um_manager.cpp
+++ b/wled00/um_manager.cpp
@@ -8,7 +8,7 @@ void UsermodManager::setup() { for (unsigned i = 0; i < numMods; i++
void UsermodManager::connected() { for (unsigned i = 0; i < numMods; i++) ums[i]->connected(); }
void UsermodManager::loop() { for (unsigned i = 0; i < numMods; i++) ums[i]->loop(); }
void UsermodManager::handleOverlayDraw() { for (unsigned i = 0; i < numMods; i++) ums[i]->handleOverlayDraw(); }
-void UsermodManager::appendConfigData() { for (unsigned i = 0; i < numMods; i++) ums[i]->appendConfigData(); }
+void UsermodManager::appendConfigData(Print& dest) { for (unsigned i = 0; i < numMods; i++) ums[i]->appendConfigData(dest); }
bool UsermodManager::handleButton(uint8_t b) {
bool overrideIO = false;
for (unsigned i = 0; i < numMods; i++) {
diff --git a/wled00/util.cpp b/wled00/util.cpp
index 99a75bdd3..00506ea97 100644
--- a/wled00/util.cpp
+++ b/wled00/util.cpp
@@ -89,88 +89,43 @@ bool updateVal(const char* req, const char* key, byte* val, byte minv, byte maxv
//append a numeric setting to string buffer
-void sappend(char stype, const char* key, int val)
+void sappend(Print& dest, char stype, const char* key, int val)
{
- char ds[] = "d.Sf.";
-
+ const __FlashStringHelper* type_str;
switch(stype)
{
case 'c': //checkbox
- oappend(ds);
- oappend(key);
- oappend(".checked=");
- oappendi(val);
- oappend(";");
+ type_str = F(".checked=");
break;
case 'v': //numeric
- oappend(ds);
- oappend(key);
- oappend(".value=");
- oappendi(val);
- oappend(";");
+ type_str = F(".value=");
break;
case 'i': //selectedIndex
- oappend(ds);
- oappend(key);
- oappend(SET_F(".selectedIndex="));
- oappendi(val);
- oappend(";");
+ type_str = F(".selectedIndex=");
break;
+ default:
+ return; //???
}
+
+ dest.printf_P(PSTR("d.Sf.%s%s%d;"), key, type_str, val);
}
//append a string setting to buffer
-void sappends(char stype, const char* key, char* val)
+void sappends(Print& dest, char stype, const char* key, char* val)
{
switch(stype)
{
case 's': {//string (we can interpret val as char*)
- String buf = val;
- //convert "%" to "%%" to make EspAsyncWebServer happy
- //buf.replace("%","%%");
- oappend("d.Sf.");
- oappend(key);
- oappend(".value=\"");
- oappend(buf.c_str());
- oappend("\";");
+ dest.printf_P(PSTR("d.Sf.%s.value=\"%s\";"),key,val);
break;}
case 'm': //message
- oappend(SET_F("d.getElementsByClassName"));
- oappend(key);
- oappend(SET_F(".innerHTML=\""));
- oappend(val);
- oappend("\";");
+ dest.printf_P(PSTR("d.getElementsByClassName%s.innerHTML=\"%s\";"), key, val);
break;
}
}
-bool oappendi(int i)
-{
- char s[12]; // 32bit signed number can have 10 digits plus - sign
- sprintf(s, "%d", i);
- return oappend(s);
-}
-
-
-bool oappend(const char* txt)
-{
- unsigned len = strlen(txt);
- if ((obuf == nullptr) || (olen + len >= SETTINGS_STACK_BUF_SIZE)) { // sanity checks
-#ifdef WLED_DEBUG
- DEBUG_PRINT(F("oappend() buffer overflow. Cannot append "));
- DEBUG_PRINT(len); DEBUG_PRINT(F(" bytes \t\""));
- DEBUG_PRINT(txt); DEBUG_PRINTLN(F("\""));
-#endif
- return false; // buffer full
- }
- strcpy(obuf + olen, txt);
- olen += len;
- return true;
-}
-
-
void prepareHostname(char* hostname)
{
sprintf_P(hostname, PSTR("wled-%*s"), 6, escapedMac.c_str() + 6);
diff --git a/wled00/wled.h b/wled00/wled.h
index 31a612858..052f29b29 100644
--- a/wled00/wled.h
+++ b/wled00/wled.h
@@ -839,10 +839,6 @@ WLED_GLOBAL time_t sunrise _INIT(0);
WLED_GLOBAL time_t sunset _INIT(0);
WLED_GLOBAL Toki toki _INIT(Toki());
-// Temp buffer
-WLED_GLOBAL char* obuf;
-WLED_GLOBAL uint16_t olen _INIT(0);
-
// General filesystem
WLED_GLOBAL size_t fsBytesUsed _INIT(0);
WLED_GLOBAL size_t fsBytesTotal _INIT(0);
diff --git a/wled00/wled_server.cpp b/wled00/wled_server.cpp
index 9d4e4c85b..8fdcb1ebe 100644
--- a/wled00/wled_server.cpp
+++ b/wled00/wled_server.cpp
@@ -520,27 +520,23 @@ void serveSettingsJS(AsyncWebServerRequest* request)
handleStaticContent(request, FPSTR(_common_js), 200, FPSTR(CONTENT_TYPE_JAVASCRIPT), JS_common, JS_common_length);
return;
}
- char buf[SETTINGS_STACK_BUF_SIZE+37];
- buf[0] = 0;
byte subPage = request->arg(F("p")).toInt();
if (subPage > 10) {
- strcpy_P(buf, PSTR("alert('Settings for this request are not implemented.');"));
- request->send(501, FPSTR(CONTENT_TYPE_JAVASCRIPT), buf);
+ request->send_P(501, FPSTR(CONTENT_TYPE_JAVASCRIPT), PSTR("alert('Settings for this request are not implemented.');"));
return;
}
if (subPage > 0 && !correctPIN && strlen(settingsPIN)>0) {
- strcpy_P(buf, PSTR("alert('PIN incorrect.');"));
- request->send(401, FPSTR(CONTENT_TYPE_JAVASCRIPT), buf);
+ request->send_P(401, FPSTR(CONTENT_TYPE_JAVASCRIPT), PSTR("alert('PIN incorrect.');"));
return;
}
- strcat_P(buf,PSTR("function GetV(){var d=document;"));
- getSettingsJS(subPage, buf+strlen(buf)); // this may overflow by 35bytes!!!
- strcat_P(buf,PSTR("}"));
- AsyncWebServerResponse *response;
- response = request->beginResponse(200, FPSTR(CONTENT_TYPE_JAVASCRIPT), buf);
+ AsyncResponseStream *response = request->beginResponseStream(FPSTR(CONTENT_TYPE_JAVASCRIPT));
response->addHeader(F("Cache-Control"), F("no-store"));
response->addHeader(F("Expires"), F("0"));
+
+ response->print(F("function GetV(){var d=document;"));
+ getSettingsJS(subPage, *response);
+ response->print(F("}"));
request->send(response);
}
diff --git a/wled00/xml.cpp b/wled00/xml.cpp
index 71d66d002..2d63d61f3 100644
--- a/wled00/xml.cpp
+++ b/wled00/xml.cpp
@@ -6,85 +6,80 @@
*/
//build XML response to HTTP /win API request
-void XML_response(AsyncWebServerRequest *request, char* dest)
+void XML_response(Print& dest)
{
- char sbuf[(dest == nullptr)?1024:1]; //allocate local buffer if none passed
- obuf = (dest == nullptr)? sbuf:dest;
-
- olen = 0;
- oappend(SET_F(""));
- oappendi((nightlightActive && nightlightMode > NL_MODE_SET) ? briT : bri);
- oappend(SET_F(""));
+ dest.print(F(""));
+ dest.print((nightlightActive && nightlightMode > NL_MODE_SET) ? briT : bri);
+ dest.print(F(""));
for (int i = 0; i < 3; i++)
{
- oappend("");
- oappendi(col[i]);
- oappend("");
+ dest.print("");
+ dest.print(col[i]);
+ dest.print("");
}
for (int i = 0; i < 3; i++)
{
- oappend("");
- oappendi(colSec[i]);
- oappend("");
+ dest.print("");
+ dest.print(colSec[i]);
+ dest.print("");
}
- oappend(SET_F(""));
- oappendi(notifyDirect);
- oappend(SET_F(""));
- oappendi(receiveGroups!=0);
- oappend(SET_F(""));
- oappendi(nightlightActive);
- oappend(SET_F(""));
- oappendi(nightlightMode > NL_MODE_SET);
- oappend(SET_F(""));
- oappendi(nightlightDelayMins);
- oappend(SET_F(""));
- oappendi(nightlightTargetBri);
- oappend(SET_F(""));
- oappendi(effectCurrent);
- oappend(SET_F(""));
- oappendi(effectSpeed);
- oappend(SET_F(""));
- oappendi(effectIntensity);
- oappend(SET_F(""));
- oappendi(effectPalette);
- oappend(SET_F(""));
+ dest.print(F(""));
+ dest.print(notifyDirect);
+ dest.print(F(""));
+ dest.print(receiveGroups!=0);
+ dest.print(F(""));
+ dest.print(nightlightActive);
+ dest.print(F(""));
+ dest.print(nightlightMode > NL_MODE_SET);
+ dest.print(F(""));
+ dest.print(nightlightDelayMins);
+ dest.print(F(""));
+ dest.print(nightlightTargetBri);
+ dest.print(F(""));
+ dest.print(effectCurrent);
+ dest.print(F(""));
+ dest.print(effectSpeed);
+ dest.print(F(""));
+ dest.print(effectIntensity);
+ dest.print(F(""));
+ dest.print(effectPalette);
+ dest.print(F(""));
if (strip.hasWhiteChannel()) {
- oappendi(col[3]);
+ dest.print(col[3]);
} else {
- oappend("-1");
+ dest.print("-1");
}
- oappend(SET_F(""));
- oappendi(colSec[3]);
- oappend(SET_F(""));
- oappendi(currentPreset);
- oappend(SET_F(""));
- oappendi(currentPlaylist >= 0);
- oappend(SET_F(""));
- oappend(serverDescription);
+ dest.print(F(""));
+ dest.print(colSec[3]);
+ dest.print(F(""));
+ dest.print(currentPreset);
+ dest.print(F(""));
+ dest.print(currentPlaylist >= 0);
+ dest.print(F(""));
+ dest.print(serverDescription);
if (realtimeMode)
{
- oappend(SET_F(" (live)"));
+ dest.print(F(" (live)"));
}
- oappend(SET_F(""));
- oappendi(strip.getFirstSelectedSegId());
- oappend(SET_F(""));
- if (request != nullptr) request->send(200, "text/xml", obuf);
+ dest.print(F(""));
+ dest.print(strip.getFirstSelectedSegId());
+ dest.print(F(""));
}
-void extractPin(JsonObject &obj, const char *key) {
+static void extractPin(Print& dest, JsonObject &obj, const char *key) {
if (obj[key].is()) {
JsonArray pins = obj[key].as();
for (JsonVariant pv : pins) {
- if (pv.as() > -1) { oappend(","); oappendi(pv.as()); }
+ if (pv.as() > -1) { dest.print(","); dest.print(pv.as()); }
}
} else {
- if (obj[key].as() > -1) { oappend(","); oappendi(obj[key].as()); }
+ if (obj[key].as() > -1) { dest.print(","); dest.print(obj[key].as()); }
}
}
-// oappend used pins by scanning JsonObject (1 level deep)
-void fillUMPins(JsonObject &mods)
+// dest.print used pins by scanning JsonObject (1 level deep)
+void fillUMPins(Print& dest, JsonObject &mods)
{
for (JsonPair kv : mods) {
// kv.key() is usermod name or subobject key
@@ -93,7 +88,7 @@ void fillUMPins(JsonObject &mods)
if (!obj.isNull()) {
// element is an JsonObject
if (!obj["pin"].isNull()) {
- extractPin(obj, "pin");
+ extractPin(dest, obj, "pin");
} else {
// scan keys (just one level deep as is possible with usermods)
for (JsonPair so : obj) {
@@ -102,7 +97,7 @@ void fillUMPins(JsonObject &mods)
// we found a key containing "pin" substring
if (strlen(strstr(key, "pin")) == 3) {
// and it is at the end, we found another pin
- extractPin(obj, key);
+ extractPin(dest, obj, key);
continue;
}
}
@@ -110,7 +105,7 @@ void fillUMPins(JsonObject &mods)
JsonObject subObj = obj[so.key()];
if (!subObj["pin"].isNull()) {
// get pins from subobject
- extractPin(subObj, "pin");
+ extractPin(dest, subObj, "pin");
}
}
}
@@ -118,101 +113,99 @@ void fillUMPins(JsonObject &mods)
}
}
-void appendGPIOinfo() {
+void appendGPIOinfo(Print& dest) {
char nS[8];
// add usermod pins as d.um_p array
- oappend(SET_F("d.um_p=[-1")); // has to have 1 element
+ dest.print(F("d.um_p=[-1")); // has to have 1 element
if (i2c_sda > -1 && i2c_scl > -1) {
- oappend(","); oappend(itoa(i2c_sda,nS,10));
- oappend(","); oappend(itoa(i2c_scl,nS,10));
+ dest.print(","); dest.print(itoa(i2c_sda,nS,10));
+ dest.print(","); dest.print(itoa(i2c_scl,nS,10));
}
if (spi_mosi > -1 && spi_sclk > -1) {
- oappend(","); oappend(itoa(spi_mosi,nS,10));
- oappend(","); oappend(itoa(spi_sclk,nS,10));
+ dest.print(","); dest.print(itoa(spi_mosi,nS,10));
+ dest.print(","); dest.print(itoa(spi_sclk,nS,10));
}
// usermod pin reservations will become unnecessary when settings pages will read cfg.json directly
if (requestJSONBufferLock(6)) {
// if we can't allocate JSON buffer ignore usermod pins
JsonObject mods = pDoc->createNestedObject(F("um"));
usermods.addToConfig(mods);
- if (!mods.isNull()) fillUMPins(mods);
+ if (!mods.isNull()) fillUMPins(dest, mods);
releaseJSONBufferLock();
}
- oappend(SET_F("];"));
+ dest.print(F("];"));
// add reserved (unusable) pins
- oappend(SET_F("d.rsvd=["));
+ dest.print(SET_F("d.rsvd=["));
for (unsigned i = 0; i < WLED_NUM_PINS; i++) {
if (!pinManager.isPinOk(i, false)) { // include readonly pins
- oappendi(i); oappend(",");
+ dest.print(i); dest.print(",");
}
}
#ifdef WLED_ENABLE_DMX
- oappend(SET_F("2,")); // DMX hardcoded pin
+ dest.print(SET_F("2,")); // DMX hardcoded pin
#endif
#if defined(WLED_DEBUG) && !defined(WLED_DEBUG_HOST)
- oappend(itoa(hardwareTX,nS,10)); oappend(","); // debug output (TX) pin
+ dest.print(itoa(hardwareTX,nS,10)); dest.print(","); // debug output (TX) pin
#endif
//Note: Using pin 3 (RX) disables Adalight / Serial JSON
#ifdef WLED_USE_ETHERNET
if (ethernetType != WLED_ETH_NONE && ethernetType < WLED_NUM_ETH_TYPES) {
- for (unsigned p=0; p=0) { oappend(itoa(ethernetBoards[ethernetType].eth_power,nS,10)); oappend(","); }
- if (ethernetBoards[ethernetType].eth_mdc>=0) { oappend(itoa(ethernetBoards[ethernetType].eth_mdc,nS,10)); oappend(","); }
- if (ethernetBoards[ethernetType].eth_mdio>=0) { oappend(itoa(ethernetBoards[ethernetType].eth_mdio,nS,10)); oappend(","); }
+ for (unsigned p=0; p=0) { dest.print(itoa(ethernetBoards[ethernetType].eth_power,nS,10)); dest.print(","); }
+ if (ethernetBoards[ethernetType].eth_mdc>=0) { dest.print(itoa(ethernetBoards[ethernetType].eth_mdc,nS,10)); dest.print(","); }
+ if (ethernetBoards[ethernetType].eth_mdio>=0) { dest.print(itoa(ethernetBoards[ethernetType].eth_mdio,nS,10)); dest.print(","); }
switch (ethernetBoards[ethernetType].eth_clk_mode) {
case ETH_CLOCK_GPIO0_IN:
case ETH_CLOCK_GPIO0_OUT:
- oappend(SET_F("0"));
+ dest.print(SET_F("0"));
break;
case ETH_CLOCK_GPIO16_OUT:
- oappend(SET_F("16"));
+ dest.print(SET_F("16"));
break;
case ETH_CLOCK_GPIO17_OUT:
- oappend(SET_F("17"));
+ dest.print(SET_F("17"));
break;
}
}
#endif
- oappend(SET_F("];")); // rsvd
+ dest.print(SET_F("];")); // rsvd
// add info for read-only GPIO
- oappend(SET_F("d.ro_gpio=["));
+ dest.print(SET_F("d.ro_gpio=["));
bool firstPin = true;
for (unsigned i = 0; i < WLED_NUM_PINS; i++) {
if (pinManager.isReadOnlyPin(i)) {
// No comma before the first pin
- if (!firstPin) oappend(SET_F(","));
- oappendi(i);
+ if (!firstPin) dest.print(SET_F(","));
+ dest.print(i);
firstPin = false;
}
}
- oappend(SET_F("];"));
+ dest.print(SET_F("];"));
// add info about max. # of pins
- oappend(SET_F("d.max_gpio="));
- oappendi(WLED_NUM_PINS);
- oappend(SET_F(";"));
+ dest.print(SET_F("d.max_gpio="));
+ dest.print(WLED_NUM_PINS);
+ dest.print(SET_F(";"));
}
//get values for settings form in javascript
-void getSettingsJS(byte subPage, char* dest)
+void getSettingsJS(byte subPage, Print& dest)
{
//0: menu 1: wifi 2: leds 3: ui 4: sync 5: time 6: sec
DEBUG_PRINTF_P(PSTR("settings resp %u\n"), (unsigned)subPage);
- obuf = dest;
- olen = 0;
if (subPage <0 || subPage >10) return;
if (subPage == SUBPAGE_MENU)
{
#ifdef WLED_DISABLE_2D // include only if 2D is not compiled in
- oappend(PSTR("gId('2dbtn').style.display='none';"));
+ dest.print(F("gId('2dbtn').style.display='none';"));
#endif
#ifdef WLED_ENABLE_DMX // include only if DMX is enabled
- oappend(PSTR("gId('dmxbtn').style.display='';"));
+ dest.print(F("gId('dmxbtn').style.display='';"));
#endif
}
@@ -220,65 +213,65 @@ void getSettingsJS(byte subPage, char* dest)
{
char nS[10];
size_t l;
- oappend(SET_F("resetWiFi("));
- oappend(itoa(WLED_MAX_WIFI_COUNT,nS,10));
- oappend(SET_F(");"));
+ dest.print(F("resetWiFi("));
+ dest.print(WLED_MAX_WIFI_COUNT);
+ dest.print(F(");"));
for (size_t n = 0; n < multiWiFi.size(); n++) {
l = strlen(multiWiFi[n].clientPass);
char fpass[l+1]; //fill password field with ***
fpass[l] = 0;
memset(fpass,'*',l);
- oappend(SET_F("addWiFi(\""));
- oappend(multiWiFi[n].clientSSID);
- oappend(SET_F("\",\""));
- oappend(fpass);
- oappend(SET_F("\",0x"));
- oappend(itoa(multiWiFi[n].staticIP,nS,16));
- oappend(SET_F(",0x"));
- oappend(itoa(multiWiFi[n].staticGW,nS,16));
- oappend(SET_F(",0x"));
- oappend(itoa(multiWiFi[n].staticSN,nS,16));
- oappend(SET_F(");"));
+ dest.print(F("addWiFi(\""));
+ dest.print(multiWiFi[n].clientSSID);
+ dest.print(F("\",\""));
+ dest.print(fpass);
+ dest.print(F("\",0x"));
+ dest.print(itoa(multiWiFi[n].staticIP,nS,16));
+ dest.print(F(",0x"));
+ dest.print(itoa(multiWiFi[n].staticGW,nS,16));
+ dest.print(F(",0x"));
+ dest.print(itoa(multiWiFi[n].staticSN,nS,16));
+ dest.print(F(");"));
}
- sappend('v',SET_F("D0"),dnsAddress[0]);
- sappend('v',SET_F("D1"),dnsAddress[1]);
- sappend('v',SET_F("D2"),dnsAddress[2]);
- sappend('v',SET_F("D3"),dnsAddress[3]);
+ sappend(dest,'v',SET_F("D0"),dnsAddress[0]);
+ sappend(dest,'v',SET_F("D1"),dnsAddress[1]);
+ sappend(dest,'v',SET_F("D2"),dnsAddress[2]);
+ sappend(dest,'v',SET_F("D3"),dnsAddress[3]);
- sappends('s',SET_F("CM"),cmDNS);
- sappend('i',SET_F("AB"),apBehavior);
- sappends('s',SET_F("AS"),apSSID);
- sappend('c',SET_F("AH"),apHide);
+ sappends(dest,'s',SET_F("CM"),cmDNS);
+ sappend(dest,'i',SET_F("AB"),apBehavior);
+ sappends(dest,'s',SET_F("AS"),apSSID);
+ sappend(dest,'c',SET_F("AH"),apHide);
l = strlen(apPass);
char fapass[l+1]; //fill password field with ***
fapass[l] = 0;
memset(fapass,'*',l);
- sappends('s',SET_F("AP"),fapass);
+ sappends(dest,'s',SET_F("AP"),fapass);
- sappend('v',SET_F("AC"),apChannel);
+ sappend(dest,'v',SET_F("AC"),apChannel);
#ifdef ARDUINO_ARCH_ESP32
- sappend('v',SET_F("TX"),txPower);
+ sappend(dest,'v',SET_F("TX"),txPower);
#else
- oappend(SET_F("gId('tx').style.display='none';"));
+ dest.print(F("gId('tx').style.display='none';"));
#endif
- sappend('c',SET_F("FG"),force802_3g);
- sappend('c',SET_F("WS"),noWifiSleep);
+ sappend(dest,'c',SET_F("FG"),force802_3g);
+ sappend(dest,'c',SET_F("WS"),noWifiSleep);
#ifndef WLED_DISABLE_ESPNOW
- sappend('c',SET_F("RE"),enableESPNow);
- sappends('s',SET_F("RMAC"),linked_remote);
+ sappend(dest,'c',SET_F("RE"),enableESPNow);
+ sappends(dest,'s',SET_F("RMAC"),linked_remote);
#else
//hide remote settings if not compiled
- oappend(SET_F("toggle('ESPNOW');")); // hide ESP-NOW setting
+ dest.print(F("toggle('ESPNOW');")); // hide ESP-NOW setting
#endif
#ifdef WLED_USE_ETHERNET
- sappend('v',SET_F("ETH"),ethernetType);
+ sappend(dest,'v',SET_F("ETH"),ethernetType);
#else
//hide ethernet setting if not compiled in
- oappend(SET_F("gId('ethd').style.display='none';"));
+ dest.print(F("gId('ethd').style.display='none';"));
#endif
if (Network.isConnected()) //is connected
@@ -290,10 +283,10 @@ void getSettingsJS(byte subPage, char* dest)
#if defined(ARDUINO_ARCH_ESP32) && defined(WLED_USE_ETHERNET)
if (Network.isEthernet()) strcat_P(s ,SET_F(" (Ethernet)"));
#endif
- sappends('m',SET_F("(\"sip\")[0]"),s);
+ sappends(dest,'m',SET_F("(\"sip\")[0]"),s);
} else
{
- sappends('m',SET_F("(\"sip\")[0]"),(char*)F("Not connected"));
+ sappends(dest,'m',SET_F("(\"sip\")[0]"),(char*)F("Not connected"));
}
if (WiFi.softAPIP()[0] != 0) //is active
@@ -301,19 +294,19 @@ void getSettingsJS(byte subPage, char* dest)
char s[16];
IPAddress apIP = WiFi.softAPIP();
sprintf(s, "%d.%d.%d.%d", apIP[0], apIP[1], apIP[2], apIP[3]);
- sappends('m',SET_F("(\"sip\")[1]"),s);
+ sappends(dest,'m',SET_F("(\"sip\")[1]"),s);
} else
{
- sappends('m',SET_F("(\"sip\")[1]"),(char*)F("Not active"));
+ sappends(dest,'m',SET_F("(\"sip\")[1]"),(char*)F("Not active"));
}
#ifndef WLED_DISABLE_ESPNOW
if (strlen(last_signal_src) > 0) { //Have seen an ESP-NOW Remote
- sappends('m',SET_F("(\"rlid\")[0]"),last_signal_src);
+ sappends(dest,'m',SET_F("(\"rlid\")[0]"),last_signal_src);
} else if (!enableESPNow) {
- sappends('m',SET_F("(\"rlid\")[0]"),(char*)F("(Enable ESP-NOW to listen)"));
+ sappends(dest,'m',SET_F("(\"rlid\")[0]"),(char*)F("(Enable ESP-NOW to listen)"));
} else {
- sappends('m',SET_F("(\"rlid\")[0]"),(char*)F("None"));
+ sappends(dest,'m',SET_F("(\"rlid\")[0]"),(char*)F("None"));
}
#endif
}
@@ -322,30 +315,30 @@ void getSettingsJS(byte subPage, char* dest)
{
char nS[32];
- appendGPIOinfo();
+ appendGPIOinfo(dest);
- oappend(SET_F("d.ledTypes=")); oappend(BusManager::getLEDTypesJSONString().c_str()); oappend(";");
+ dest.print(SET_F("d.ledTypes=")); dest.print(BusManager::getLEDTypesJSONString().c_str()); dest.print(";");
// set limits
- oappend(SET_F("bLimits("));
- oappend(itoa(WLED_MAX_BUSSES,nS,10)); oappend(",");
- oappend(itoa(WLED_MIN_VIRTUAL_BUSSES,nS,10)); oappend(",");
- oappend(itoa(MAX_LEDS_PER_BUS,nS,10)); oappend(",");
- oappend(itoa(MAX_LED_MEMORY,nS,10)); oappend(",");
- oappend(itoa(MAX_LEDS,nS,10)); oappend(",");
- oappend(itoa(WLED_MAX_COLOR_ORDER_MAPPINGS,nS,10)); oappend(",");
- oappend(itoa(WLED_MAX_DIGITAL_CHANNELS,nS,10)); oappend(",");
- oappend(itoa(WLED_MAX_ANALOG_CHANNELS,nS,10));
- oappend(SET_F(");"));
+ dest.print(F("bLimits("));
+ dest.print(itoa(WLED_MAX_BUSSES,nS,10)); dest.print(",");
+ dest.print(itoa(WLED_MIN_VIRTUAL_BUSSES,nS,10)); dest.print(",");
+ dest.print(itoa(MAX_LEDS_PER_BUS,nS,10)); dest.print(",");
+ dest.print(itoa(MAX_LED_MEMORY,nS,10)); dest.print(",");
+ dest.print(itoa(MAX_LEDS,nS,10)); dest.print(",");
+ dest.print(itoa(WLED_MAX_COLOR_ORDER_MAPPINGS,nS,10)); dest.print(",");
+ dest.print(itoa(WLED_MAX_DIGITAL_CHANNELS,nS,10)); dest.print(",");
+ dest.print(itoa(WLED_MAX_ANALOG_CHANNELS,nS,10));
+ dest.print(F(");"));
- sappend('c',SET_F("MS"),strip.autoSegments);
- sappend('c',SET_F("CCT"),strip.correctWB);
- sappend('c',SET_F("IC"),cctICused);
- sappend('c',SET_F("CR"),strip.cctFromRgb);
- sappend('v',SET_F("CB"),strip.cctBlending);
- sappend('v',SET_F("FR"),strip.getTargetFps());
- sappend('v',SET_F("AW"),Bus::getGlobalAWMode());
- sappend('c',SET_F("LD"),useGlobalLedBuffer);
+ sappend(dest,'c',SET_F("MS"),strip.autoSegments);
+ sappend(dest,'c',SET_F("CCT"),strip.correctWB);
+ sappend(dest,'c',SET_F("IC"),cctICused);
+ sappend(dest,'c',SET_F("CR"),strip.cctFromRgb);
+ sappend(dest,'v',SET_F("CB"),strip.cctBlending);
+ sappend(dest,'v',SET_F("FR"),strip.getTargetFps());
+ sappend(dest,'v',SET_F("AW"),Bus::getGlobalAWMode());
+ sappend(dest,'c',SET_F("LD"),useGlobalLedBuffer);
unsigned sumMa = 0;
for (int s = 0; s < BusManager::getNumBusses(); s++) {
@@ -365,22 +358,22 @@ void getSettingsJS(byte subPage, char* dest)
char sp[4] = "SP"; sp[2] = offset+s; sp[3] = 0; //bus clock speed
char la[4] = "LA"; la[2] = offset+s; la[3] = 0; //LED current
char ma[4] = "MA"; ma[2] = offset+s; ma[3] = 0; //max per-port PSU current
- oappend(SET_F("addLEDs(1);"));
+ dest.print(F("addLEDs(1);"));
uint8_t pins[5];
int nPins = bus->getPins(pins);
for (int i = 0; i < nPins; i++) {
lp[1] = offset+i;
- if (pinManager.isPinOk(pins[i]) || bus->isVirtual()) sappend('v',lp,pins[i]);
+ if (pinManager.isPinOk(pins[i]) || bus->isVirtual()) sappend(dest,'v',lp,pins[i]);
}
- sappend('v',lc,bus->getLength());
- sappend('v',lt,bus->getType());
- sappend('v',co,bus->getColorOrder() & 0x0F);
- sappend('v',ls,bus->getStart());
- sappend('c',cv,bus->isReversed());
- sappend('v',sl,bus->skippedLeds());
- sappend('c',rf,bus->isOffRefreshRequired());
- sappend('v',aw,bus->getAutoWhiteMode());
- sappend('v',wo,bus->getColorOrder() >> 4);
+ sappend(dest,'v',lc,bus->getLength());
+ sappend(dest,'v',lt,bus->getType());
+ sappend(dest,'v',co,bus->getColorOrder() & 0x0F);
+ sappend(dest,'v',ls,bus->getStart());
+ sappend(dest,'c',cv,bus->isReversed());
+ sappend(dest,'v',sl,bus->skippedLeds());
+ sappend(dest,'c',rf,bus->isOffRefreshRequired());
+ sappend(dest,'v',aw,bus->getAutoWhiteMode());
+ sappend(dest,'v',wo,bus->getColorOrder() >> 4);
unsigned speed = bus->getFrequency();
if (bus->isPWM()) {
switch (speed) {
@@ -401,158 +394,158 @@ void getSettingsJS(byte subPage, char* dest)
case 20000 : speed = 4; break;
}
}
- sappend('v',sp,speed);
- sappend('v',la,bus->getLEDCurrent());
- sappend('v',ma,bus->getMaxCurrent());
+ sappend(dest,'v',sp,speed);
+ sappend(dest,'v',la,bus->getLEDCurrent());
+ sappend(dest,'v',ma,bus->getMaxCurrent());
sumMa += bus->getMaxCurrent();
}
- sappend('v',SET_F("MA"),BusManager::ablMilliampsMax() ? BusManager::ablMilliampsMax() : sumMa);
- sappend('c',SET_F("ABL"),BusManager::ablMilliampsMax() || sumMa > 0);
- sappend('c',SET_F("PPL"),!BusManager::ablMilliampsMax() && sumMa > 0);
+ sappend(dest,'v',SET_F("MA"),BusManager::ablMilliampsMax() ? BusManager::ablMilliampsMax() : sumMa);
+ sappend(dest,'c',SET_F("ABL"),BusManager::ablMilliampsMax() || sumMa > 0);
+ sappend(dest,'c',SET_F("PPL"),!BusManager::ablMilliampsMax() && sumMa > 0);
- oappend(SET_F("resetCOM("));
- oappend(itoa(WLED_MAX_COLOR_ORDER_MAPPINGS,nS,10));
- oappend(SET_F(");"));
+ dest.print(F("resetCOM("));
+ dest.print(itoa(WLED_MAX_COLOR_ORDER_MAPPINGS,nS,10));
+ dest.print(F(");"));
const ColorOrderMap& com = BusManager::getColorOrderMap();
for (int s = 0; s < com.count(); s++) {
const ColorOrderMapEntry* entry = com.get(s);
if (entry == nullptr) break;
- oappend(SET_F("addCOM("));
- oappend(itoa(entry->start,nS,10)); oappend(",");
- oappend(itoa(entry->len,nS,10)); oappend(",");
- oappend(itoa(entry->colorOrder,nS,10)); oappend(");");
+ dest.print(F("addCOM("));
+ dest.print(itoa(entry->start,nS,10)); dest.print(",");
+ dest.print(itoa(entry->len,nS,10)); dest.print(",");
+ dest.print(itoa(entry->colorOrder,nS,10)); dest.print(");");
}
- sappend('v',SET_F("CA"),briS);
+ sappend(dest,'v',SET_F("CA"),briS);
- sappend('c',SET_F("BO"),turnOnAtBoot);
- sappend('v',SET_F("BP"),bootPreset);
+ sappend(dest,'c',SET_F("BO"),turnOnAtBoot);
+ sappend(dest,'v',SET_F("BP"),bootPreset);
- sappend('c',SET_F("GB"),gammaCorrectBri);
- sappend('c',SET_F("GC"),gammaCorrectCol);
- dtostrf(gammaCorrectVal,3,1,nS); sappends('s',SET_F("GV"),nS);
- sappend('c',SET_F("TF"),fadeTransition);
- sappend('c',SET_F("EB"),modeBlending);
- sappend('v',SET_F("TD"),transitionDelayDefault);
- sappend('c',SET_F("PF"),strip.paletteFade);
- sappend('v',SET_F("TP"),randomPaletteChangeTime);
- sappend('c',SET_F("TH"),useHarmonicRandomPalette);
- sappend('v',SET_F("BF"),briMultiplier);
- sappend('v',SET_F("TB"),nightlightTargetBri);
- sappend('v',SET_F("TL"),nightlightDelayMinsDefault);
- sappend('v',SET_F("TW"),nightlightMode);
- sappend('i',SET_F("PB"),strip.paletteBlend);
- sappend('v',SET_F("RL"),rlyPin);
- sappend('c',SET_F("RM"),rlyMde);
- sappend('c',SET_F("RO"),rlyOpenDrain);
+ sappend(dest,'c',SET_F("GB"),gammaCorrectBri);
+ sappend(dest,'c',SET_F("GC"),gammaCorrectCol);
+ dtostrf(gammaCorrectVal,3,1,nS); sappends(dest,'s',SET_F("GV"),nS);
+ sappend(dest,'c',SET_F("TF"),fadeTransition);
+ sappend(dest,'c',SET_F("EB"),modeBlending);
+ sappend(dest,'v',SET_F("TD"),transitionDelayDefault);
+ sappend(dest,'c',SET_F("PF"),strip.paletteFade);
+ sappend(dest,'v',SET_F("TP"),randomPaletteChangeTime);
+ sappend(dest,'c',SET_F("TH"),useHarmonicRandomPalette);
+ sappend(dest,'v',SET_F("BF"),briMultiplier);
+ sappend(dest,'v',SET_F("TB"),nightlightTargetBri);
+ sappend(dest,'v',SET_F("TL"),nightlightDelayMinsDefault);
+ sappend(dest,'v',SET_F("TW"),nightlightMode);
+ sappend(dest,'i',SET_F("PB"),strip.paletteBlend);
+ sappend(dest,'v',SET_F("RL"),rlyPin);
+ sappend(dest,'c',SET_F("RM"),rlyMde);
+ sappend(dest,'c',SET_F("RO"),rlyOpenDrain);
for (int i = 0; i < WLED_MAX_BUTTONS; i++) {
- oappend(SET_F("addBtn("));
- oappend(itoa(i,nS,10)); oappend(",");
- oappend(itoa(btnPin[i],nS,10)); oappend(",");
- oappend(itoa(buttonType[i],nS,10));
- oappend(SET_F(");"));
+ dest.print(F("addBtn("));
+ dest.print(itoa(i,nS,10)); dest.print(",");
+ dest.print(itoa(btnPin[i],nS,10)); dest.print(",");
+ dest.print(itoa(buttonType[i],nS,10));
+ dest.print(F(");"));
}
- sappend('c',SET_F("IP"),disablePullUp);
- sappend('v',SET_F("TT"),touchThreshold);
+ sappend(dest,'c',SET_F("IP"),disablePullUp);
+ sappend(dest,'v',SET_F("TT"),touchThreshold);
#ifndef WLED_DISABLE_INFRARED
- sappend('v',SET_F("IR"),irPin);
- sappend('v',SET_F("IT"),irEnabled);
+ sappend(dest,'v',SET_F("IR"),irPin);
+ sappend(dest,'v',SET_F("IT"),irEnabled);
#endif
- sappend('c',SET_F("MSO"),!irApplyToAllSelected);
+ sappend(dest,'c',SET_F("MSO"),!irApplyToAllSelected);
}
if (subPage == SUBPAGE_UI)
{
- sappends('s',SET_F("DS"),serverDescription);
- sappend('c',SET_F("SU"),simplifiedUI);
+ sappends(dest,'s',SET_F("DS"),serverDescription);
+ sappend(dest,'c',SET_F("SU"),simplifiedUI);
}
if (subPage == SUBPAGE_SYNC)
{
[[maybe_unused]] char nS[32];
- sappend('v',SET_F("UP"),udpPort);
- sappend('v',SET_F("U2"),udpPort2);
+ sappend(dest,'v',SET_F("UP"),udpPort);
+ sappend(dest,'v',SET_F("U2"),udpPort2);
#ifndef WLED_DISABLE_ESPNOW
- if (enableESPNow) sappend('c',SET_F("EN"),useESPNowSync);
- else oappend(SET_F("toggle('ESPNOW');")); // hide ESP-NOW setting
+ if (enableESPNow) sappend(dest,'c',SET_F("EN"),useESPNowSync);
+ else dest.print(F("toggle('ESPNOW');")); // hide ESP-NOW setting
#else
- oappend(SET_F("toggle('ESPNOW');")); // hide ESP-NOW setting
+ dest.print(F("toggle('ESPNOW');")); // hide ESP-NOW setting
#endif
- sappend('v',SET_F("GS"),syncGroups);
- sappend('v',SET_F("GR"),receiveGroups);
+ sappend(dest,'v',SET_F("GS"),syncGroups);
+ sappend(dest,'v',SET_F("GR"),receiveGroups);
- sappend('c',SET_F("RB"),receiveNotificationBrightness);
- sappend('c',SET_F("RC"),receiveNotificationColor);
- sappend('c',SET_F("RX"),receiveNotificationEffects);
- sappend('c',SET_F("RP"),receiveNotificationPalette);
- sappend('c',SET_F("SO"),receiveSegmentOptions);
- sappend('c',SET_F("SG"),receiveSegmentBounds);
- sappend('c',SET_F("SS"),sendNotifications);
- sappend('c',SET_F("SD"),notifyDirect);
- sappend('c',SET_F("SB"),notifyButton);
- sappend('c',SET_F("SH"),notifyHue);
- sappend('v',SET_F("UR"),udpNumRetries);
+ sappend(dest,'c',SET_F("RB"),receiveNotificationBrightness);
+ sappend(dest,'c',SET_F("RC"),receiveNotificationColor);
+ sappend(dest,'c',SET_F("RX"),receiveNotificationEffects);
+ sappend(dest,'c',SET_F("RP"),receiveNotificationPalette);
+ sappend(dest,'c',SET_F("SO"),receiveSegmentOptions);
+ sappend(dest,'c',SET_F("SG"),receiveSegmentBounds);
+ sappend(dest,'c',SET_F("SS"),sendNotifications);
+ sappend(dest,'c',SET_F("SD"),notifyDirect);
+ sappend(dest,'c',SET_F("SB"),notifyButton);
+ sappend(dest,'c',SET_F("SH"),notifyHue);
+ sappend(dest,'v',SET_F("UR"),udpNumRetries);
- sappend('c',SET_F("NL"),nodeListEnabled);
- sappend('c',SET_F("NB"),nodeBroadcastEnabled);
+ sappend(dest,'c',SET_F("NL"),nodeListEnabled);
+ sappend(dest,'c',SET_F("NB"),nodeBroadcastEnabled);
- sappend('c',SET_F("RD"),receiveDirect);
- sappend('c',SET_F("MO"),useMainSegmentOnly);
- sappend('c',SET_F("RLM"),realtimeRespectLedMaps);
- sappend('v',SET_F("EP"),e131Port);
- sappend('c',SET_F("ES"),e131SkipOutOfSequence);
- sappend('c',SET_F("EM"),e131Multicast);
- sappend('v',SET_F("EU"),e131Universe);
- sappend('v',SET_F("DA"),DMXAddress);
- sappend('v',SET_F("XX"),DMXSegmentSpacing);
- sappend('v',SET_F("PY"),e131Priority);
- sappend('v',SET_F("DM"),DMXMode);
- sappend('v',SET_F("ET"),realtimeTimeoutMs);
- sappend('c',SET_F("FB"),arlsForceMaxBri);
- sappend('c',SET_F("RG"),arlsDisableGammaCorrection);
- sappend('v',SET_F("WO"),arlsOffset);
+ sappend(dest,'c',SET_F("RD"),receiveDirect);
+ sappend(dest,'c',SET_F("MO"),useMainSegmentOnly);
+ sappend(dest,'c',SET_F("RLM"),realtimeRespectLedMaps);
+ sappend(dest,'v',SET_F("EP"),e131Port);
+ sappend(dest,'c',SET_F("ES"),e131SkipOutOfSequence);
+ sappend(dest,'c',SET_F("EM"),e131Multicast);
+ sappend(dest,'v',SET_F("EU"),e131Universe);
+ sappend(dest,'v',SET_F("DA"),DMXAddress);
+ sappend(dest,'v',SET_F("XX"),DMXSegmentSpacing);
+ sappend(dest,'v',SET_F("PY"),e131Priority);
+ sappend(dest,'v',SET_F("DM"),DMXMode);
+ sappend(dest,'v',SET_F("ET"),realtimeTimeoutMs);
+ sappend(dest,'c',SET_F("FB"),arlsForceMaxBri);
+ sappend(dest,'c',SET_F("RG"),arlsDisableGammaCorrection);
+ sappend(dest,'v',SET_F("WO"),arlsOffset);
#ifndef WLED_DISABLE_ALEXA
- sappend('c',SET_F("AL"),alexaEnabled);
- sappends('s',SET_F("AI"),alexaInvocationName);
- sappend('c',SET_F("SA"),notifyAlexa);
- sappend('v',SET_F("AP"),alexaNumPresets);
+ sappend(dest,'c',SET_F("AL"),alexaEnabled);
+ sappends(dest,'s',SET_F("AI"),alexaInvocationName);
+ sappend(dest,'c',SET_F("SA"),notifyAlexa);
+ sappend(dest,'v',SET_F("AP"),alexaNumPresets);
#else
- oappend(SET_F("toggle('Alexa');")); // hide Alexa settings
+ dest.print(F("toggle('Alexa');")); // hide Alexa settings
#endif
#ifndef WLED_DISABLE_MQTT
- sappend('c',SET_F("MQ"),mqttEnabled);
- sappends('s',SET_F("MS"),mqttServer);
- sappend('v',SET_F("MQPORT"),mqttPort);
- sappends('s',SET_F("MQUSER"),mqttUser);
+ sappend(dest,'c',SET_F("MQ"),mqttEnabled);
+ sappends(dest,'s',SET_F("MS"),mqttServer);
+ sappend(dest,'v',SET_F("MQPORT"),mqttPort);
+ sappends(dest,'s',SET_F("MQUSER"),mqttUser);
byte l = strlen(mqttPass);
char fpass[l+1]; //fill password field with ***
fpass[l] = 0;
memset(fpass,'*',l);
- sappends('s',SET_F("MQPASS"),fpass);
- sappends('s',SET_F("MQCID"),mqttClientID);
- sappends('s',"MD",mqttDeviceTopic);
- sappends('s',SET_F("MG"),mqttGroupTopic);
- sappend('c',SET_F("BM"),buttonPublishMqtt);
- sappend('c',SET_F("RT"),retainMqttMsg);
- oappend(SET_F("d.Sf.MD.maxlength=")); oappend(itoa(MQTT_MAX_TOPIC_LEN,nS,10)); oappend(SET_F(";"));
- oappend(SET_F("d.Sf.MG.maxlength=")); oappend(itoa(MQTT_MAX_TOPIC_LEN,nS,10)); oappend(SET_F(";"));
- oappend(SET_F("d.Sf.MS.maxlength=")); oappend(itoa(MQTT_MAX_SERVER_LEN,nS,10)); oappend(SET_F(";"));
+ sappends(dest,'s',SET_F("MQPASS"),fpass);
+ sappends(dest,'s',SET_F("MQCID"),mqttClientID);
+ sappends(dest,'s',"MD",mqttDeviceTopic);
+ sappends(dest,'s',SET_F("MG"),mqttGroupTopic);
+ sappend(dest,'c',SET_F("BM"),buttonPublishMqtt);
+ sappend(dest,'c',SET_F("RT"),retainMqttMsg);
+ dest.print(F("d.Sf.MD.maxlength=")); dest.print(itoa(MQTT_MAX_TOPIC_LEN,nS,10)); dest.print(F(";"));
+ dest.print(F("d.Sf.MG.maxlength=")); dest.print(itoa(MQTT_MAX_TOPIC_LEN,nS,10)); dest.print(F(";"));
+ dest.print(F("d.Sf.MS.maxlength=")); dest.print(itoa(MQTT_MAX_SERVER_LEN,nS,10)); dest.print(F(";"));
#else
- oappend(SET_F("toggle('MQTT');")); // hide MQTT settings
+ dest.print(F("toggle('MQTT');")); // hide MQTT settings
#endif
#ifndef WLED_DISABLE_HUESYNC
- sappend('v',SET_F("H0"),hueIP[0]);
- sappend('v',SET_F("H1"),hueIP[1]);
- sappend('v',SET_F("H2"),hueIP[2]);
- sappend('v',SET_F("H3"),hueIP[3]);
- sappend('v',SET_F("HL"),huePollLightId);
- sappend('v',SET_F("HI"),huePollIntervalMs);
- sappend('c',SET_F("HP"),huePollingEnabled);
- sappend('c',SET_F("HO"),hueApplyOnOff);
- sappend('c',SET_F("HB"),hueApplyBri);
- sappend('c',SET_F("HC"),hueApplyColor);
+ sappend(dest,'v',SET_F("H0"),hueIP[0]);
+ sappend(dest,'v',SET_F("H1"),hueIP[1]);
+ sappend(dest,'v',SET_F("H2"),hueIP[2]);
+ sappend(dest,'v',SET_F("H3"),hueIP[3]);
+ sappend(dest,'v',SET_F("HL"),huePollLightId);
+ sappend(dest,'v',SET_F("HI"),huePollIntervalMs);
+ sappend(dest,'c',SET_F("HP"),huePollingEnabled);
+ sappend(dest,'c',SET_F("HO"),hueApplyOnOff);
+ sappend(dest,'c',SET_F("HB"),hueApplyBri);
+ sappend(dest,'c',SET_F("HC"),hueApplyColor);
char hueErrorString[25];
switch (hueError)
{
@@ -566,61 +559,61 @@ void getSettingsJS(byte subPage, char* dest)
default: sprintf_P(hueErrorString,PSTR("Bridge Error %i"),hueError);
}
- sappends('m',SET_F("(\"sip\")[0]"),hueErrorString);
+ sappends(dest,'m',SET_F("(\"sip\")[0]"),hueErrorString);
#else
- oappend(SET_F("toggle('Hue');")); // hide Hue Sync settings
+ dest.print(F("toggle('Hue');")); // hide Hue Sync settings
#endif
- sappend('v',SET_F("BD"),serialBaud);
+ sappend(dest,'v',SET_F("BD"),serialBaud);
#ifndef WLED_ENABLE_ADALIGHT
- oappend(SET_F("toggle('Serial);"));
+ dest.print(SET_F("toggle('Serial);"));
#endif
}
if (subPage == SUBPAGE_TIME)
{
- sappend('c',SET_F("NT"),ntpEnabled);
- sappends('s',SET_F("NS"),ntpServerName);
- sappend('c',SET_F("CF"),!useAMPM);
- sappend('i',SET_F("TZ"),currentTimezone);
- sappend('v',SET_F("UO"),utcOffsetSecs);
+ sappend(dest,'c',SET_F("NT"),ntpEnabled);
+ sappends(dest,'s',SET_F("NS"),ntpServerName);
+ sappend(dest,'c',SET_F("CF"),!useAMPM);
+ sappend(dest,'i',SET_F("TZ"),currentTimezone);
+ sappend(dest,'v',SET_F("UO"),utcOffsetSecs);
char tm[32];
dtostrf(longitude,4,2,tm);
- sappends('s',SET_F("LN"),tm);
+ sappends(dest,'s',SET_F("LN"),tm);
dtostrf(latitude,4,2,tm);
- sappends('s',SET_F("LT"),tm);
+ sappends(dest,'s',SET_F("LT"),tm);
getTimeString(tm);
- sappends('m',SET_F("(\"times\")[0]"),tm);
+ sappends(dest,'m',SET_F("(\"times\")[0]"),tm);
if ((int)(longitude*10.0f) || (int)(latitude*10.0f)) {
sprintf_P(tm, PSTR("Sunrise: %02d:%02d Sunset: %02d:%02d"), hour(sunrise), minute(sunrise), hour(sunset), minute(sunset));
- sappends('m',SET_F("(\"times\")[1]"),tm);
+ sappends(dest,'m',SET_F("(\"times\")[1]"),tm);
}
- sappend('c',SET_F("OL"),overlayCurrent);
- sappend('v',SET_F("O1"),overlayMin);
- sappend('v',SET_F("O2"),overlayMax);
- sappend('v',SET_F("OM"),analogClock12pixel);
- sappend('c',SET_F("OS"),analogClockSecondsTrail);
- sappend('c',SET_F("O5"),analogClock5MinuteMarks);
- sappend('c',SET_F("OB"),analogClockSolidBlack);
+ sappend(dest,'c',SET_F("OL"),overlayCurrent);
+ sappend(dest,'v',SET_F("O1"),overlayMin);
+ sappend(dest,'v',SET_F("O2"),overlayMax);
+ sappend(dest,'v',SET_F("OM"),analogClock12pixel);
+ sappend(dest,'c',SET_F("OS"),analogClockSecondsTrail);
+ sappend(dest,'c',SET_F("O5"),analogClock5MinuteMarks);
+ sappend(dest,'c',SET_F("OB"),analogClockSolidBlack);
- sappend('c',SET_F("CE"),countdownMode);
- sappend('v',SET_F("CY"),countdownYear);
- sappend('v',SET_F("CI"),countdownMonth);
- sappend('v',SET_F("CD"),countdownDay);
- sappend('v',SET_F("CH"),countdownHour);
- sappend('v',SET_F("CM"),countdownMin);
- sappend('v',SET_F("CS"),countdownSec);
+ sappend(dest,'c',SET_F("CE"),countdownMode);
+ sappend(dest,'v',SET_F("CY"),countdownYear);
+ sappend(dest,'v',SET_F("CI"),countdownMonth);
+ sappend(dest,'v',SET_F("CD"),countdownDay);
+ sappend(dest,'v',SET_F("CH"),countdownHour);
+ sappend(dest,'v',SET_F("CM"),countdownMin);
+ sappend(dest,'v',SET_F("CS"),countdownSec);
- sappend('v',SET_F("A0"),macroAlexaOn);
- sappend('v',SET_F("A1"),macroAlexaOff);
- sappend('v',SET_F("MC"),macroCountdown);
- sappend('v',SET_F("MN"),macroNl);
+ sappend(dest,'v',SET_F("A0"),macroAlexaOn);
+ sappend(dest,'v',SET_F("A1"),macroAlexaOff);
+ sappend(dest,'v',SET_F("MC"),macroCountdown);
+ sappend(dest,'v',SET_F("MN"),macroNl);
for (unsigned i=0; i> 4) & 0x0F);
- k[0] = 'P'; sappend('v',k,timerMonth[i] & 0x0F);
- k[0] = 'D'; sappend('v',k,timerDay[i]);
- k[0] = 'E'; sappend('v',k,timerDayEnd[i]);
+ k[0] = 'M'; sappend(dest,'v',k,(timerMonth[i] >> 4) & 0x0F);
+ k[0] = 'P'; sappend(dest,'v',k,timerMonth[i] & 0x0F);
+ k[0] = 'D'; sappend(dest,'v',k,timerDay[i]);
+ k[0] = 'E'; sappend(dest,'v',k,timerDayEnd[i]);
}
}
}
@@ -647,121 +640,116 @@ void getSettingsJS(byte subPage, char* dest)
char fpass[l+1]; //fill PIN field with 0000
fpass[l] = 0;
memset(fpass,'0',l);
- sappends('s',SET_F("PIN"),fpass);
- sappend('c',SET_F("NO"),otaLock);
- sappend('c',SET_F("OW"),wifiLock);
- sappend('c',SET_F("AO"),aOtaEnabled);
- sappends('m',SET_F("(\"sip\")[0]"),(char*)F("WLED "));
- olen -= 2; //delete ";
- oappend(versionString);
- oappend(SET_F(" (build "));
- oappendi(VERSION);
- oappend(SET_F(")\";"));
- oappend(SET_F("sd=\""));
- oappend(serverDescription);
- oappend(SET_F("\";"));
+ sappends(dest,'s',SET_F("PIN"),fpass);
+ sappend(dest,'c',SET_F("NO"),otaLock);
+ sappend(dest,'c',SET_F("OW"),wifiLock);
+ sappend(dest,'c',SET_F("AO"),aOtaEnabled);
+ char tmp_buf[128];
+ snprintf_P(tmp_buf,sizeof(tmp_buf),PSTR("WLED %s (build %d)"),versionString,VERSION);
+ sappends(dest,'m',SET_F("(\"sip\")[0]"),tmp_buf);
+ dest.print(F("sd=\""));
+ dest.print(serverDescription);
+ dest.print(F("\";"));
}
#ifdef WLED_ENABLE_DMX // include only if DMX is enabled
if (subPage == SUBPAGE_DMX)
{
- sappend('v',SET_F("PU"),e131ProxyUniverse);
+ sappend(dest,'v',SET_F("PU"),e131ProxyUniverse);
- sappend('v',SET_F("CN"),DMXChannels);
- sappend('v',SET_F("CG"),DMXGap);
- sappend('v',SET_F("CS"),DMXStart);
- sappend('v',SET_F("SL"),DMXStartLED);
+ sappend(dest,'v',SET_F("CN"),DMXChannels);
+ sappend(dest,'v',SET_F("CG"),DMXGap);
+ sappend(dest,'v',SET_F("CS"),DMXStart);
+ sappend(dest,'v',SET_F("SL"),DMXStartLED);
- sappend('i',SET_F("CH1"),DMXFixtureMap[0]);
- sappend('i',SET_F("CH2"),DMXFixtureMap[1]);
- sappend('i',SET_F("CH3"),DMXFixtureMap[2]);
- sappend('i',SET_F("CH4"),DMXFixtureMap[3]);
- sappend('i',SET_F("CH5"),DMXFixtureMap[4]);
- sappend('i',SET_F("CH6"),DMXFixtureMap[5]);
- sappend('i',SET_F("CH7"),DMXFixtureMap[6]);
- sappend('i',SET_F("CH8"),DMXFixtureMap[7]);
- sappend('i',SET_F("CH9"),DMXFixtureMap[8]);
- sappend('i',SET_F("CH10"),DMXFixtureMap[9]);
- sappend('i',SET_F("CH11"),DMXFixtureMap[10]);
- sappend('i',SET_F("CH12"),DMXFixtureMap[11]);
- sappend('i',SET_F("CH13"),DMXFixtureMap[12]);
- sappend('i',SET_F("CH14"),DMXFixtureMap[13]);
- sappend('i',SET_F("CH15"),DMXFixtureMap[14]);
+ sappend(dest,'i',SET_F("CH1"),DMXFixtureMap[0]);
+ sappend(dest,'i',SET_F("CH2"),DMXFixtureMap[1]);
+ sappend(dest,'i',SET_F("CH3"),DMXFixtureMap[2]);
+ sappend(dest,'i',SET_F("CH4"),DMXFixtureMap[3]);
+ sappend(dest,'i',SET_F("CH5"),DMXFixtureMap[4]);
+ sappend(dest,'i',SET_F("CH6"),DMXFixtureMap[5]);
+ sappend(dest,'i',SET_F("CH7"),DMXFixtureMap[6]);
+ sappend(dest,'i',SET_F("CH8"),DMXFixtureMap[7]);
+ sappend(dest,'i',SET_F("CH9"),DMXFixtureMap[8]);
+ sappend(dest,'i',SET_F("CH10"),DMXFixtureMap[9]);
+ sappend(dest,'i',SET_F("CH11"),DMXFixtureMap[10]);
+ sappend(dest,'i',SET_F("CH12"),DMXFixtureMap[11]);
+ sappend(dest,'i',SET_F("CH13"),DMXFixtureMap[12]);
+ sappend(dest,'i',SET_F("CH14"),DMXFixtureMap[13]);
+ sappend(dest,'i',SET_F("CH15"),DMXFixtureMap[14]);
}
#endif
if (subPage == SUBPAGE_UM) //usermods
{
- appendGPIOinfo();
- oappend(SET_F("numM="));
- oappendi(usermods.getModCount());
- oappend(";");
- sappend('v',SET_F("SDA"),i2c_sda);
- sappend('v',SET_F("SCL"),i2c_scl);
- sappend('v',SET_F("MOSI"),spi_mosi);
- sappend('v',SET_F("MISO"),spi_miso);
- sappend('v',SET_F("SCLK"),spi_sclk);
- oappend(SET_F("addInfo('SDA','")); oappendi(HW_PIN_SDA); oappend(SET_F("');"));
- oappend(SET_F("addInfo('SCL','")); oappendi(HW_PIN_SCL); oappend(SET_F("');"));
- oappend(SET_F("addInfo('MOSI','")); oappendi(HW_PIN_DATASPI); oappend(SET_F("');"));
- oappend(SET_F("addInfo('MISO','")); oappendi(HW_PIN_MISOSPI); oappend(SET_F("');"));
- oappend(SET_F("addInfo('SCLK','")); oappendi(HW_PIN_CLOCKSPI); oappend(SET_F("');"));
- usermods.appendConfigData();
+ appendGPIOinfo(dest);
+ dest.print(F("numM="));
+ dest.print(usermods.getModCount());
+ dest.print(";");
+ sappend(dest,'v',SET_F("SDA"),i2c_sda);
+ sappend(dest,'v',SET_F("SCL"),i2c_scl);
+ sappend(dest,'v',SET_F("MOSI"),spi_mosi);
+ sappend(dest,'v',SET_F("MISO"),spi_miso);
+ sappend(dest,'v',SET_F("SCLK"),spi_sclk);
+ dest.print(F("addInfo('SDA','")); dest.print(HW_PIN_SDA); dest.print(F("');"));
+ dest.print(F("addInfo('SCL','")); dest.print(HW_PIN_SCL); dest.print(F("');"));
+ dest.print(F("addInfo('MOSI','")); dest.print(HW_PIN_DATASPI); dest.print(F("');"));
+ dest.print(F("addInfo('MISO','")); dest.print(HW_PIN_MISOSPI); dest.print(F("');"));
+ dest.print(F("addInfo('SCLK','")); dest.print(HW_PIN_CLOCKSPI); dest.print(F("');"));
+ usermods.appendConfigData(dest);
}
if (subPage == SUBPAGE_UPDATE) // update
{
- sappends('m',SET_F("(\"sip\")[0]"),(char*)F("WLED "));
- olen -= 2; //delete ";
- oappend(versionString);
- oappend(SET_F("
"));
- oappend(releaseString);
- oappend(SET_F("
("));
+ char tmp_buf[128];
+ snprintf_P(tmp_buf,sizeof(tmp_buf),PSTR("WLED %s
%s
(%s build %d)"),
+ versionString,
+ releaseString,
#if defined(ARDUINO_ARCH_ESP32)
- oappend(ESP.getChipModel());
+ ESP.getChipModel(),
#else
- oappend("esp8266");
+ F("esp8266"),
#endif
- oappend(SET_F(" build "));
- oappendi(VERSION);
- oappend(SET_F(")\";"));
+ VERSION);
+
+ sappends(dest,'m',SET_F("(\"sip\")[0]"),tmp_buf);
}
if (subPage == SUBPAGE_2D) // 2D matrices
{
- sappend('v',SET_F("SOMP"),strip.isMatrix);
+ sappend(dest,'v',SET_F("SOMP"),strip.isMatrix);
#ifndef WLED_DISABLE_2D
- oappend(SET_F("maxPanels=")); oappendi(WLED_MAX_PANELS); oappend(SET_F(";"));
- oappend(SET_F("resetPanels();"));
+ dest.print(F("maxPanels=")); dest.print(WLED_MAX_PANELS); dest.print(F(";"));
+ dest.print(F("resetPanels();"));
if (strip.isMatrix) {
if(strip.panels>0){
- sappend('v',SET_F("PW"),strip.panel[0].width); //Set generator Width and Height to first panel size for convenience
- sappend('v',SET_F("PH"),strip.panel[0].height);
+ sappend(dest,'v',SET_F("PW"),strip.panel[0].width); //Set generator Width and Height to first panel size for convenience
+ sappend(dest,'v',SET_F("PH"),strip.panel[0].height);
}
- sappend('v',SET_F("MPC"),strip.panels);
+ sappend(dest,'v',SET_F("MPC"),strip.panels);
// panels
for (unsigned i=0; i