2020-11-04 11:04:40 +01:00
|
|
|
#include "wled.h"
|
2021-10-11 02:19:33 +02:00
|
|
|
#include "wled_ethernet.h"
|
2020-11-04 11:04:40 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Serializes and parses the cfg.json and wsec.json settings files, stored in internal FS.
|
|
|
|
* The structure of the JSON is not to be considered an official API and may change without notice.
|
|
|
|
*/
|
|
|
|
|
|
|
|
//simple macro for ArduinoJSON's or syntax
|
|
|
|
#define CJSON(a,b) a = b | a
|
|
|
|
|
|
|
|
void getStringFromJson(char* dest, const char* src, size_t len) {
|
|
|
|
if (src != nullptr) strlcpy(dest, src, len);
|
|
|
|
}
|
|
|
|
|
2021-05-11 01:11:16 +02:00
|
|
|
bool deserializeConfig(JsonObject doc, bool fromFS) {
|
2021-12-04 01:05:01 +01:00
|
|
|
bool needsSave = false;
|
2021-03-04 12:10:18 +01:00
|
|
|
//int rev_major = doc["rev"][0]; // 1
|
|
|
|
//int rev_minor = doc["rev"][1]; // 0
|
2020-11-04 11:04:40 +01:00
|
|
|
|
2020-11-07 23:54:56 +01:00
|
|
|
//long vid = doc[F("vid")]; // 2010020
|
2020-11-04 11:04:40 +01:00
|
|
|
|
2021-08-23 14:14:48 +02:00
|
|
|
#ifdef WLED_USE_ETHERNET
|
|
|
|
JsonObject ethernet = doc[F("eth")];
|
|
|
|
CJSON(ethernetType, ethernet["type"]);
|
|
|
|
// NOTE: Ethernet configuration takes priority over other use of pins
|
|
|
|
WLED::instance().initEthernet();
|
|
|
|
#endif
|
|
|
|
|
2021-03-13 22:04:37 +01:00
|
|
|
JsonObject id = doc["id"];
|
2020-11-07 23:54:56 +01:00
|
|
|
getStringFromJson(cmDNS, id[F("mdns")], 33);
|
|
|
|
getStringFromJson(serverDescription, id[F("name")], 33);
|
|
|
|
getStringFromJson(alexaInvocationName, id[F("inv")], 33);
|
2020-11-04 11:04:40 +01:00
|
|
|
|
2021-06-30 12:33:51 +02:00
|
|
|
JsonObject nw_ins_0 = doc["nw"]["ins"][0];
|
2020-11-07 23:54:56 +01:00
|
|
|
getStringFromJson(clientSSID, nw_ins_0[F("ssid")], 33);
|
|
|
|
//int nw_ins_0_pskl = nw_ins_0[F("pskl")];
|
2020-11-04 11:04:40 +01:00
|
|
|
//The WiFi PSK is normally not contained in the regular file for security reasons.
|
|
|
|
//If it is present however, we will use it
|
|
|
|
getStringFromJson(clientPass, nw_ins_0["psk"], 65);
|
|
|
|
|
2021-03-13 22:04:37 +01:00
|
|
|
JsonArray nw_ins_0_ip = nw_ins_0["ip"];
|
|
|
|
JsonArray nw_ins_0_gw = nw_ins_0["gw"];
|
|
|
|
JsonArray nw_ins_0_sn = nw_ins_0["sn"];
|
2020-11-04 11:04:40 +01:00
|
|
|
|
|
|
|
for (byte i = 0; i < 4; i++) {
|
|
|
|
CJSON(staticIP[i], nw_ins_0_ip[i]);
|
|
|
|
CJSON(staticGateway[i], nw_ins_0_gw[i]);
|
|
|
|
CJSON(staticSubnet[i], nw_ins_0_sn[i]);
|
|
|
|
}
|
|
|
|
|
2021-03-13 22:04:37 +01:00
|
|
|
JsonObject ap = doc["ap"];
|
2020-11-07 23:54:56 +01:00
|
|
|
getStringFromJson(apSSID, ap[F("ssid")], 33);
|
2020-11-04 11:04:40 +01:00
|
|
|
getStringFromJson(apPass, ap["psk"] , 65); //normally not present due to security
|
2020-11-07 23:54:56 +01:00
|
|
|
//int ap_pskl = ap[F("pskl")];
|
2020-11-04 11:04:40 +01:00
|
|
|
|
2020-11-07 23:54:56 +01:00
|
|
|
CJSON(apChannel, ap[F("chan")]);
|
2020-11-04 11:04:40 +01:00
|
|
|
if (apChannel > 13 || apChannel < 1) apChannel = 1;
|
|
|
|
|
2020-11-07 23:54:56 +01:00
|
|
|
CJSON(apHide, ap[F("hide")]);
|
2020-11-04 11:04:40 +01:00
|
|
|
if (apHide > 1) apHide = 1;
|
|
|
|
|
2020-11-07 23:54:56 +01:00
|
|
|
CJSON(apBehavior, ap[F("behav")]);
|
2021-01-15 10:37:45 +01:00
|
|
|
|
2020-11-04 11:04:40 +01:00
|
|
|
/*
|
2021-03-13 22:04:37 +01:00
|
|
|
JsonArray ap_ip = ap["ip"];
|
2020-11-04 11:04:40 +01:00
|
|
|
for (byte i = 0; i < 4; i++) {
|
|
|
|
apIP[i] = ap_ip;
|
2021-05-20 19:54:07 +02:00
|
|
|
}
|
|
|
|
*/
|
2020-11-04 11:04:40 +01:00
|
|
|
|
2020-11-07 23:54:56 +01:00
|
|
|
noWifiSleep = doc[F("wifi")][F("sleep")] | !noWifiSleep; // inverted
|
2020-11-04 11:04:40 +01:00
|
|
|
noWifiSleep = !noWifiSleep;
|
2020-11-07 23:54:56 +01:00
|
|
|
//int wifi_phy = doc[F("wifi")][F("phy")]; //force phy mode n?
|
2020-11-04 11:04:40 +01:00
|
|
|
|
2020-11-07 23:54:56 +01:00
|
|
|
JsonObject hw = doc[F("hw")];
|
2020-11-04 11:04:40 +01:00
|
|
|
|
2021-08-23 14:14:48 +02:00
|
|
|
// initialize LED pins and lengths prior to other HW (except for ethernet)
|
2022-02-04 10:10:37 +01:00
|
|
|
JsonObject hw_led = hw["led"];
|
2020-11-04 11:04:40 +01:00
|
|
|
|
2020-11-07 23:54:56 +01:00
|
|
|
CJSON(strip.ablMilliampsMax, hw_led[F("maxpwr")]);
|
|
|
|
CJSON(strip.milliampsPerLed, hw_led[F("ledma")]);
|
2022-03-08 02:16:33 +01:00
|
|
|
CJSON(strip.autoWhiteMode, hw_led[F("rgbwm")]);
|
|
|
|
Bus::setAutoWhiteMode(strip.autoWhiteMode);
|
2022-03-05 01:05:26 +01:00
|
|
|
strip.fixInvalidSegments(); // refreshes segment light capabilities (in case auto white mode changed)
|
2021-11-24 11:02:25 +01:00
|
|
|
CJSON(correctWB, hw_led["cct"]);
|
2021-11-26 20:18:38 +01:00
|
|
|
CJSON(cctFromRgb, hw_led[F("cr")]);
|
2022-03-08 02:16:33 +01:00
|
|
|
CJSON(strip.cctBlending, hw_led[F("cb")]);
|
|
|
|
Bus::setCCTBlend(strip.cctBlending);
|
|
|
|
strip.setTargetFps(hw_led["fps"]); //NOP if 0, default 42 FPS
|
2020-11-04 11:04:40 +01:00
|
|
|
|
2021-01-31 00:38:27 +01:00
|
|
|
JsonArray ins = hw_led["ins"];
|
2021-10-31 11:57:41 +01:00
|
|
|
|
2021-05-11 01:11:16 +02:00
|
|
|
if (fromFS || !ins.isNull()) {
|
2021-10-11 02:19:33 +02:00
|
|
|
uint8_t s = 0; // bus iterator
|
2022-03-05 01:05:26 +01:00
|
|
|
if (fromFS) busses.removeAll(); // can't safely manipulate busses directly in network callback
|
2021-05-11 01:11:16 +02:00
|
|
|
uint32_t mem = 0;
|
|
|
|
for (JsonObject elm : ins) {
|
|
|
|
if (s >= WLED_MAX_BUSSES) break;
|
|
|
|
uint8_t pins[5] = {255, 255, 255, 255, 255};
|
2021-05-20 19:54:07 +02:00
|
|
|
JsonArray pinArr = elm["pin"];
|
2021-05-11 01:11:16 +02:00
|
|
|
if (pinArr.size() == 0) continue;
|
|
|
|
pins[0] = pinArr[0];
|
|
|
|
uint8_t i = 0;
|
|
|
|
for (int p : pinArr) {
|
2021-05-20 19:54:07 +02:00
|
|
|
pins[i++] = p;
|
2021-05-11 01:11:16 +02:00
|
|
|
if (i>4) break;
|
|
|
|
}
|
|
|
|
|
2022-02-04 10:10:37 +01:00
|
|
|
uint16_t length = elm["len"] | 1;
|
2021-05-11 01:11:16 +02:00
|
|
|
uint8_t colorOrder = (int)elm[F("order")];
|
2021-05-17 16:23:46 +02:00
|
|
|
uint8_t skipFirst = elm[F("skip")];
|
2021-09-12 01:15:51 +02:00
|
|
|
uint16_t start = elm["start"] | 0;
|
2021-10-11 02:19:33 +02:00
|
|
|
if (length==0 || start + length > MAX_LEDS) continue; // zero length or we reached max. number of LEDs, just stop
|
2021-05-11 01:11:16 +02:00
|
|
|
uint8_t ledType = elm["type"] | TYPE_WS2812_RGB;
|
|
|
|
bool reversed = elm["rev"];
|
2021-10-11 02:19:33 +02:00
|
|
|
bool refresh = elm["ref"] | false;
|
2022-03-05 01:05:26 +01:00
|
|
|
ledType |= refresh << 7; // hack bit 7 to indicate strip requires off refresh
|
|
|
|
if (fromFS) {
|
|
|
|
BusConfig bc = BusConfig(ledType, pins, start, length, colorOrder, reversed, skipFirst);
|
|
|
|
mem += BusManager::memUsage(bc);
|
|
|
|
if (mem <= MAX_LED_MEMORY && busses.getNumBusses() <= WLED_MAX_BUSSES) busses.add(bc); // finalization will be done in WLED::beginStrip()
|
|
|
|
} else {
|
|
|
|
if (busConfigs[s] != nullptr) delete busConfigs[s];
|
|
|
|
busConfigs[s] = new BusConfig(ledType, pins, start, length, colorOrder, reversed, skipFirst);
|
|
|
|
doInitBusses = true;
|
|
|
|
}
|
2022-03-19 14:21:14 +01:00
|
|
|
s++;
|
2021-01-31 00:38:27 +01:00
|
|
|
}
|
2021-10-11 02:19:33 +02:00
|
|
|
// finalization done in beginStrip()
|
2021-01-31 00:38:27 +01:00
|
|
|
}
|
2021-03-20 18:43:05 +01:00
|
|
|
if (hw_led["rev"]) busses.getBus(0)->reversed = true; //set 0.11 global reversed setting for first bus
|
2020-11-04 11:04:40 +01:00
|
|
|
|
2022-01-26 00:42:04 +01:00
|
|
|
// read color order map configuration
|
|
|
|
JsonArray hw_com = hw[F("com")];
|
|
|
|
if (!hw_com.isNull()) {
|
|
|
|
ColorOrderMap com = {};
|
|
|
|
uint8_t s = 0;
|
|
|
|
for (JsonObject entry : hw_com) {
|
|
|
|
if (s > WLED_MAX_COLOR_ORDER_MAPPINGS) break;
|
2022-02-04 10:10:37 +01:00
|
|
|
uint16_t start = entry["start"] | 0;
|
|
|
|
uint16_t len = entry["len"] | 0;
|
2022-01-26 00:42:04 +01:00
|
|
|
uint8_t colorOrder = (int)entry[F("order")];
|
|
|
|
com.add(start, len, colorOrder);
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
busses.updateColorOrderMap(com);
|
|
|
|
}
|
|
|
|
|
2021-05-20 19:54:07 +02:00
|
|
|
// read multiple button configuration
|
2021-07-01 20:51:52 +02:00
|
|
|
JsonObject btn_obj = hw["btn"];
|
|
|
|
JsonArray hw_btn_ins = btn_obj[F("ins")];
|
2021-05-20 19:54:07 +02:00
|
|
|
if (!hw_btn_ins.isNull()) {
|
|
|
|
uint8_t s = 0;
|
|
|
|
for (JsonObject btn : hw_btn_ins) {
|
|
|
|
CJSON(buttonType[s], btn["type"]);
|
2021-06-30 12:33:51 +02:00
|
|
|
int8_t pin = btn["pin"][0] | -1;
|
2021-08-23 14:14:48 +02:00
|
|
|
if (pin > -1 && pinManager.allocatePin(pin, false, PinOwner::Button)) {
|
2021-06-30 12:33:51 +02:00
|
|
|
btnPin[s] = pin;
|
|
|
|
pinMode(btnPin[s], INPUT_PULLUP);
|
|
|
|
} else {
|
|
|
|
btnPin[s] = -1;
|
2021-05-20 19:54:07 +02:00
|
|
|
}
|
2021-07-01 20:51:52 +02:00
|
|
|
JsonArray hw_btn_ins_0_macros = btn["macros"];
|
2021-05-20 19:54:07 +02:00
|
|
|
CJSON(macroButton[s], hw_btn_ins_0_macros[0]);
|
|
|
|
CJSON(macroLongPress[s],hw_btn_ins_0_macros[1]);
|
|
|
|
CJSON(macroDoublePress[s], hw_btn_ins_0_macros[2]);
|
|
|
|
if (++s >= WLED_MAX_BUTTONS) break; // max buttons reached
|
|
|
|
}
|
|
|
|
// clear remaining buttons
|
|
|
|
for (; s<WLED_MAX_BUTTONS; s++) {
|
|
|
|
btnPin[s] = -1;
|
|
|
|
buttonType[s] = BTN_TYPE_NONE;
|
|
|
|
macroButton[s] = 0;
|
|
|
|
macroLongPress[s] = 0;
|
|
|
|
macroDoublePress[s] = 0;
|
2021-05-11 01:11:16 +02:00
|
|
|
}
|
2021-05-20 19:54:07 +02:00
|
|
|
} else {
|
|
|
|
// new install/missing configuration (button 0 has defaults)
|
2021-07-09 20:06:48 +02:00
|
|
|
if (fromFS) {
|
|
|
|
// relies upon only being called once with fromFS == true, which is currently true.
|
|
|
|
uint8_t s = 0;
|
2021-08-23 14:14:48 +02:00
|
|
|
if (pinManager.allocatePin(btnPin[0], false, PinOwner::Button)) { // initialized to #define value BTNPIN, or zero if not defined(!)
|
2021-07-09 20:06:48 +02:00
|
|
|
++s; // do not clear default button if allocated successfully
|
|
|
|
}
|
|
|
|
for (; s<WLED_MAX_BUTTONS; s++) {
|
2021-05-20 19:54:07 +02:00
|
|
|
btnPin[s] = -1;
|
|
|
|
buttonType[s] = BTN_TYPE_NONE;
|
|
|
|
macroButton[s] = 0;
|
|
|
|
macroLongPress[s] = 0;
|
|
|
|
macroDoublePress[s] = 0;
|
|
|
|
}
|
2021-07-09 20:06:48 +02:00
|
|
|
}
|
2021-01-17 00:20:31 +01:00
|
|
|
}
|
2021-07-01 20:51:52 +02:00
|
|
|
CJSON(touchThreshold,btn_obj[F("tt")]);
|
|
|
|
CJSON(buttonPublishMqtt,btn_obj["mqtt"]);
|
2020-11-04 11:04:40 +01:00
|
|
|
|
2021-05-11 01:11:16 +02:00
|
|
|
int hw_ir_pin = hw["ir"]["pin"] | -2; // 4
|
|
|
|
if (hw_ir_pin > -2) {
|
2021-08-23 14:14:48 +02:00
|
|
|
if (pinManager.allocatePin(hw_ir_pin, false, PinOwner::IR)) {
|
2021-05-11 01:11:16 +02:00
|
|
|
irPin = hw_ir_pin;
|
|
|
|
} else {
|
|
|
|
irPin = -1;
|
|
|
|
}
|
2021-01-17 00:20:31 +01:00
|
|
|
}
|
2021-03-13 22:04:37 +01:00
|
|
|
CJSON(irEnabled, hw["ir"]["type"]);
|
2022-02-26 01:37:09 +01:00
|
|
|
CJSON(irApplyToAllSelected, hw["ir"]["sel"]);
|
2021-01-17 00:20:31 +01:00
|
|
|
|
2021-03-04 12:10:18 +01:00
|
|
|
JsonObject relay = hw[F("relay")];
|
2021-05-11 01:11:16 +02:00
|
|
|
int hw_relay_pin = relay["pin"] | -2;
|
|
|
|
if (hw_relay_pin > -2) {
|
2021-08-23 14:14:48 +02:00
|
|
|
if (pinManager.allocatePin(hw_relay_pin,true, PinOwner::Relay)) {
|
2021-05-11 01:11:16 +02:00
|
|
|
rlyPin = hw_relay_pin;
|
|
|
|
pinMode(rlyPin, OUTPUT);
|
|
|
|
} else {
|
|
|
|
rlyPin = -1;
|
|
|
|
}
|
2021-01-17 00:20:31 +01:00
|
|
|
}
|
2021-03-04 12:10:18 +01:00
|
|
|
if (relay.containsKey("rev")) {
|
|
|
|
rlyMde = !relay["rev"];
|
|
|
|
}
|
2020-11-04 11:04:40 +01:00
|
|
|
|
2022-02-01 20:02:46 +01:00
|
|
|
CJSON(serialBaud, hw[F("baud")]);
|
|
|
|
if (serialBaud < 96 || serialBaud > 15000) serialBaud = 1152;
|
|
|
|
updateBaudRate(serialBaud *100);
|
|
|
|
|
2021-05-20 19:54:07 +02:00
|
|
|
//int hw_status_pin = hw[F("status")]["pin"]; // -1
|
2020-11-04 11:04:40 +01:00
|
|
|
|
2020-11-07 23:54:56 +01:00
|
|
|
JsonObject light = doc[F("light")];
|
|
|
|
CJSON(briMultiplier, light[F("scale-bri")]);
|
|
|
|
CJSON(strip.paletteBlend, light[F("pal-mode")]);
|
2021-09-11 01:17:42 +02:00
|
|
|
CJSON(autoSegments, light[F("aseg")]);
|
2020-11-04 11:04:40 +01:00
|
|
|
|
2021-07-01 20:51:52 +02:00
|
|
|
float light_gc_bri = light["gc"]["bri"];
|
|
|
|
float light_gc_col = light["gc"]["col"]; // 2.8
|
2020-11-04 11:04:40 +01:00
|
|
|
if (light_gc_bri > 1.5) strip.gammaCorrectBri = true;
|
|
|
|
else if (light_gc_bri > 0.5) strip.gammaCorrectBri = false;
|
|
|
|
if (light_gc_col > 1.5) strip.gammaCorrectCol = true;
|
|
|
|
else if (light_gc_col > 0.5) strip.gammaCorrectCol = false;
|
|
|
|
|
2022-02-04 10:10:37 +01:00
|
|
|
JsonObject light_tr = light["tr"];
|
|
|
|
CJSON(fadeTransition, light_tr["mode"]);
|
2021-05-20 19:54:07 +02:00
|
|
|
int tdd = light_tr["dur"] | -1;
|
2020-11-04 11:04:40 +01:00
|
|
|
if (tdd >= 0) transitionDelayDefault = tdd * 100;
|
2021-05-11 01:11:16 +02:00
|
|
|
CJSON(strip.paletteFade, light_tr["pal"]);
|
2020-11-04 11:04:40 +01:00
|
|
|
|
|
|
|
JsonObject light_nl = light["nl"];
|
2022-02-04 10:10:37 +01:00
|
|
|
CJSON(nightlightMode, light_nl["mode"]);
|
2021-05-11 01:11:16 +02:00
|
|
|
byte prev = nightlightDelayMinsDefault;
|
2022-02-04 10:10:37 +01:00
|
|
|
CJSON(nightlightDelayMinsDefault, light_nl["dur"]);
|
2021-05-11 01:11:16 +02:00
|
|
|
if (nightlightDelayMinsDefault != prev) nightlightDelayMins = nightlightDelayMinsDefault;
|
2020-11-04 11:04:40 +01:00
|
|
|
|
2020-11-07 23:54:56 +01:00
|
|
|
CJSON(nightlightTargetBri, light_nl[F("tbri")]);
|
2021-07-01 20:51:52 +02:00
|
|
|
CJSON(macroNl, light_nl["macro"]);
|
2020-11-04 11:04:40 +01:00
|
|
|
|
2022-02-04 10:10:37 +01:00
|
|
|
JsonObject def = doc["def"];
|
2021-11-23 13:17:33 +01:00
|
|
|
CJSON(bootPreset, def["ps"]);
|
2020-11-04 11:04:40 +01:00
|
|
|
CJSON(turnOnAtBoot, def["on"]); // true
|
|
|
|
CJSON(briS, def["bri"]); // 128
|
|
|
|
|
|
|
|
JsonObject interfaces = doc["if"];
|
|
|
|
|
2022-02-04 10:10:37 +01:00
|
|
|
JsonObject if_sync = interfaces["sync"];
|
2020-11-07 23:54:56 +01:00
|
|
|
CJSON(udpPort, if_sync[F("port0")]); // 21324
|
|
|
|
CJSON(udpPort2, if_sync[F("port1")]); // 65506
|
2020-11-04 11:04:40 +01:00
|
|
|
|
2021-03-13 22:04:37 +01:00
|
|
|
JsonObject if_sync_recv = if_sync["recv"];
|
2020-11-04 11:04:40 +01:00
|
|
|
CJSON(receiveNotificationBrightness, if_sync_recv["bri"]);
|
2021-03-13 22:04:37 +01:00
|
|
|
CJSON(receiveNotificationColor, if_sync_recv["col"]);
|
2021-07-10 16:14:17 +02:00
|
|
|
CJSON(receiveNotificationEffects, if_sync_recv["fx"]);
|
2021-08-25 16:39:12 +02:00
|
|
|
CJSON(receiveGroups, if_sync_recv["grp"]);
|
2021-12-17 20:33:48 +01:00
|
|
|
CJSON(receiveSegmentOptions, if_sync_recv["seg"]);
|
2022-02-16 14:55:35 +01:00
|
|
|
CJSON(receiveSegmentBounds, if_sync_recv["sb"]);
|
2021-05-11 01:11:16 +02:00
|
|
|
//! following line might be a problem if called after boot
|
2021-12-17 20:33:48 +01:00
|
|
|
receiveNotifications = (receiveNotificationBrightness || receiveNotificationColor || receiveNotificationEffects || receiveSegmentOptions);
|
2020-11-04 11:04:40 +01:00
|
|
|
|
2021-03-13 22:04:37 +01:00
|
|
|
JsonObject if_sync_send = if_sync["send"];
|
2021-05-11 01:11:16 +02:00
|
|
|
prev = notifyDirectDefault;
|
2020-11-07 23:54:56 +01:00
|
|
|
CJSON(notifyDirectDefault, if_sync_send[F("dir")]);
|
2021-05-11 01:11:16 +02:00
|
|
|
if (notifyDirectDefault != prev) notifyDirect = notifyDirectDefault;
|
2021-07-01 20:51:52 +02:00
|
|
|
CJSON(notifyButton, if_sync_send["btn"]);
|
|
|
|
CJSON(notifyAlexa, if_sync_send["va"]);
|
|
|
|
CJSON(notifyHue, if_sync_send["hue"]);
|
|
|
|
CJSON(notifyMacro, if_sync_send["macro"]);
|
2020-11-07 23:54:56 +01:00
|
|
|
CJSON(notifyTwice, if_sync_send[F("twice")]);
|
2021-08-25 16:39:12 +02:00
|
|
|
CJSON(syncGroups, if_sync_send["grp"]);
|
2020-11-07 23:54:56 +01:00
|
|
|
|
2021-03-13 22:04:37 +01:00
|
|
|
JsonObject if_nodes = interfaces["nodes"];
|
|
|
|
CJSON(nodeListEnabled, if_nodes[F("list")]);
|
|
|
|
CJSON(nodeBroadcastEnabled, if_nodes[F("bcast")]);
|
|
|
|
|
|
|
|
JsonObject if_live = interfaces["live"];
|
|
|
|
CJSON(receiveDirect, if_live["en"]);
|
|
|
|
CJSON(e131Port, if_live["port"]); // 5568
|
2021-10-04 19:41:20 +02:00
|
|
|
if (e131Port == DDP_DEFAULT_PORT) e131Port = E131_DEFAULT_PORT; // prevent double DDP port allocation
|
2020-11-07 23:54:56 +01:00
|
|
|
CJSON(e131Multicast, if_live[F("mc")]);
|
|
|
|
|
|
|
|
JsonObject if_live_dmx = if_live[F("dmx")];
|
|
|
|
CJSON(e131Universe, if_live_dmx[F("uni")]);
|
|
|
|
CJSON(e131SkipOutOfSequence, if_live_dmx[F("seqskip")]);
|
|
|
|
CJSON(DMXAddress, if_live_dmx[F("addr")]);
|
2022-02-04 10:10:37 +01:00
|
|
|
CJSON(DMXMode, if_live_dmx["mode"]);
|
2020-11-07 23:54:56 +01:00
|
|
|
|
|
|
|
tdd = if_live[F("timeout")] | -1;
|
2020-11-04 11:04:40 +01:00
|
|
|
if (tdd >= 0) realtimeTimeoutMs = tdd * 100;
|
2020-11-07 23:54:56 +01:00
|
|
|
CJSON(arlsForceMaxBri, if_live[F("maxbri")]);
|
|
|
|
CJSON(arlsDisableGammaCorrection, if_live[F("no-gc")]); // false
|
|
|
|
CJSON(arlsOffset, if_live[F("offset")]); // 0
|
2020-11-04 11:04:40 +01:00
|
|
|
|
2021-07-01 20:51:52 +02:00
|
|
|
CJSON(alexaEnabled, interfaces["va"][F("alexa")]); // false
|
2020-11-04 11:04:40 +01:00
|
|
|
|
2021-07-01 20:51:52 +02:00
|
|
|
CJSON(macroAlexaOn, interfaces["va"]["macros"][0]);
|
|
|
|
CJSON(macroAlexaOff, interfaces["va"]["macros"][1]);
|
2020-11-04 11:04:40 +01:00
|
|
|
|
2021-05-20 19:54:07 +02:00
|
|
|
#ifndef WLED_DISABLE_BLYNK
|
2021-03-13 22:04:37 +01:00
|
|
|
const char* apikey = interfaces["blynk"][F("token")] | "Hidden";
|
2020-11-04 11:04:40 +01:00
|
|
|
tdd = strnlen(apikey, 36);
|
|
|
|
if (tdd > 20 || tdd == 0)
|
|
|
|
getStringFromJson(blynkApiKey, apikey, 36); //normally not present due to security
|
|
|
|
|
2021-03-13 22:04:37 +01:00
|
|
|
JsonObject if_blynk = interfaces["blynk"];
|
2020-12-22 00:44:16 +01:00
|
|
|
getStringFromJson(blynkHost, if_blynk[F("host")], 33);
|
2021-03-13 22:04:37 +01:00
|
|
|
CJSON(blynkPort, if_blynk["port"]);
|
2021-05-20 19:54:07 +02:00
|
|
|
#endif
|
2020-12-22 00:44:16 +01:00
|
|
|
|
2021-05-20 19:54:07 +02:00
|
|
|
#ifdef WLED_ENABLE_MQTT
|
2021-03-13 22:04:37 +01:00
|
|
|
JsonObject if_mqtt = interfaces["mqtt"];
|
|
|
|
CJSON(mqttEnabled, if_mqtt["en"]);
|
2020-11-07 23:54:56 +01:00
|
|
|
getStringFromJson(mqttServer, if_mqtt[F("broker")], 33);
|
2021-03-13 22:04:37 +01:00
|
|
|
CJSON(mqttPort, if_mqtt["port"]); // 1883
|
2020-11-07 23:54:56 +01:00
|
|
|
getStringFromJson(mqttUser, if_mqtt[F("user")], 41);
|
2021-06-30 01:23:35 +02:00
|
|
|
getStringFromJson(mqttPass, if_mqtt["psk"], 65); //normally not present due to security
|
2020-11-07 23:54:56 +01:00
|
|
|
getStringFromJson(mqttClientID, if_mqtt[F("cid")], 41);
|
2020-11-04 11:04:40 +01:00
|
|
|
|
2020-11-07 23:54:56 +01:00
|
|
|
getStringFromJson(mqttDeviceTopic, if_mqtt[F("topics")][F("device")], 33); // "wled/test"
|
2020-12-10 01:28:42 +01:00
|
|
|
getStringFromJson(mqttGroupTopic, if_mqtt[F("topics")][F("group")], 33); // ""
|
2021-05-20 19:54:07 +02:00
|
|
|
#endif
|
2020-11-04 11:04:40 +01:00
|
|
|
|
2021-05-20 19:54:07 +02:00
|
|
|
#ifndef WLED_DISABLE_HUESYNC
|
2021-07-01 20:51:52 +02:00
|
|
|
JsonObject if_hue = interfaces["hue"];
|
2021-03-13 22:04:37 +01:00
|
|
|
CJSON(huePollingEnabled, if_hue["en"]);
|
|
|
|
CJSON(huePollLightId, if_hue["id"]);
|
2020-11-07 23:54:56 +01:00
|
|
|
tdd = if_hue[F("iv")] | -1;
|
2020-11-04 11:04:40 +01:00
|
|
|
if (tdd >= 2) huePollIntervalMs = tdd * 100;
|
|
|
|
|
2021-03-13 22:04:37 +01:00
|
|
|
JsonObject if_hue_recv = if_hue["recv"];
|
2020-11-04 11:04:40 +01:00
|
|
|
CJSON(hueApplyOnOff, if_hue_recv["on"]);
|
|
|
|
CJSON(hueApplyBri, if_hue_recv["bri"]);
|
2021-03-13 22:04:37 +01:00
|
|
|
CJSON(hueApplyColor, if_hue_recv["col"]);
|
2020-11-04 11:04:40 +01:00
|
|
|
|
2021-03-13 22:04:37 +01:00
|
|
|
JsonArray if_hue_ip = if_hue["ip"];
|
2020-11-04 11:04:40 +01:00
|
|
|
|
|
|
|
for (byte i = 0; i < 4; i++)
|
|
|
|
CJSON(hueIP[i], if_hue_ip[i]);
|
2021-05-20 19:54:07 +02:00
|
|
|
#endif
|
2020-11-04 11:04:40 +01:00
|
|
|
|
2020-11-07 23:54:56 +01:00
|
|
|
JsonObject if_ntp = interfaces[F("ntp")];
|
2021-03-13 22:04:37 +01:00
|
|
|
CJSON(ntpEnabled, if_ntp["en"]);
|
2020-11-07 23:54:56 +01:00
|
|
|
getStringFromJson(ntpServerName, if_ntp[F("host")], 33); // "1.wled.pool.ntp.org"
|
|
|
|
CJSON(currentTimezone, if_ntp[F("tz")]);
|
|
|
|
CJSON(utcOffsetSecs, if_ntp[F("offset")]);
|
|
|
|
CJSON(useAMPM, if_ntp[F("ampm")]);
|
2021-04-12 21:53:22 +02:00
|
|
|
CJSON(longitude, if_ntp[F("ln")]);
|
|
|
|
CJSON(latitude, if_ntp[F("lt")]);
|
2020-11-04 11:04:40 +01:00
|
|
|
|
2020-11-07 23:54:56 +01:00
|
|
|
JsonObject ol = doc[F("ol")];
|
2022-03-07 00:11:43 +01:00
|
|
|
CJSON(overlayCurrent ,ol[F("clock")]); // 0
|
2020-11-07 23:54:56 +01:00
|
|
|
CJSON(countdownMode, ol[F("cntdwn")]);
|
2020-11-04 11:04:40 +01:00
|
|
|
|
2021-05-20 19:54:07 +02:00
|
|
|
CJSON(overlayMin, ol["min"]);
|
2020-12-10 01:28:42 +01:00
|
|
|
CJSON(overlayMax, ol[F("max")]);
|
|
|
|
CJSON(analogClock12pixel, ol[F("o12pix")]);
|
|
|
|
CJSON(analogClock5MinuteMarks, ol[F("o5m")]);
|
|
|
|
CJSON(analogClockSecondsTrail, ol[F("osec")]);
|
2020-11-04 11:04:40 +01:00
|
|
|
|
|
|
|
//timed macro rules
|
2020-11-07 23:54:56 +01:00
|
|
|
JsonObject tm = doc[F("timers")];
|
|
|
|
JsonObject cntdwn = tm[F("cntdwn")];
|
|
|
|
JsonArray cntdwn_goal = cntdwn[F("goal")];
|
2020-11-04 11:04:40 +01:00
|
|
|
CJSON(countdownYear, cntdwn_goal[0]);
|
|
|
|
CJSON(countdownMonth, cntdwn_goal[1]);
|
|
|
|
CJSON(countdownDay, cntdwn_goal[2]);
|
|
|
|
CJSON(countdownHour, cntdwn_goal[3]);
|
|
|
|
CJSON(countdownMin, cntdwn_goal[4]);
|
|
|
|
CJSON(countdownSec, cntdwn_goal[5]);
|
2021-07-01 20:51:52 +02:00
|
|
|
CJSON(macroCountdown, cntdwn["macro"]);
|
2020-12-31 20:47:38 +01:00
|
|
|
setCountdown();
|
2020-11-04 11:04:40 +01:00
|
|
|
|
2021-07-01 20:51:52 +02:00
|
|
|
JsonArray timers = tm["ins"];
|
2020-11-04 11:04:40 +01:00
|
|
|
uint8_t it = 0;
|
|
|
|
for (JsonObject timer : timers) {
|
2021-04-12 21:53:22 +02:00
|
|
|
if (it > 9) break;
|
|
|
|
if (it<8 && timer[F("hour")]==255) it=8; // hour==255 -> sunrise/sunset
|
2020-11-07 23:54:56 +01:00
|
|
|
CJSON(timerHours[it], timer[F("hour")]);
|
2021-05-20 19:54:07 +02:00
|
|
|
CJSON(timerMinutes[it], timer["min"]);
|
2021-07-01 20:51:52 +02:00
|
|
|
CJSON(timerMacro[it], timer["macro"]);
|
2020-11-04 11:04:40 +01:00
|
|
|
|
2021-12-31 14:09:48 +01:00
|
|
|
byte dowPrev = timerWeekday[it];
|
2020-12-16 00:10:48 +01:00
|
|
|
//note: act is currently only 0 or 1.
|
|
|
|
//the reason we are not using bool is that the on-disk type in 0.11.0 was already int
|
|
|
|
int actPrev = timerWeekday[it] & 0x01;
|
2020-11-07 23:54:56 +01:00
|
|
|
CJSON(timerWeekday[it], timer[F("dow")]);
|
2020-11-04 11:04:40 +01:00
|
|
|
if (timerWeekday[it] != dowPrev) { //present in JSON
|
|
|
|
timerWeekday[it] <<= 1; //add active bit
|
2021-03-13 22:04:37 +01:00
|
|
|
int act = timer["en"] | actPrev;
|
2020-11-04 11:04:40 +01:00
|
|
|
if (act) timerWeekday[it]++;
|
|
|
|
}
|
2021-12-31 14:09:48 +01:00
|
|
|
if (it<8) {
|
2022-02-26 01:37:09 +01:00
|
|
|
JsonObject start = timer["start"];
|
|
|
|
byte startm = start["mon"];
|
|
|
|
if (startm) timerMonth[it] = (startm << 4);
|
2021-12-31 14:09:48 +01:00
|
|
|
CJSON(timerDay[it], start["day"]);
|
2022-02-26 01:37:09 +01:00
|
|
|
JsonObject end = timer["end"];
|
|
|
|
CJSON(timerDayEnd[it], end["day"]);
|
|
|
|
byte endm = end["mon"];
|
|
|
|
if (startm) timerMonth[it] += endm & 0x0F;
|
|
|
|
if (!(timerMonth[it] & 0x0F)) timerMonth[it] += 12; //default end month to 12
|
2021-12-31 14:09:48 +01:00
|
|
|
}
|
2020-11-04 11:04:40 +01:00
|
|
|
it++;
|
|
|
|
}
|
|
|
|
|
|
|
|
JsonObject ota = doc["ota"];
|
|
|
|
const char* pwd = ota["psk"]; //normally not present due to security
|
|
|
|
|
|
|
|
bool pwdCorrect = !otaLock; //always allow access if ota not locked
|
|
|
|
if (pwd != nullptr && strncmp(otaPass, pwd, 33) == 0) pwdCorrect = true;
|
|
|
|
|
|
|
|
if (pwdCorrect) { //only accept these values from cfg.json if ota is unlocked (else from wsec.json)
|
2020-11-07 23:54:56 +01:00
|
|
|
CJSON(otaLock, ota[F("lock")]);
|
|
|
|
CJSON(wifiLock, ota[F("lock-wifi")]);
|
|
|
|
CJSON(aOtaEnabled, ota[F("aota")]);
|
2020-11-04 11:04:40 +01:00
|
|
|
getStringFromJson(otaPass, pwd, 33); //normally not present due to security
|
|
|
|
}
|
2020-11-04 17:17:54 +01:00
|
|
|
|
2020-11-09 11:09:47 +01:00
|
|
|
#ifdef WLED_ENABLE_DMX
|
|
|
|
JsonObject dmx = doc["dmx"];
|
|
|
|
CJSON(DMXChannels, dmx[F("chan")]);
|
|
|
|
CJSON(DMXGap,dmx[F("gap")]);
|
2021-09-12 01:15:51 +02:00
|
|
|
CJSON(DMXStart, dmx["start"]);
|
2020-11-09 11:09:47 +01:00
|
|
|
CJSON(DMXStartLED,dmx[F("start-led")]);
|
|
|
|
|
2020-12-21 21:04:21 +01:00
|
|
|
JsonArray dmx_fixmap = dmx[F("fixmap")];
|
2021-11-10 00:29:04 +01:00
|
|
|
for (int i = 0; i < dmx_fixmap.size(); i++) {
|
|
|
|
if (i > 14) break;
|
2020-12-21 21:04:21 +01:00
|
|
|
CJSON(DMXFixtureMap[i],dmx_fixmap[i]);
|
2020-11-09 11:09:47 +01:00
|
|
|
}
|
2021-11-30 23:10:23 +01:00
|
|
|
|
|
|
|
CJSON(e131ProxyUniverse, dmx[F("e131proxy")]);
|
2020-11-09 11:09:47 +01:00
|
|
|
#endif
|
2020-11-11 15:50:15 +01:00
|
|
|
|
2021-05-20 19:54:07 +02:00
|
|
|
DEBUG_PRINTLN(F("Starting usermod config."));
|
2020-11-11 15:50:15 +01:00
|
|
|
JsonObject usermods_settings = doc["um"];
|
2021-06-25 01:26:15 +02:00
|
|
|
if (!usermods_settings.isNull()) {
|
2021-12-04 01:05:01 +01:00
|
|
|
needsSave = !usermods.readFromConfig(usermods_settings);
|
2021-06-25 01:26:15 +02:00
|
|
|
}
|
2021-05-11 01:11:16 +02:00
|
|
|
|
2021-12-04 01:05:01 +01:00
|
|
|
if (fromFS) return needsSave;
|
2022-03-19 14:21:14 +01:00
|
|
|
// if from /json/cfg
|
2021-05-11 01:11:16 +02:00
|
|
|
doReboot = doc[F("rb")] | doReboot;
|
2022-03-19 14:21:14 +01:00
|
|
|
if (doInitBusses) return false; // no save needed, will do after bus init in wled.cpp loop
|
2021-05-11 01:11:16 +02:00
|
|
|
return (doc["sv"] | true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void deserializeConfigFromFS() {
|
|
|
|
bool success = deserializeConfigSec();
|
|
|
|
if (!success) { //if file does not exist, try reading from EEPROM
|
|
|
|
deEEPSettings();
|
2021-06-25 01:26:15 +02:00
|
|
|
return;
|
2021-05-11 01:11:16 +02:00
|
|
|
}
|
|
|
|
|
2021-12-04 01:05:01 +01:00
|
|
|
#ifdef WLED_USE_DYNAMIC_JSON
|
2021-05-11 01:11:16 +02:00
|
|
|
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
2021-12-04 01:05:01 +01:00
|
|
|
#else
|
|
|
|
if (!requestJSONBufferLock(1)) return;
|
|
|
|
#endif
|
2021-05-11 01:11:16 +02:00
|
|
|
|
|
|
|
DEBUG_PRINTLN(F("Reading settings from /cfg.json..."));
|
|
|
|
|
|
|
|
success = readObjectFromFile("/cfg.json", nullptr, &doc);
|
|
|
|
if (!success) { //if file does not exist, try reading from EEPROM
|
2021-06-25 01:26:15 +02:00
|
|
|
deEEPSettings();
|
2021-12-04 01:05:01 +01:00
|
|
|
releaseJSONBufferLock();
|
2021-05-11 01:11:16 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-08-23 14:14:48 +02:00
|
|
|
// NOTE: This routine deserializes *and* applies the configuration
|
|
|
|
// Therefore, must also initialize ethernet from this function
|
2021-12-04 01:05:01 +01:00
|
|
|
bool needsSave = deserializeConfig(doc.as<JsonObject>(), true);
|
|
|
|
releaseJSONBufferLock();
|
|
|
|
|
|
|
|
if (needsSave) serializeConfig(); // usermods required new prameters
|
2020-11-04 11:04:40 +01:00
|
|
|
}
|
|
|
|
|
2020-11-05 22:54:13 +01:00
|
|
|
void serializeConfig() {
|
2020-11-07 23:54:56 +01:00
|
|
|
serializeConfigSec();
|
|
|
|
|
2020-11-06 22:12:48 +01:00
|
|
|
DEBUG_PRINTLN(F("Writing settings to /cfg.json..."));
|
|
|
|
|
2021-12-04 01:05:01 +01:00
|
|
|
#ifdef WLED_USE_DYNAMIC_JSON
|
2020-11-04 11:04:40 +01:00
|
|
|
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
2021-12-04 01:05:01 +01:00
|
|
|
#else
|
|
|
|
if (!requestJSONBufferLock(2)) return;
|
|
|
|
#endif
|
2020-11-04 11:04:40 +01:00
|
|
|
|
|
|
|
JsonArray rev = doc.createNestedArray("rev");
|
|
|
|
rev.add(1); //major settings revision
|
|
|
|
rev.add(0); //minor settings revision
|
|
|
|
|
2020-11-07 23:54:56 +01:00
|
|
|
doc[F("vid")] = VERSION;
|
2020-11-04 11:04:40 +01:00
|
|
|
|
|
|
|
JsonObject id = doc.createNestedObject("id");
|
2020-11-07 23:54:56 +01:00
|
|
|
id[F("mdns")] = cmDNS;
|
|
|
|
id[F("name")] = serverDescription;
|
|
|
|
id[F("inv")] = alexaInvocationName;
|
2020-11-04 11:04:40 +01:00
|
|
|
|
|
|
|
JsonObject nw = doc.createNestedObject("nw");
|
|
|
|
|
|
|
|
JsonArray nw_ins = nw.createNestedArray("ins");
|
|
|
|
|
|
|
|
JsonObject nw_ins_0 = nw_ins.createNestedObject();
|
2020-11-07 23:54:56 +01:00
|
|
|
nw_ins_0[F("ssid")] = clientSSID;
|
|
|
|
nw_ins_0[F("pskl")] = strlen(clientPass);
|
2020-11-04 11:04:40 +01:00
|
|
|
|
|
|
|
JsonArray nw_ins_0_ip = nw_ins_0.createNestedArray("ip");
|
|
|
|
JsonArray nw_ins_0_gw = nw_ins_0.createNestedArray("gw");
|
|
|
|
JsonArray nw_ins_0_sn = nw_ins_0.createNestedArray("sn");
|
|
|
|
|
|
|
|
for (byte i = 0; i < 4; i++) {
|
|
|
|
nw_ins_0_ip.add(staticIP[i]);
|
|
|
|
nw_ins_0_gw.add(staticGateway[i]);
|
|
|
|
nw_ins_0_sn.add(staticSubnet[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
JsonObject ap = doc.createNestedObject("ap");
|
2020-11-07 23:54:56 +01:00
|
|
|
ap[F("ssid")] = apSSID;
|
|
|
|
ap[F("pskl")] = strlen(apPass);
|
|
|
|
ap[F("chan")] = apChannel;
|
2020-12-19 17:09:39 +01:00
|
|
|
ap[F("hide")] = apHide;
|
2020-11-07 23:54:56 +01:00
|
|
|
ap[F("behav")] = apBehavior;
|
2020-11-04 11:04:40 +01:00
|
|
|
|
|
|
|
JsonArray ap_ip = ap.createNestedArray("ip");
|
|
|
|
ap_ip.add(4);
|
|
|
|
ap_ip.add(3);
|
|
|
|
ap_ip.add(2);
|
|
|
|
ap_ip.add(1);
|
|
|
|
|
|
|
|
JsonObject wifi = doc.createNestedObject("wifi");
|
2020-11-07 23:54:56 +01:00
|
|
|
wifi[F("sleep")] = !noWifiSleep;
|
2021-07-09 16:25:23 +02:00
|
|
|
//wifi[F("phy")] = 1;
|
2020-11-04 11:04:40 +01:00
|
|
|
|
2021-01-15 10:37:45 +01:00
|
|
|
#ifdef WLED_USE_ETHERNET
|
|
|
|
JsonObject ethernet = doc.createNestedObject("eth");
|
2021-03-13 22:04:37 +01:00
|
|
|
ethernet["type"] = ethernetType;
|
2021-10-11 02:19:33 +02:00
|
|
|
if (ethernetType != WLED_ETH_NONE && ethernetType < WLED_NUM_ETH_TYPES) {
|
|
|
|
JsonArray pins = ethernet.createNestedArray("pin");
|
|
|
|
for (uint8_t p=0; p<WLED_ETH_RSVD_PINS_COUNT; p++) pins.add(esp32_nonconfigurable_ethernet_pins[p].pin);
|
|
|
|
if (ethernetBoards[ethernetType].eth_power>=0) pins.add(ethernetBoards[ethernetType].eth_power);
|
|
|
|
if (ethernetBoards[ethernetType].eth_mdc>=0) pins.add(ethernetBoards[ethernetType].eth_mdc);
|
|
|
|
if (ethernetBoards[ethernetType].eth_mdio>=0) pins.add(ethernetBoards[ethernetType].eth_mdio);
|
|
|
|
switch (ethernetBoards[ethernetType].eth_clk_mode) {
|
|
|
|
case ETH_CLOCK_GPIO0_IN:
|
|
|
|
case ETH_CLOCK_GPIO0_OUT:
|
|
|
|
pins.add(0);
|
|
|
|
break;
|
|
|
|
case ETH_CLOCK_GPIO16_OUT:
|
|
|
|
pins.add(16);
|
|
|
|
break;
|
|
|
|
case ETH_CLOCK_GPIO17_OUT:
|
|
|
|
pins.add(17);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-01-15 10:37:45 +01:00
|
|
|
#endif
|
|
|
|
|
2020-11-04 11:04:40 +01:00
|
|
|
JsonObject hw = doc.createNestedObject("hw");
|
|
|
|
|
|
|
|
JsonObject hw_led = hw.createNestedObject("led");
|
2021-10-31 11:57:41 +01:00
|
|
|
hw_led[F("total")] = strip.getLengthTotal(); //no longer read, but provided for compatibility on downgrade
|
2020-11-07 23:54:56 +01:00
|
|
|
hw_led[F("maxpwr")] = strip.ablMilliampsMax;
|
|
|
|
hw_led[F("ledma")] = strip.milliampsPerLed;
|
2021-11-24 11:02:25 +01:00
|
|
|
hw_led["cct"] = correctWB;
|
2021-11-26 20:18:38 +01:00
|
|
|
hw_led[F("cr")] = cctFromRgb;
|
2022-03-08 02:16:33 +01:00
|
|
|
hw_led[F("cb")] = strip.cctBlending;
|
|
|
|
hw_led["fps"] = strip.getTargetFps();
|
|
|
|
hw_led[F("rgbwm")] = strip.autoWhiteMode;
|
2020-11-04 11:04:40 +01:00
|
|
|
|
|
|
|
JsonArray hw_led_ins = hw_led.createNestedArray("ins");
|
|
|
|
|
2021-01-21 01:21:16 +01:00
|
|
|
for (uint8_t s = 0; s < busses.getNumBusses(); s++) {
|
|
|
|
Bus *bus = busses.getBus(s);
|
2021-01-17 00:20:31 +01:00
|
|
|
if (!bus || bus->getLength()==0) break;
|
2021-01-21 01:21:16 +01:00
|
|
|
JsonObject ins = hw_led_ins.createNestedObject();
|
2021-09-12 01:15:51 +02:00
|
|
|
ins["start"] = bus->getStart();
|
2022-02-04 10:10:37 +01:00
|
|
|
ins["len"] = bus->getLength();
|
2021-01-21 01:21:16 +01:00
|
|
|
JsonArray ins_pin = ins.createNestedArray("pin");
|
|
|
|
uint8_t pins[5];
|
|
|
|
uint8_t nPins = bus->getPins(pins);
|
|
|
|
for (uint8_t i = 0; i < nPins; i++) ins_pin.add(pins[i]);
|
|
|
|
ins[F("order")] = bus->getColorOrder();
|
2021-03-04 12:10:18 +01:00
|
|
|
ins["rev"] = bus->reversed;
|
2021-05-17 16:23:46 +02:00
|
|
|
ins[F("skip")] = bus->skippedLeds();
|
2021-10-20 20:29:13 +02:00
|
|
|
ins["type"] = bus->getType() & 0x7F;
|
2021-10-11 02:19:33 +02:00
|
|
|
ins["ref"] = bus->isOffRefreshRequired();
|
2022-02-04 10:10:37 +01:00
|
|
|
//ins[F("rgbw")] = bus->isRgbw();
|
2021-01-17 00:20:31 +01:00
|
|
|
}
|
2020-11-04 11:04:40 +01:00
|
|
|
|
2022-01-26 00:42:04 +01:00
|
|
|
JsonArray hw_com = hw.createNestedArray(F("com"));
|
|
|
|
const ColorOrderMap& com = busses.getColorOrderMap();
|
|
|
|
for (uint8_t s = 0; s < com.count(); s++) {
|
|
|
|
const ColorOrderMapEntry *entry = com.get(s);
|
|
|
|
if (!entry) break;
|
|
|
|
|
|
|
|
JsonObject co = hw_com.createNestedObject();
|
2022-02-04 10:10:37 +01:00
|
|
|
co["start"] = entry->start;
|
|
|
|
co["len"] = entry->len;
|
2022-01-26 00:42:04 +01:00
|
|
|
co[F("order")] = entry->colorOrder;
|
|
|
|
}
|
|
|
|
|
2021-05-20 19:54:07 +02:00
|
|
|
// button(s)
|
2020-11-04 11:04:40 +01:00
|
|
|
JsonObject hw_btn = hw.createNestedObject("btn");
|
2021-05-20 19:54:07 +02:00
|
|
|
hw_btn["max"] = WLED_MAX_BUTTONS; // just information about max number of buttons (not actually used)
|
2020-11-04 11:04:40 +01:00
|
|
|
JsonArray hw_btn_ins = hw_btn.createNestedArray("ins");
|
|
|
|
|
2021-07-09 16:25:23 +02:00
|
|
|
// configuration for all buttons
|
|
|
|
for (uint8_t i=0; i<WLED_MAX_BUTTONS; i++) {
|
|
|
|
JsonObject hw_btn_ins_0 = hw_btn_ins.createNestedObject();
|
2021-05-20 19:54:07 +02:00
|
|
|
hw_btn_ins_0["type"] = buttonType[i];
|
2021-07-09 16:25:23 +02:00
|
|
|
JsonArray hw_btn_ins_0_pin = hw_btn_ins_0.createNestedArray("pin");
|
2021-05-20 19:54:07 +02:00
|
|
|
hw_btn_ins_0_pin.add(btnPin[i]);
|
2021-07-09 16:25:23 +02:00
|
|
|
JsonArray hw_btn_ins_0_macros = hw_btn_ins_0.createNestedArray("macros");
|
2021-05-20 19:54:07 +02:00
|
|
|
hw_btn_ins_0_macros.add(macroButton[i]);
|
|
|
|
hw_btn_ins_0_macros.add(macroLongPress[i]);
|
|
|
|
hw_btn_ins_0_macros.add(macroDoublePress[i]);
|
|
|
|
}
|
2021-07-09 16:25:23 +02:00
|
|
|
|
2021-05-20 19:54:07 +02:00
|
|
|
hw_btn[F("tt")] = touchThreshold;
|
2021-07-01 20:51:52 +02:00
|
|
|
hw_btn["mqtt"] = buttonPublishMqtt;
|
2020-11-04 11:04:40 +01:00
|
|
|
|
2021-03-30 02:04:02 +02:00
|
|
|
JsonObject hw_ir = hw.createNestedObject("ir");
|
|
|
|
hw_ir["pin"] = irPin;
|
2021-10-11 02:19:33 +02:00
|
|
|
hw_ir["type"] = irEnabled; // the byte 'irEnabled' does contain the IR-Remote Type ( 0=disabled )
|
2022-02-26 01:37:09 +01:00
|
|
|
hw_ir["sel"] = irApplyToAllSelected;
|
2020-11-04 11:04:40 +01:00
|
|
|
|
2021-03-13 22:04:37 +01:00
|
|
|
JsonObject hw_relay = hw.createNestedObject(F("relay"));
|
|
|
|
hw_relay["pin"] = rlyPin;
|
2021-03-04 12:10:18 +01:00
|
|
|
hw_relay["rev"] = !rlyMde;
|
2021-01-17 00:20:31 +01:00
|
|
|
|
2022-02-01 20:02:46 +01:00
|
|
|
hw[F("baud")] = serialBaud;
|
|
|
|
|
2021-01-17 00:20:31 +01:00
|
|
|
//JsonObject hw_status = hw.createNestedObject("status");
|
2021-03-13 22:04:37 +01:00
|
|
|
//hw_status["pin"] = -1;
|
2020-11-04 11:04:40 +01:00
|
|
|
|
2021-03-13 22:04:37 +01:00
|
|
|
JsonObject light = doc.createNestedObject(F("light"));
|
2020-11-07 23:54:56 +01:00
|
|
|
light[F("scale-bri")] = briMultiplier;
|
|
|
|
light[F("pal-mode")] = strip.paletteBlend;
|
2021-09-11 01:17:42 +02:00
|
|
|
light[F("aseg")] = autoSegments;
|
2020-11-04 11:04:40 +01:00
|
|
|
|
|
|
|
JsonObject light_gc = light.createNestedObject("gc");
|
|
|
|
light_gc["bri"] = (strip.gammaCorrectBri) ? 2.8 : 1.0;
|
2021-03-13 22:04:37 +01:00
|
|
|
light_gc["col"] = (strip.gammaCorrectCol) ? 2.8 : 1.0;
|
2020-11-04 11:04:40 +01:00
|
|
|
|
|
|
|
JsonObject light_tr = light.createNestedObject("tr");
|
2022-02-04 10:10:37 +01:00
|
|
|
light_tr["mode"] = fadeTransition;
|
2021-05-20 19:54:07 +02:00
|
|
|
light_tr["dur"] = transitionDelayDefault / 100;
|
2021-05-11 01:11:16 +02:00
|
|
|
light_tr["pal"] = strip.paletteFade;
|
2020-11-04 11:04:40 +01:00
|
|
|
|
|
|
|
JsonObject light_nl = light.createNestedObject("nl");
|
2022-02-04 10:10:37 +01:00
|
|
|
light_nl["mode"] = nightlightMode;
|
2021-05-20 19:54:07 +02:00
|
|
|
light_nl["dur"] = nightlightDelayMinsDefault;
|
2020-11-07 23:54:56 +01:00
|
|
|
light_nl[F("tbri")] = nightlightTargetBri;
|
2021-07-01 20:51:52 +02:00
|
|
|
light_nl["macro"] = macroNl;
|
2020-11-04 11:04:40 +01:00
|
|
|
|
|
|
|
JsonObject def = doc.createNestedObject("def");
|
2021-11-23 13:17:33 +01:00
|
|
|
def["ps"] = bootPreset;
|
2020-11-04 11:04:40 +01:00
|
|
|
def["on"] = turnOnAtBoot;
|
|
|
|
def["bri"] = briS;
|
|
|
|
|
|
|
|
JsonObject interfaces = doc.createNestedObject("if");
|
|
|
|
|
|
|
|
JsonObject if_sync = interfaces.createNestedObject("sync");
|
2020-11-07 23:54:56 +01:00
|
|
|
if_sync[F("port0")] = udpPort;
|
|
|
|
if_sync[F("port1")] = udpPort2;
|
2020-11-04 11:04:40 +01:00
|
|
|
|
|
|
|
JsonObject if_sync_recv = if_sync.createNestedObject("recv");
|
|
|
|
if_sync_recv["bri"] = receiveNotificationBrightness;
|
2021-03-13 22:04:37 +01:00
|
|
|
if_sync_recv["col"] = receiveNotificationColor;
|
2022-02-16 14:55:35 +01:00
|
|
|
if_sync_recv["fx"] = receiveNotificationEffects;
|
2021-08-25 16:39:12 +02:00
|
|
|
if_sync_recv["grp"] = receiveGroups;
|
2021-12-17 20:33:48 +01:00
|
|
|
if_sync_recv["seg"] = receiveSegmentOptions;
|
2022-02-16 14:55:35 +01:00
|
|
|
if_sync_recv["sb"] = receiveSegmentBounds;
|
2020-11-04 11:04:40 +01:00
|
|
|
|
|
|
|
JsonObject if_sync_send = if_sync.createNestedObject("send");
|
2020-11-07 23:54:56 +01:00
|
|
|
if_sync_send[F("dir")] = notifyDirect;
|
2021-07-01 20:51:52 +02:00
|
|
|
if_sync_send["btn"] = notifyButton;
|
|
|
|
if_sync_send["va"] = notifyAlexa;
|
|
|
|
if_sync_send["hue"] = notifyHue;
|
|
|
|
if_sync_send["macro"] = notifyMacro;
|
2020-11-07 23:54:56 +01:00
|
|
|
if_sync_send[F("twice")] = notifyTwice;
|
2021-08-25 16:39:12 +02:00
|
|
|
if_sync_send["grp"] = syncGroups;
|
2020-11-07 23:54:56 +01:00
|
|
|
|
2021-03-13 22:04:37 +01:00
|
|
|
JsonObject if_nodes = interfaces.createNestedObject("nodes");
|
|
|
|
if_nodes[F("list")] = nodeListEnabled;
|
|
|
|
if_nodes[F("bcast")] = nodeBroadcastEnabled;
|
|
|
|
|
2020-11-07 23:54:56 +01:00
|
|
|
JsonObject if_live = interfaces.createNestedObject("live");
|
2021-03-13 22:04:37 +01:00
|
|
|
if_live["en"] = receiveDirect;
|
|
|
|
if_live["port"] = e131Port;
|
2020-11-07 23:54:56 +01:00
|
|
|
if_live[F("mc")] = e131Multicast;
|
|
|
|
|
|
|
|
JsonObject if_live_dmx = if_live.createNestedObject("dmx");
|
|
|
|
if_live_dmx[F("uni")] = e131Universe;
|
|
|
|
if_live_dmx[F("seqskip")] = e131SkipOutOfSequence;
|
|
|
|
if_live_dmx[F("addr")] = DMXAddress;
|
2022-02-04 10:10:37 +01:00
|
|
|
if_live_dmx["mode"] = DMXMode;
|
2021-08-19 18:24:41 +02:00
|
|
|
|
2020-11-07 23:54:56 +01:00
|
|
|
if_live[F("timeout")] = realtimeTimeoutMs / 100;
|
|
|
|
if_live[F("maxbri")] = arlsForceMaxBri;
|
|
|
|
if_live[F("no-gc")] = arlsDisableGammaCorrection;
|
|
|
|
if_live[F("offset")] = arlsOffset;
|
2020-11-04 11:04:40 +01:00
|
|
|
|
|
|
|
JsonObject if_va = interfaces.createNestedObject("va");
|
2020-11-07 23:54:56 +01:00
|
|
|
if_va[F("alexa")] = alexaEnabled;
|
2020-11-04 11:04:40 +01:00
|
|
|
|
|
|
|
JsonArray if_va_macros = if_va.createNestedArray("macros");
|
|
|
|
if_va_macros.add(macroAlexaOn);
|
|
|
|
if_va_macros.add(macroAlexaOff);
|
2021-05-20 19:54:07 +02:00
|
|
|
|
|
|
|
#ifndef WLED_DISABLE_BLYNK
|
2020-11-04 11:04:40 +01:00
|
|
|
JsonObject if_blynk = interfaces.createNestedObject("blynk");
|
2020-11-07 23:54:56 +01:00
|
|
|
if_blynk[F("token")] = strlen(blynkApiKey) ? "Hidden":"";
|
2020-12-22 00:44:16 +01:00
|
|
|
if_blynk[F("host")] = blynkHost;
|
2021-03-13 22:04:37 +01:00
|
|
|
if_blynk["port"] = blynkPort;
|
2021-05-20 19:54:07 +02:00
|
|
|
#endif
|
2020-11-04 11:04:40 +01:00
|
|
|
|
2021-05-20 19:54:07 +02:00
|
|
|
#ifdef WLED_ENABLE_MQTT
|
2020-11-04 11:04:40 +01:00
|
|
|
JsonObject if_mqtt = interfaces.createNestedObject("mqtt");
|
2021-03-13 22:04:37 +01:00
|
|
|
if_mqtt["en"] = mqttEnabled;
|
2020-11-07 23:54:56 +01:00
|
|
|
if_mqtt[F("broker")] = mqttServer;
|
2021-03-13 22:04:37 +01:00
|
|
|
if_mqtt["port"] = mqttPort;
|
2020-11-07 23:54:56 +01:00
|
|
|
if_mqtt[F("user")] = mqttUser;
|
|
|
|
if_mqtt[F("pskl")] = strlen(mqttPass);
|
|
|
|
if_mqtt[F("cid")] = mqttClientID;
|
2020-11-04 11:04:40 +01:00
|
|
|
|
2021-03-13 22:04:37 +01:00
|
|
|
JsonObject if_mqtt_topics = if_mqtt.createNestedObject(F("topics"));
|
2020-11-07 23:54:56 +01:00
|
|
|
if_mqtt_topics[F("device")] = mqttDeviceTopic;
|
|
|
|
if_mqtt_topics[F("group")] = mqttGroupTopic;
|
2021-05-20 19:54:07 +02:00
|
|
|
#endif
|
2020-11-04 11:04:40 +01:00
|
|
|
|
2021-05-20 19:54:07 +02:00
|
|
|
#ifndef WLED_DISABLE_HUESYNC
|
2020-11-04 11:04:40 +01:00
|
|
|
JsonObject if_hue = interfaces.createNestedObject("hue");
|
2021-03-13 22:04:37 +01:00
|
|
|
if_hue["en"] = huePollingEnabled;
|
|
|
|
if_hue["id"] = huePollLightId;
|
2020-11-07 23:54:56 +01:00
|
|
|
if_hue[F("iv")] = huePollIntervalMs / 100;
|
2020-11-04 11:04:40 +01:00
|
|
|
|
|
|
|
JsonObject if_hue_recv = if_hue.createNestedObject("recv");
|
|
|
|
if_hue_recv["on"] = hueApplyOnOff;
|
|
|
|
if_hue_recv["bri"] = hueApplyBri;
|
2021-03-13 22:04:37 +01:00
|
|
|
if_hue_recv["col"] = hueApplyColor;
|
2020-11-04 11:04:40 +01:00
|
|
|
|
|
|
|
JsonArray if_hue_ip = if_hue.createNestedArray("ip");
|
|
|
|
for (byte i = 0; i < 4; i++) {
|
|
|
|
if_hue_ip.add(hueIP[i]);
|
|
|
|
}
|
2021-05-20 19:54:07 +02:00
|
|
|
#endif
|
2020-11-04 11:04:40 +01:00
|
|
|
|
|
|
|
JsonObject if_ntp = interfaces.createNestedObject("ntp");
|
2021-03-13 22:04:37 +01:00
|
|
|
if_ntp["en"] = ntpEnabled;
|
2020-11-07 23:54:56 +01:00
|
|
|
if_ntp[F("host")] = ntpServerName;
|
|
|
|
if_ntp[F("tz")] = currentTimezone;
|
|
|
|
if_ntp[F("offset")] = utcOffsetSecs;
|
|
|
|
if_ntp[F("ampm")] = useAMPM;
|
2021-04-12 21:53:22 +02:00
|
|
|
if_ntp[F("ln")] = longitude;
|
|
|
|
if_ntp[F("lt")] = latitude;
|
2020-11-04 11:04:40 +01:00
|
|
|
|
|
|
|
JsonObject ol = doc.createNestedObject("ol");
|
2022-03-07 00:11:43 +01:00
|
|
|
ol[F("clock")] = overlayCurrent;
|
2020-11-07 23:54:56 +01:00
|
|
|
ol[F("cntdwn")] = countdownMode;
|
2020-11-04 11:04:40 +01:00
|
|
|
|
2021-05-20 19:54:07 +02:00
|
|
|
ol["min"] = overlayMin;
|
2020-12-10 01:28:42 +01:00
|
|
|
ol[F("max")] = overlayMax;
|
|
|
|
ol[F("o12pix")] = analogClock12pixel;
|
|
|
|
ol[F("o5m")] = analogClock5MinuteMarks;
|
|
|
|
ol[F("osec")] = analogClockSecondsTrail;
|
|
|
|
|
2021-03-13 22:04:37 +01:00
|
|
|
JsonObject timers = doc.createNestedObject(F("timers"));
|
2020-11-04 11:04:40 +01:00
|
|
|
|
2021-03-13 22:04:37 +01:00
|
|
|
JsonObject cntdwn = timers.createNestedObject(F("cntdwn"));
|
|
|
|
JsonArray goal = cntdwn.createNestedArray(F("goal"));
|
2020-11-04 11:04:40 +01:00
|
|
|
goal.add(countdownYear); goal.add(countdownMonth); goal.add(countdownDay);
|
|
|
|
goal.add(countdownHour); goal.add(countdownMin); goal.add(countdownSec);
|
2021-07-01 20:51:52 +02:00
|
|
|
cntdwn["macro"] = macroCountdown;
|
2020-11-04 11:04:40 +01:00
|
|
|
|
|
|
|
JsonArray timers_ins = timers.createNestedArray("ins");
|
|
|
|
|
2021-04-12 21:53:22 +02:00
|
|
|
for (byte i = 0; i < 10; i++) {
|
|
|
|
if (timerMacro[i] == 0 && timerHours[i] == 0 && timerMinutes[i] == 0) continue; // sunrise/sunset get saved always (timerHours=255)
|
2020-11-04 11:04:40 +01:00
|
|
|
JsonObject timers_ins0 = timers_ins.createNestedObject();
|
2021-03-13 22:04:37 +01:00
|
|
|
timers_ins0["en"] = (timerWeekday[i] & 0x01);
|
2020-11-07 23:54:56 +01:00
|
|
|
timers_ins0[F("hour")] = timerHours[i];
|
2021-05-20 19:54:07 +02:00
|
|
|
timers_ins0["min"] = timerMinutes[i];
|
2021-07-01 20:51:52 +02:00
|
|
|
timers_ins0["macro"] = timerMacro[i];
|
2020-11-07 23:54:56 +01:00
|
|
|
timers_ins0[F("dow")] = timerWeekday[i] >> 1;
|
2021-12-31 14:09:48 +01:00
|
|
|
if (i<8) {
|
2022-02-26 01:37:09 +01:00
|
|
|
JsonObject start = timers_ins0.createNestedObject("start");
|
2021-12-31 14:09:48 +01:00
|
|
|
start["mon"] = (timerMonth[i] >> 4) & 0xF;
|
|
|
|
start["day"] = timerDay[i];
|
2022-02-26 01:37:09 +01:00
|
|
|
JsonObject end = timers_ins0.createNestedObject("end");
|
|
|
|
end["mon"] = timerMonth[i] & 0xF;
|
2021-12-31 14:09:48 +01:00
|
|
|
end["day"] = timerDayEnd[i];
|
|
|
|
}
|
2020-11-04 11:04:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
JsonObject ota = doc.createNestedObject("ota");
|
2020-11-07 23:54:56 +01:00
|
|
|
ota[F("lock")] = otaLock;
|
|
|
|
ota[F("lock-wifi")] = wifiLock;
|
|
|
|
ota[F("pskl")] = strlen(otaPass);
|
|
|
|
ota[F("aota")] = aOtaEnabled;
|
2020-11-08 23:44:10 +01:00
|
|
|
|
|
|
|
#ifdef WLED_ENABLE_DMX
|
|
|
|
JsonObject dmx = doc.createNestedObject("dmx");
|
|
|
|
dmx[F("chan")] = DMXChannels;
|
|
|
|
dmx[F("gap")] = DMXGap;
|
2021-09-12 01:15:51 +02:00
|
|
|
dmx["start"] = DMXStart;
|
2020-11-08 23:44:10 +01:00
|
|
|
dmx[F("start-led")] = DMXStartLED;
|
|
|
|
|
2021-03-13 22:04:37 +01:00
|
|
|
JsonArray dmx_fixmap = dmx.createNestedArray(F("fixmap"));
|
2021-11-30 23:10:23 +01:00
|
|
|
for (byte i = 0; i < 15; i++) {
|
2020-11-08 23:44:10 +01:00
|
|
|
dmx_fixmap.add(DMXFixtureMap[i]);
|
2021-11-30 23:10:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
dmx[F("e131proxy")] = e131ProxyUniverse;
|
2020-11-08 23:44:10 +01:00
|
|
|
#endif
|
2020-11-04 11:04:40 +01:00
|
|
|
|
2020-11-11 15:50:15 +01:00
|
|
|
JsonObject usermods_settings = doc.createNestedObject("um");
|
|
|
|
usermods.addToConfig(usermods_settings);
|
|
|
|
|
2020-11-06 22:12:48 +01:00
|
|
|
File f = WLED_FS.open("/cfg.json", "w");
|
|
|
|
if (f) serializeJson(doc, f);
|
|
|
|
f.close();
|
2021-12-04 01:05:01 +01:00
|
|
|
releaseJSONBufferLock();
|
2020-11-04 17:17:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//settings in /wsec.json, not accessible via webserver, for passwords and tokens
|
2020-11-05 22:54:13 +01:00
|
|
|
bool deserializeConfigSec() {
|
2020-11-06 22:12:48 +01:00
|
|
|
DEBUG_PRINTLN(F("Reading settings from /wsec.json..."));
|
|
|
|
|
2021-12-04 01:05:01 +01:00
|
|
|
#ifdef WLED_USE_DYNAMIC_JSON
|
2020-11-04 17:17:54 +01:00
|
|
|
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
2021-12-04 01:05:01 +01:00
|
|
|
#else
|
|
|
|
if (!requestJSONBufferLock(3)) return false;
|
|
|
|
#endif
|
2020-11-04 17:17:54 +01:00
|
|
|
|
2020-11-06 22:12:48 +01:00
|
|
|
bool success = readObjectFromFile("/wsec.json", nullptr, &doc);
|
2021-12-04 01:05:01 +01:00
|
|
|
if (!success) {
|
|
|
|
releaseJSONBufferLock();
|
|
|
|
return false;
|
|
|
|
}
|
2020-11-06 22:12:48 +01:00
|
|
|
|
2021-06-30 12:33:51 +02:00
|
|
|
JsonObject nw_ins_0 = doc["nw"]["ins"][0];
|
2020-11-04 17:17:54 +01:00
|
|
|
getStringFromJson(clientPass, nw_ins_0["psk"], 65);
|
|
|
|
|
2021-03-13 22:04:37 +01:00
|
|
|
JsonObject ap = doc["ap"];
|
2020-11-04 17:17:54 +01:00
|
|
|
getStringFromJson(apPass, ap["psk"] , 65);
|
|
|
|
|
2020-11-05 22:54:13 +01:00
|
|
|
JsonObject interfaces = doc["if"];
|
2020-11-04 17:17:54 +01:00
|
|
|
|
2021-05-20 19:54:07 +02:00
|
|
|
#ifndef WLED_DISABLE_BLYNK
|
2020-11-07 23:54:56 +01:00
|
|
|
const char* apikey = interfaces["blynk"][F("token")] | "Hidden";
|
2020-11-05 22:54:13 +01:00
|
|
|
int tdd = strnlen(apikey, 36);
|
|
|
|
if (tdd > 20 || tdd == 0)
|
|
|
|
getStringFromJson(blynkApiKey, apikey, 36);
|
2021-05-20 19:54:07 +02:00
|
|
|
#endif
|
2020-11-04 17:17:54 +01:00
|
|
|
|
2021-05-20 19:54:07 +02:00
|
|
|
#ifdef WLED_ENABLE_MQTT
|
2021-03-13 22:04:37 +01:00
|
|
|
JsonObject if_mqtt = interfaces["mqtt"];
|
2021-06-30 01:23:35 +02:00
|
|
|
getStringFromJson(mqttPass, if_mqtt["psk"], 65);
|
2021-05-20 19:54:07 +02:00
|
|
|
#endif
|
2020-11-04 17:17:54 +01:00
|
|
|
|
2021-05-20 19:54:07 +02:00
|
|
|
#ifndef WLED_DISABLE_HUESYNC
|
2021-07-01 20:51:52 +02:00
|
|
|
getStringFromJson(hueApiKey, interfaces["hue"][F("key")], 47);
|
2021-05-20 19:54:07 +02:00
|
|
|
#endif
|
2020-11-05 22:54:13 +01:00
|
|
|
|
|
|
|
JsonObject ota = doc["ota"];
|
2020-11-07 23:54:56 +01:00
|
|
|
getStringFromJson(otaPass, ota[F("pwd")], 33);
|
|
|
|
CJSON(otaLock, ota[F("lock")]);
|
|
|
|
CJSON(wifiLock, ota[F("lock-wifi")]);
|
|
|
|
CJSON(aOtaEnabled, ota[F("aota")]);
|
2020-11-06 22:12:48 +01:00
|
|
|
|
2021-12-04 01:05:01 +01:00
|
|
|
releaseJSONBufferLock();
|
2020-11-06 22:12:48 +01:00
|
|
|
return true;
|
2020-11-04 17:17:54 +01:00
|
|
|
}
|
|
|
|
|
2020-11-05 22:54:13 +01:00
|
|
|
void serializeConfigSec() {
|
2020-11-06 22:12:48 +01:00
|
|
|
DEBUG_PRINTLN(F("Writing settings to /wsec.json..."));
|
|
|
|
|
2021-12-04 01:05:01 +01:00
|
|
|
#ifdef WLED_USE_DYNAMIC_JSON
|
2020-11-06 22:12:48 +01:00
|
|
|
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
|
2021-12-04 01:05:01 +01:00
|
|
|
#else
|
|
|
|
if (!requestJSONBufferLock(4)) return;
|
|
|
|
#endif
|
2020-11-06 22:12:48 +01:00
|
|
|
|
|
|
|
JsonObject nw = doc.createNestedObject("nw");
|
|
|
|
|
|
|
|
JsonArray nw_ins = nw.createNestedArray("ins");
|
|
|
|
|
|
|
|
JsonObject nw_ins_0 = nw_ins.createNestedObject();
|
|
|
|
nw_ins_0["psk"] = clientPass;
|
|
|
|
|
|
|
|
JsonObject ap = doc.createNestedObject("ap");
|
|
|
|
ap["psk"] = apPass;
|
|
|
|
|
|
|
|
JsonObject interfaces = doc.createNestedObject("if");
|
2021-05-20 19:54:07 +02:00
|
|
|
#ifndef WLED_DISABLE_BLYNK
|
2020-11-06 22:12:48 +01:00
|
|
|
JsonObject if_blynk = interfaces.createNestedObject("blynk");
|
2020-11-07 23:54:56 +01:00
|
|
|
if_blynk[F("token")] = blynkApiKey;
|
2021-05-20 19:54:07 +02:00
|
|
|
#endif
|
|
|
|
#ifdef WLED_ENABLE_MQTT
|
2020-11-06 22:12:48 +01:00
|
|
|
JsonObject if_mqtt = interfaces.createNestedObject("mqtt");
|
|
|
|
if_mqtt["psk"] = mqttPass;
|
2021-05-20 19:54:07 +02:00
|
|
|
#endif
|
|
|
|
#ifndef WLED_DISABLE_HUESYNC
|
2020-11-06 22:12:48 +01:00
|
|
|
JsonObject if_hue = interfaces.createNestedObject("hue");
|
2020-11-07 23:54:56 +01:00
|
|
|
if_hue[F("key")] = hueApiKey;
|
2021-05-20 19:54:07 +02:00
|
|
|
#endif
|
2020-11-06 22:12:48 +01:00
|
|
|
|
|
|
|
JsonObject ota = doc.createNestedObject("ota");
|
2020-11-07 23:54:56 +01:00
|
|
|
ota[F("pwd")] = otaPass;
|
|
|
|
ota[F("lock")] = otaLock;
|
|
|
|
ota[F("lock-wifi")] = wifiLock;
|
|
|
|
ota[F("aota")] = aOtaEnabled;
|
2020-11-04 17:17:54 +01:00
|
|
|
|
2020-11-06 22:12:48 +01:00
|
|
|
File f = WLED_FS.open("/wsec.json", "w");
|
|
|
|
if (f) serializeJson(doc, f);
|
|
|
|
f.close();
|
2021-12-04 01:05:01 +01:00
|
|
|
releaseJSONBufferLock();
|
2020-12-21 21:04:21 +01:00
|
|
|
}
|