This commit is contained in:
cschwinne 2020-11-07 23:54:56 +01:00
parent 3ff23ade8b
commit 362156c8ab
5 changed files with 263 additions and 276 deletions

View File

@ -32,26 +32,26 @@ void deserializeConfig() {
//deserializeJson(doc, json);
//int rev_major = doc["rev"][0]; // 1
//int rev_minor = doc["rev"][1]; // 0
//int rev_major = doc[F("rev")][0]; // 1
//int rev_minor = doc[F("rev")][1]; // 0
//long vid = doc["vid"]; // 2010020
//long vid = doc[F("vid")]; // 2010020
JsonObject id = doc["id"];
getStringFromJson(cmDNS, id["mdns"], 33);
getStringFromJson(serverDescription, id["name"], 33);
getStringFromJson(alexaInvocationName, id["inv"], 33);
JsonObject id = doc[F("id")];
getStringFromJson(cmDNS, id[F("mdns")], 33);
getStringFromJson(serverDescription, id[F("name")], 33);
getStringFromJson(alexaInvocationName, id[F("inv")], 33);
JsonObject nw_ins_0 = doc["nw"]["ins"][0];
getStringFromJson(clientSSID, nw_ins_0["ssid"], 33);
//int nw_ins_0_pskl = nw_ins_0["pskl"];
JsonObject nw_ins_0 = doc["nw"][F("ins")][0];
getStringFromJson(clientSSID, nw_ins_0[F("ssid")], 33);
//int nw_ins_0_pskl = nw_ins_0[F("pskl")];
//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);
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"];
JsonArray nw_ins_0_ip = nw_ins_0[F("ip")];
JsonArray nw_ins_0_gw = nw_ins_0[F("gw")];
JsonArray nw_ins_0_sn = nw_ins_0[F("sn")];
for (byte i = 0; i < 4; i++) {
CJSON(staticIP[i], nw_ins_0_ip[i]);
@ -59,226 +59,226 @@ void deserializeConfig() {
CJSON(staticSubnet[i], nw_ins_0_sn[i]);
}
JsonObject ap = doc["ap"];
getStringFromJson(apSSID, ap["ssid"], 33);
JsonObject ap = doc[F("ap")];
getStringFromJson(apSSID, ap[F("ssid")], 33);
getStringFromJson(apPass, ap["psk"] , 65); //normally not present due to security
//int ap_pskl = ap["pskl"];
//int ap_pskl = ap[F("pskl")];
CJSON(apChannel, ap["chan"]);
CJSON(apChannel, ap[F("chan")]);
if (apChannel > 13 || apChannel < 1) apChannel = 1;
CJSON(apHide, ap["hide"]);
CJSON(apHide, ap[F("hide")]);
if (apHide > 1) apHide = 1;
CJSON(apBehavior, ap["behav"]);
CJSON(apBehavior, ap[F("behav")]);
/*
JsonArray ap_ip = ap["ip"];
JsonArray ap_ip = ap[F("ip")];
for (byte i = 0; i < 4; i++) {
apIP[i] = ap_ip;
}*/
noWifiSleep = doc["wifi"]["sleep"] | !noWifiSleep; // inverted
noWifiSleep = doc[F("wifi")][F("sleep")] | !noWifiSleep; // inverted
noWifiSleep = !noWifiSleep;
//int wifi_phy = doc["wifi"]["phy"]; //force phy mode n?
//int wifi_phy = doc[F("wifi")][F("phy")]; //force phy mode n?
JsonObject hw = doc["hw"];
JsonObject hw = doc[F("hw")];
JsonObject hw_led = hw["led"];
CJSON(ledCount, hw_led["total"]);
JsonObject hw_led = hw[F("led")];
CJSON(ledCount, hw_led[F("total")]);
if (ledCount > MAX_LEDS) ledCount = MAX_LEDS;
CJSON(strip.ablMilliampsMax, hw_led["maxpwr"]);
CJSON(strip.milliampsPerLed, hw_led["ledma"]);
CJSON(strip.reverseMode, hw_led["rev"]);
CJSON(strip.ablMilliampsMax, hw_led[F("maxpwr")]);
CJSON(strip.milliampsPerLed, hw_led[F("ledma")]);
CJSON(strip.reverseMode, hw_led[F("rev")]);
JsonObject hw_led_ins_0 = hw_led["ins"][0];
//bool hw_led_ins_0_en = hw_led_ins_0["en"]; // true
//int hw_led_ins_0_start = hw_led_ins_0["start"]; // 0
//int hw_led_ins_0_len = hw_led_ins_0["len"]; // 1200
JsonObject hw_led_ins_0 = hw_led[F("ins")][0];
//bool hw_led_ins_0_en = hw_led_ins_0[F("en")]; // true
//int hw_led_ins_0_start = hw_led_ins_0[F("start")]; // 0
//int hw_led_ins_0_len = hw_led_ins_0[F("len")]; // 1200
//int hw_led_ins_0_pin_0 = hw_led_ins_0["pin"][0]; // 2
//int hw_led_ins_0_pin_0 = hw_led_ins_0[F("pin")][0]; // 2
strip.colorOrder = hw_led_ins_0["order"];
//bool hw_led_ins_0_rev = hw_led_ins_0["rev"]; // false
skipFirstLed = hw_led_ins_0["skip"]; // 0
//int hw_led_ins_0_type = hw_led_ins_0["type"]; // 2*/
strip.colorOrder = hw_led_ins_0[F("order")];
//bool hw_led_ins_0_rev = hw_led_ins_0[F("rev")]; // false
skipFirstLed = hw_led_ins_0[F("skip")]; // 0
//int hw_led_ins_0_type = hw_led_ins_0[F("type")]; // 2*/
JsonObject hw_btn_ins_0 = hw["btn"]["ins"][0];
buttonEnabled = hw_btn_ins_0["en"] | buttonEnabled;
JsonObject hw_btn_ins_0 = hw[F("btn")][F("ins")][0];
buttonEnabled = hw_btn_ins_0[F("en")] | buttonEnabled;
//int hw_btn_ins_0_pin_0 = hw_btn_ins_0["pin"][0]; // 0
//int hw_btn_ins_0_pin_0 = hw_btn_ins_0[F("pin")][0]; // 0
JsonArray hw_btn_ins_0_macros = hw_btn_ins_0["macros"];
JsonArray hw_btn_ins_0_macros = hw_btn_ins_0[F("macros")];
CJSON(macroButton, hw_btn_ins_0_macros[0]);
CJSON(macroLongPress,hw_btn_ins_0_macros[1]);
CJSON(macroDoublePress, hw_btn_ins_0_macros[2]);
//int hw_btn_ins_0_type = hw_btn_ins_0["type"]; // 0
//int hw_btn_ins_0_type = hw_btn_ins_0[F("type")]; // 0
//int hw_ir_pin = hw["ir"]["pin"]; // 4
CJSON(irEnabled, hw["ir"]["type"]); // 0
//int hw_ir_pin = hw[F("ir")][F("pin")]; // 4
CJSON(irEnabled, hw[F("ir")][F("type")]); // 0
//int hw_relay_pin = hw["relay"]["pin"]; // 12
//bool hw_relay_rev = hw["relay"]["rev"]; // false
//int hw_relay_pin = hw[F("relay")][F("pin")]; // 12
//bool hw_relay_rev = hw[F("relay")][F("rev")]; // false
//int hw_status_pin = hw["status"]["pin"]; // -1
//int hw_status_pin = hw[F("status")][F("pin")]; // -1
JsonObject light = doc["light"];
CJSON(briMultiplier, light["scale-bri"]);
CJSON(strip.paletteBlend, light["pal-mode"]);
JsonObject light = doc[F("light")];
CJSON(briMultiplier, light[F("scale-bri")]);
CJSON(strip.paletteBlend, light[F("pal-mode")]);
float light_gc_bri = light["gc"]["bri"];
float light_gc_col = light["gc"]["col"]; // 2.8
float light_gc_bri = light[F("gc")]["bri"];
float light_gc_col = light[F("gc")][F("col")]; // 2.8
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;
JsonObject light_tr = light["tr"];
CJSON(fadeTransition, light_tr["mode"]);
int tdd = light_tr["dur"] | -1;
JsonObject light_tr = light[F("tr")];
CJSON(fadeTransition, light_tr[F("mode")]);
int tdd = light_tr[F("dur")] | -1;
if (tdd >= 0) transitionDelayDefault = tdd * 100;
CJSON(strip.paletteFade, light_tr["pal"]);
CJSON(strip.paletteFade, light_tr[F("pal")]);
JsonObject light_nl = light["nl"];
CJSON(nightlightMode, light_nl["mode"]);
CJSON(nightlightDelayMinsDefault, light_nl["dur"]);
CJSON(nightlightMode, light_nl[F("mode")]);
CJSON(nightlightDelayMinsDefault, light_nl[F("dur")]);
nightlightDelayMins = nightlightDelayMinsDefault;
CJSON(nightlightTargetBri, light_nl["tbri"]);
CJSON(macroNl, light_nl["macro"]);
CJSON(nightlightTargetBri, light_nl[F("tbri")]);
CJSON(macroNl, light_nl[F("macro")]);
JsonObject def = doc["def"];
CJSON(bootPreset, def["ps"]);
JsonObject def = doc[F("def")];
CJSON(bootPreset, def[F("ps")]);
CJSON(turnOnAtBoot, def["on"]); // true
CJSON(briS, def["bri"]); // 128
if (briS == 0) briS = 255;
JsonObject def_cy = def["cy"];
JsonObject def_cy = def[F("cy")];
CJSON(presetCyclingEnabled, def_cy["on"]);
CJSON(presetCycleMin, def_cy["range"][0]);
CJSON(presetCycleMax, def_cy["range"][1]);
CJSON(presetCycleMin, def_cy[F("range")][0]);
CJSON(presetCycleMax, def_cy[F("range")][1]);
tdd = def_cy["dur"] | -1;
tdd = def_cy[F("dur")] | -1;
if (tdd >= 0) presetCycleTime = tdd * 100;
JsonObject interfaces = doc["if"];
JsonObject if_sync = interfaces["sync"];
CJSON(udpPort, if_sync["port0"]); // 21324
CJSON(udpPort2, if_sync["port1"]); // 65506
JsonObject if_sync = interfaces[F("sync")];
CJSON(udpPort, if_sync[F("port0")]); // 21324
CJSON(udpPort2, if_sync[F("port1")]); // 65506
JsonObject if_sync_recv = if_sync["recv"];
JsonObject if_sync_recv = if_sync[F("recv")];
CJSON(receiveNotificationBrightness, if_sync_recv["bri"]);
CJSON(receiveNotificationColor, if_sync_recv["col"]);
CJSON(receiveNotificationEffects, if_sync_recv["fx"]);
CJSON(receiveNotificationColor, if_sync_recv[F("col")]);
CJSON(receiveNotificationEffects, if_sync_recv[F("fx")]);
receiveNotifications = (receiveNotificationBrightness || receiveNotificationColor || receiveNotificationEffects);
JsonObject if_sync_send = if_sync["send"];
CJSON(notifyDirectDefault, if_sync_send["dir"]);
JsonObject if_sync_send = if_sync[F("send")];
CJSON(notifyDirectDefault, if_sync_send[F("dir")]);
notifyDirect = notifyDirectDefault;
CJSON(notifyButton, if_sync_send["btn"]);
CJSON(notifyAlexa, if_sync_send["va"]);
CJSON(notifyHue, if_sync_send["hue"]);
CJSON(notifyMacro, if_sync_send["macro"]);
CJSON(notifyTwice, if_sync_send["twice"]);
CJSON(notifyButton, if_sync_send[F("btn")]);
CJSON(notifyAlexa, if_sync_send[F("va")]);
CJSON(notifyHue, if_sync_send[F("hue")]);
CJSON(notifyMacro, if_sync_send[F("macro")]);
CJSON(notifyTwice, if_sync_send[F("twice")]);
JsonObject if_realtime = interfaces["realtime"];
CJSON(receiveDirect, if_realtime["en"]);
CJSON(e131Port, if_realtime["port"]); // 5568
CJSON(e131Multicast, if_realtime["mc"]);
JsonObject if_live = interfaces[F("live")];
CJSON(receiveDirect, if_live[F("en")]);
CJSON(e131Port, if_live[F("port")]); // 5568
CJSON(e131Multicast, if_live[F("mc")]);
JsonObject if_realtime_dmx = if_realtime["dmx"];
CJSON(e131Universe, if_realtime_dmx["uni"]);
CJSON(e131SkipOutOfSequence, if_realtime_dmx["seqskip"]);
CJSON(DMXAddress, if_realtime_dmx["addr"]);
CJSON(DMXMode, if_realtime_dmx["mode"]);
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")]);
CJSON(DMXMode, if_live_dmx[F("mode")]);
tdd = if_realtime["timeout"] | -1;
tdd = if_live[F("timeout")] | -1;
if (tdd >= 0) realtimeTimeoutMs = tdd * 100;
CJSON(arlsForceMaxBri, if_realtime["maxbri"]);
CJSON(arlsDisableGammaCorrection, if_realtime["no-gc"]); // false
CJSON(arlsOffset, if_realtime["offset"]); // 0
CJSON(arlsForceMaxBri, if_live[F("maxbri")]);
CJSON(arlsDisableGammaCorrection, if_live[F("no-gc")]); // false
CJSON(arlsOffset, if_live[F("offset")]); // 0
CJSON(alexaEnabled, interfaces["va"]["alexa"]); // false
CJSON(alexaEnabled, interfaces[F("va")][F("alexa")]); // false
CJSON(macroAlexaOn, interfaces["va"]["macros"][0]);
CJSON(macroAlexaOff, interfaces["va"]["macros"][1]);
CJSON(macroAlexaOn, interfaces[F("va")][F("macros")][0]);
CJSON(macroAlexaOff, interfaces[F("va")][F("macros")][1]);
const char* apikey = interfaces["blynk"]["token"] | "Hidden";
const char* apikey = interfaces[F("blynk")][F("token")] | "Hidden";
tdd = strnlen(apikey, 36);
if (tdd > 20 || tdd == 0)
getStringFromJson(blynkApiKey, apikey, 36); //normally not present due to security
JsonObject if_mqtt = interfaces["mqtt"];
CJSON(mqttEnabled, if_mqtt["en"]);
getStringFromJson(mqttServer, if_mqtt["broker"], 33);
CJSON(mqttPort, if_mqtt["port"]); // 1883
getStringFromJson(mqttUser, if_mqtt["user"], 41);
JsonObject if_mqtt = interfaces[F("mqtt")];
CJSON(mqttEnabled, if_mqtt[F("en")]);
getStringFromJson(mqttServer, if_mqtt[F("broker")], 33);
CJSON(mqttPort, if_mqtt[F("port")]); // 1883
getStringFromJson(mqttUser, if_mqtt[F("user")], 41);
getStringFromJson(mqttPass, if_mqtt["psk"], 41); //normally not present due to security
getStringFromJson(mqttClientID, if_mqtt["cid"], 41);
getStringFromJson(mqttClientID, if_mqtt[F("cid")], 41);
getStringFromJson(mqttDeviceTopic, if_mqtt["topics"]["device"], 33); // "wled/test"
getStringFromJson(mqttGroupTopic, if_mqtt["topics"]["group"], 33); // ""
getStringFromJson(mqttDeviceTopic, if_mqtt[F("topics")][F("device")], 33); // "wled/test"
getStringFromJson(mqttGroupTopic, if_mqtt[F("topics")][F("group")], 33); // ""
JsonObject if_hue = interfaces["hue"];
CJSON(huePollingEnabled, if_hue["en"]);
CJSON(huePollLightId, if_hue["id"]);
tdd = if_hue["iv"] | -1;
JsonObject if_hue = interfaces[F("hue")];
CJSON(huePollingEnabled, if_hue[F("en")]);
CJSON(huePollLightId, if_hue[F("id")]);
tdd = if_hue[F("iv")] | -1;
if (tdd >= 2) huePollIntervalMs = tdd * 100;
JsonObject if_hue_recv = if_hue["recv"];
JsonObject if_hue_recv = if_hue[F("recv")];
CJSON(hueApplyOnOff, if_hue_recv["on"]);
CJSON(hueApplyBri, if_hue_recv["bri"]);
CJSON(hueApplyColor, if_hue_recv["col"]);
CJSON(hueApplyColor, if_hue_recv[F("col")]);
JsonArray if_hue_ip = if_hue["ip"];
JsonArray if_hue_ip = if_hue[F("ip")];
for (byte i = 0; i < 4; i++)
CJSON(hueIP[i], if_hue_ip[i]);
JsonObject if_ntp = interfaces["ntp"];
CJSON(ntpEnabled, if_ntp["en"]);
getStringFromJson(ntpServerName, if_ntp["host"], 33); // "1.wled.pool.ntp.org"
CJSON(currentTimezone, if_ntp["tz"]);
CJSON(utcOffsetSecs, if_ntp["offset"]);
CJSON(useAMPM, if_ntp["ampm"]);
JsonObject if_ntp = interfaces[F("ntp")];
CJSON(ntpEnabled, if_ntp[F("en")]);
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")]);
JsonObject ol = doc["ol"];
CJSON(overlayDefault ,ol["clock"]); // 0
CJSON(countdownMode, ol["cntdwn"]);
JsonObject ol = doc[F("ol")];
CJSON(overlayDefault ,ol[F("clock")]); // 0
CJSON(countdownMode, ol[F("cntdwn")]);
overlayCurrent = overlayDefault;
JsonArray ol_cntdwn = ol["cntdwn"]; //[20,12,31,23,59,59]
JsonArray ol_cntdwn = ol[F("cntdwn")]; //[20,12,31,23,59,59]
//timed macro rules
JsonObject tm = doc["timers"];
JsonObject cntdwn = tm["cntdwn"];
JsonArray cntdwn_goal = cntdwn["goal"];
JsonObject tm = doc[F("timers")];
JsonObject cntdwn = tm[F("cntdwn")];
JsonArray cntdwn_goal = cntdwn[F("goal")];
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]);
CJSON(macroCountdown, cntdwn["macro"]);
CJSON(macroCountdown, cntdwn[F("macro")]);
JsonArray timers = tm["ins"];
JsonArray timers = tm[F("ins")];
uint8_t it = 0;
for (JsonObject timer : timers) {
if (it > 7) break;
CJSON(timerHours[it], timer["hour"]);
CJSON(timerMinutes[it], timer["min"]);
CJSON(timerMacro[it], timer["macro"]);
CJSON(timerHours[it], timer[F("hour")]);
CJSON(timerMinutes[it], timer[F("min")]);
CJSON(timerMacro[it], timer[F("macro")]);
byte dowPrev = timerWeekday[it];
bool actPrev = timerWeekday[it] & 0x01;
CJSON(timerWeekday[it], timer["dow"]);
CJSON(timerWeekday[it], timer[F("dow")]);
if (timerWeekday[it] != dowPrev) { //present in JSON
timerWeekday[it] <<= 1; //add active bit
bool act = timer["en"] | actPrev;
bool act = timer[F("en")] | actPrev;
if (act) timerWeekday[it]++;
}
@ -292,9 +292,9 @@ void deserializeConfig() {
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)
CJSON(otaLock, ota["lock"]);
CJSON(wifiLock, ota["lock-wifi"]);
CJSON(aOtaEnabled, ota["aota"]);
CJSON(otaLock, ota[F("lock")]);
CJSON(wifiLock, ota[F("lock-wifi")]);
CJSON(aOtaEnabled, ota[F("aota")]);
getStringFromJson(otaPass, pwd, 33); //normally not present due to security
}
@ -302,6 +302,8 @@ void deserializeConfig() {
}
void serializeConfig() {
serializeConfigSec();
DEBUG_PRINTLN(F("Writing settings to /cfg.json..."));
DynamicJsonDocument doc(JSON_BUFFER_SIZE);
@ -311,20 +313,20 @@ void serializeConfig() {
rev.add(1); //major settings revision
rev.add(0); //minor settings revision
doc["vid"] = VERSION;
doc[F("vid")] = VERSION;
JsonObject id = doc.createNestedObject("id");
id["mdns"] = cmDNS;
id["name"] = serverDescription;
id["inv"] = alexaInvocationName;
id[F("mdns")] = cmDNS;
id[F("name")] = serverDescription;
id[F("inv")] = alexaInvocationName;
JsonObject nw = doc.createNestedObject("nw");
JsonArray nw_ins = nw.createNestedArray("ins");
JsonObject nw_ins_0 = nw_ins.createNestedObject();
nw_ins_0["ssid"] = clientSSID;
nw_ins_0["pskl"] = strlen(clientPass);
nw_ins_0[F("ssid")] = clientSSID;
nw_ins_0[F("pskl")] = strlen(clientPass);
JsonArray nw_ins_0_ip = nw_ins_0.createNestedArray("ip");
JsonArray nw_ins_0_gw = nw_ins_0.createNestedArray("gw");
@ -337,10 +339,10 @@ void serializeConfig() {
}
JsonObject ap = doc.createNestedObject("ap");
ap["ssid"] = apSSID;
ap["pskl"] = strlen(apPass);
ap["chan"] = apChannel;
ap["behav"] = apBehavior;
ap[F("ssid")] = apSSID;
ap[F("pskl")] = strlen(apPass);
ap[F("chan")] = apChannel;
ap[F("behav")] = apBehavior;
JsonArray ap_ip = ap.createNestedArray("ip");
ap_ip.add(4);
@ -349,31 +351,31 @@ void serializeConfig() {
ap_ip.add(1);
JsonObject wifi = doc.createNestedObject("wifi");
wifi["sleep"] = !noWifiSleep;
wifi["phy"] = 1;
wifi[F("sleep")] = !noWifiSleep;
wifi[F("phy")] = 1;
JsonObject hw = doc.createNestedObject("hw");
JsonObject hw_led = hw.createNestedObject("led");
hw_led["total"] = ledCount;
hw_led["maxpwr"] = strip.ablMilliampsMax;
hw_led["ledma"] = strip.milliampsPerLed;
hw_led["rev"] = strip.reverseMode;
hw_led[F("total")] = ledCount;
hw_led[F("maxpwr")] = strip.ablMilliampsMax;
hw_led[F("ledma")] = strip.milliampsPerLed;
hw_led[F("rev")] = strip.reverseMode;
JsonArray hw_led_ins = hw_led.createNestedArray("ins");
JsonObject hw_led_ins_0 = hw_led_ins.createNestedObject();
hw_led_ins_0["en"] = true;
hw_led_ins_0["start"] = 0;
hw_led_ins_0["len"] = ledCount;
hw_led_ins_0[F("en")] = true;
hw_led_ins_0[F("start")] = 0;
hw_led_ins_0[F("len")] = ledCount;
JsonArray hw_led_ins_0_pin = hw_led_ins_0.createNestedArray("pin");
hw_led_ins_0_pin.add(LEDPIN);
#ifdef DATAPIN
hw_led_ins_0_pin.add(DATAPIN);
#endif
hw_led_ins_0["order"] = strip.colorOrder; //color order
hw_led_ins_0["rev"] = false;
hw_led_ins_0["skip"] = skipFirstLed ? 1 : 0;
hw_led_ins_0[F("order")] = strip.colorOrder; //color order
hw_led_ins_0[F("rev")] = false;
hw_led_ins_0[F("skip")] = skipFirstLed ? 1 : 0;
//this is very crude and temporary
byte ledType = TYPE_WS2812_RGB;
@ -394,14 +396,14 @@ void serializeConfig() {
ledType = TYPE_TM1814;
#endif
hw_led_ins_0["type"] = ledType;
hw_led_ins_0[F("type")] = ledType;
JsonObject hw_btn = hw.createNestedObject("btn");
JsonArray hw_btn_ins = hw_btn.createNestedArray("ins");
JsonObject hw_btn_ins_0 = hw_btn_ins.createNestedObject();
hw_btn_ins_0["type"] = (buttonEnabled) ? BTN_TYPE_PUSH : BTN_TYPE_NONE;
hw_btn_ins_0[F("type")] = (buttonEnabled) ? BTN_TYPE_PUSH : BTN_TYPE_NONE;
JsonArray hw_btn_ins_0_pin = hw_btn_ins_0.createNestedArray("pin");
hw_btn_ins_0_pin.add(BTNPIN);
@ -412,36 +414,36 @@ void serializeConfig() {
hw_btn_ins_0_macros.add(macroDoublePress);
JsonObject hw_ir = hw.createNestedObject("ir");
hw_ir["pin"] = IR_PIN;
hw_ir["type"] = 0;
hw_ir[F("pin")] = IR_PIN;
hw_ir[F("type")] = 0;
JsonObject hw_relay = hw.createNestedObject("relay");
hw_relay["pin"] = RLYPIN;
hw_relay["rev"] = (RLYMDE) ? false : true;
hw_relay[F("pin")] = RLYPIN;
hw_relay[F("rev")] = (RLYMDE) ? false : true;
JsonObject hw_status = hw.createNestedObject("status");
hw_status["pin"] = -1;
hw_status[F("pin")] = -1;
JsonObject light = doc.createNestedObject("light");
light["scale-bri"] = briMultiplier;
light["pal-mode"] = strip.paletteBlend;
light[F("scale-bri")] = briMultiplier;
light[F("pal-mode")] = strip.paletteBlend;
JsonObject light_gc = light.createNestedObject("gc");
light_gc["bri"] = (strip.gammaCorrectBri) ? 2.8 : 1.0;
light_gc["col"] = (strip.gammaCorrectCol) ? 2.8 : 1.0;
light_gc[F("col")] = (strip.gammaCorrectCol) ? 2.8 : 1.0;
JsonObject light_tr = light.createNestedObject("tr");
light_tr["mode"] = fadeTransition;
light_tr["dur"] = transitionDelayDefault / 100;
light_tr["pal"] = strip.paletteFade;
light_tr[F("mode")] = fadeTransition;
light_tr[F("dur")] = transitionDelayDefault / 100;
light_tr[F("pal")] = strip.paletteFade;
JsonObject light_nl = light.createNestedObject("nl");
light_nl["mode"] = nightlightMode;
light_nl["dur"] = nightlightDelayMinsDefault;
light_nl["tbri"] = nightlightTargetBri;
light_nl["macro"] = macroNl;
light_nl[F("mode")] = nightlightMode;
light_nl[F("dur")] = nightlightDelayMinsDefault;
light_nl[F("tbri")] = nightlightTargetBri;
light_nl[F("macro")] = macroNl;
JsonObject def = doc.createNestedObject("def");
def["ps"] = bootPreset;
def[F("ps")] = bootPreset;
def["on"] = turnOnAtBoot;
def["bri"] = briS;
@ -453,73 +455,73 @@ void serializeConfig() {
JsonArray def_cy_range = def_cy.createNestedArray("range");
def_cy_range.add(presetCycleMin);
def_cy_range.add(presetCycleMax);
def_cy["dur"] = presetCycleTime / 100;
def_cy[F("dur")] = presetCycleTime / 100;
}
JsonObject interfaces = doc.createNestedObject("if");
JsonObject if_sync = interfaces.createNestedObject("sync");
if_sync["port0"] = udpPort;
if_sync["port1"] = udpPort2;
if_sync[F("port0")] = udpPort;
if_sync[F("port1")] = udpPort2;
JsonObject if_sync_recv = if_sync.createNestedObject("recv");
if_sync_recv["bri"] = receiveNotificationBrightness;
if_sync_recv["col"] = receiveNotificationColor;
if_sync_recv["fx"] = receiveNotificationEffects;
if_sync_recv[F("col")] = receiveNotificationColor;
if_sync_recv[F("fx")] = receiveNotificationEffects;
JsonObject if_sync_send = if_sync.createNestedObject("send");
if_sync_send["dir"] = notifyDirect;
if_sync_send["btn"] = notifyButton;
if_sync_send["va"] = notifyAlexa;
if_sync_send["hue"] = notifyHue;
if_sync_send["macro"] = notifyMacro;
if_sync_send["twice"] = notifyTwice;
if_sync_send[F("dir")] = notifyDirect;
if_sync_send[F("btn")] = notifyButton;
if_sync_send[F("va")] = notifyAlexa;
if_sync_send[F("hue")] = notifyHue;
if_sync_send[F("macro")] = notifyMacro;
if_sync_send[F("twice")] = notifyTwice;
JsonObject if_realtime = interfaces.createNestedObject("realtime");
if_realtime["en"] = receiveDirect;
if_realtime["port"] = e131Port;
if_realtime["mc"] = e131Multicast;
JsonObject if_live = interfaces.createNestedObject("live");
if_live[F("en")] = receiveDirect;
if_live[F("port")] = e131Port;
if_live[F("mc")] = e131Multicast;
JsonObject if_realtime_dmx = if_realtime.createNestedObject("dmx");
if_realtime_dmx["uni"] = e131Universe;
if_realtime_dmx["seqskip"] = e131SkipOutOfSequence;
if_realtime_dmx["addr"] = DMXAddress;
if_realtime_dmx["mode"] = DMXMode;
if_realtime["timeout"] = realtimeTimeout / 100;
if_realtime["maxbri"] = arlsForceMaxBri;
if_realtime["no-gc"] = arlsDisableGammaCorrection;
if_realtime["offset"] = arlsOffset;
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;
if_live_dmx[F("mode")] = DMXMode;
if_live[F("timeout")] = realtimeTimeoutMs / 100;
if_live[F("maxbri")] = arlsForceMaxBri;
if_live[F("no-gc")] = arlsDisableGammaCorrection;
if_live[F("offset")] = arlsOffset;
JsonObject if_va = interfaces.createNestedObject("va");
if_va["alexa"] = alexaEnabled;
if_va[F("alexa")] = alexaEnabled;
JsonArray if_va_macros = if_va.createNestedArray("macros");
if_va_macros.add(macroAlexaOn);
if_va_macros.add(macroAlexaOff);
JsonObject if_blynk = interfaces.createNestedObject("blynk");
if_blynk["token"] = strlen(blynkApiKey) ? "Hidden":"";
if_blynk[F("token")] = strlen(blynkApiKey) ? "Hidden":"";
JsonObject if_mqtt = interfaces.createNestedObject("mqtt");
if_mqtt["en"] = mqttEnabled;
if_mqtt["broker"] = mqttServer;
if_mqtt["port"] = mqttPort;
if_mqtt["user"] = mqttUser;
if_mqtt["pskl"] = strlen(mqttPass);
if_mqtt["cid"] = mqttClientID;
if_mqtt[F("en")] = mqttEnabled;
if_mqtt[F("broker")] = mqttServer;
if_mqtt[F("port")] = mqttPort;
if_mqtt[F("user")] = mqttUser;
if_mqtt[F("pskl")] = strlen(mqttPass);
if_mqtt[F("cid")] = mqttClientID;
JsonObject if_mqtt_topics = if_mqtt.createNestedObject("topics");
if_mqtt_topics["device"] = mqttDeviceTopic;
if_mqtt_topics["group"] = mqttGroupTopic;
if_mqtt_topics[F("device")] = mqttDeviceTopic;
if_mqtt_topics[F("group")] = mqttGroupTopic;
JsonObject if_hue = interfaces.createNestedObject("hue");
if_hue["en"] = huePollingEnabled;
if_hue["id"] = huePollLightId;
if_hue["iv"] = huePollIntervalMs / 100;
if_hue[F("en")] = huePollingEnabled;
if_hue[F("id")] = huePollLightId;
if_hue[F("iv")] = huePollIntervalMs / 100;
JsonObject if_hue_recv = if_hue.createNestedObject("recv");
if_hue_recv["on"] = hueApplyOnOff;
if_hue_recv["bri"] = hueApplyBri;
if_hue_recv["col"] = hueApplyColor;
if_hue_recv[F("col")] = hueApplyColor;
JsonArray if_hue_ip = if_hue.createNestedArray("ip");
for (byte i = 0; i < 4; i++) {
@ -527,15 +529,15 @@ void serializeConfig() {
}
JsonObject if_ntp = interfaces.createNestedObject("ntp");
if_ntp["en"] = ntpEnabled;
if_ntp["host"] = ntpServerName;
if_ntp["tz"] = currentTimezone;
if_ntp["offset"] = utcOffsetSecs;
if_ntp["ampm"] = useAMPM;
if_ntp[F("en")] = ntpEnabled;
if_ntp[F("host")] = ntpServerName;
if_ntp[F("tz")] = currentTimezone;
if_ntp[F("offset")] = utcOffsetSecs;
if_ntp[F("ampm")] = useAMPM;
JsonObject ol = doc.createNestedObject("ol");
ol["clock"] = overlayDefault;
ol["cntdwn"] = countdownMode;
ol[F("clock")] = overlayDefault;
ol[F("cntdwn")] = countdownMode;
JsonObject timers = doc.createNestedObject("timers");
@ -543,25 +545,25 @@ void serializeConfig() {
JsonArray goal = cntdwn.createNestedArray("goal");
goal.add(countdownYear); goal.add(countdownMonth); goal.add(countdownDay);
goal.add(countdownHour); goal.add(countdownMin); goal.add(countdownSec);
cntdwn["macro"] = macroCountdown;
cntdwn[F("macro")] = macroCountdown;
JsonArray timers_ins = timers.createNestedArray("ins");
for (byte i = 0; i < 8; i++) {
if (timerMacro[i] == 0 && !(timerWeekday[i] & 0x01)) continue;
if (timerMacro[i] == 0 && timerHours[i] == 0 && timerMinutes[i] == 0) continue;
JsonObject timers_ins0 = timers_ins.createNestedObject();
timers_ins0["en"] = (timerWeekday[i] & 0x01);
timers_ins0["hour"] = timerHours[i];
timers_ins0["min"] = timerMinutes[i];
timers_ins0["macro"] = timerMacro[i];
timers_ins0["dow"] = timerWeekday[i] >> 1;
timers_ins0[F("en")] = (timerWeekday[i] & 0x01);
timers_ins0[F("hour")] = timerHours[i];
timers_ins0[F("min")] = timerMinutes[i];
timers_ins0[F("macro")] = timerMacro[i];
timers_ins0[F("dow")] = timerWeekday[i] >> 1;
}
JsonObject ota = doc.createNestedObject("ota");
ota["lock"] = otaLock;
ota["lock-wifi"] = wifiLock;
ota["pskl"] = strlen(otaPass);
ota["aota"] = aOtaEnabled;
ota[F("lock")] = otaLock;
ota[F("lock-wifi")] = wifiLock;
ota[F("pskl")] = strlen(otaPass);
ota[F("aota")] = aOtaEnabled;
//}
File f = WLED_FS.open("/cfg.json", "w");
@ -578,29 +580,29 @@ bool deserializeConfigSec() {
bool success = readObjectFromFile("/wsec.json", nullptr, &doc);
if (!success) return false;
JsonObject nw_ins_0 = doc["nw"]["ins"][0];
JsonObject nw_ins_0 = doc["nw"][F("ins")][0];
getStringFromJson(clientPass, nw_ins_0["psk"], 65);
JsonObject ap = doc["ap"];
JsonObject ap = doc[F("ap")];
getStringFromJson(apPass, ap["psk"] , 65);
JsonObject interfaces = doc["if"];
const char* apikey = interfaces["blynk"]["token"] | "Hidden";
const char* apikey = interfaces["blynk"][F("token")] | "Hidden";
int tdd = strnlen(apikey, 36);
if (tdd > 20 || tdd == 0)
getStringFromJson(blynkApiKey, apikey, 36);
JsonObject if_mqtt = interfaces["mqtt"];
JsonObject if_mqtt = interfaces[F("mqtt")];
getStringFromJson(mqttPass, if_mqtt["psk"], 41);
getStringFromJson(hueApiKey, interfaces["hue"]["key"], 47);
getStringFromJson(hueApiKey, interfaces[F("hue")][F("key")], 47);
JsonObject ota = doc["ota"];
getStringFromJson(otaPass, ota["pwd"], 33);
CJSON(otaLock, ota["lock"]);
CJSON(wifiLock, ota["lock-wifi"]);
CJSON(aOtaEnabled, ota["aota"]);
getStringFromJson(otaPass, ota[F("pwd")], 33);
CJSON(otaLock, ota[F("lock")]);
CJSON(wifiLock, ota[F("lock-wifi")]);
CJSON(aOtaEnabled, ota[F("aota")]);
return true;
}
@ -622,17 +624,17 @@ void serializeConfigSec() {
JsonObject interfaces = doc.createNestedObject("if");
JsonObject if_blynk = interfaces.createNestedObject("blynk");
if_blynk["token"] = blynkApiKey;
if_blynk[F("token")] = blynkApiKey;
JsonObject if_mqtt = interfaces.createNestedObject("mqtt");
if_mqtt["psk"] = mqttPass;
JsonObject if_hue = interfaces.createNestedObject("hue");
if_hue["key"] = hueApiKey;
if_hue[F("key")] = hueApiKey;
JsonObject ota = doc.createNestedObject("ota");
ota["pwd"] = otaPass;
ota["lock"] = otaLock;
ota["lock-wifi"] = wifiLock;
ota["aota"] = aOtaEnabled;
ota[F("pwd")] = otaPass;
ota[F("lock")] = otaLock;
ota[F("lock-wifi")] = wifiLock;
ota[F("aota")] = aOtaEnabled;
File f = WLED_FS.open("/wsec.json", "w");
if (f) serializeJson(doc, f);

View File

@ -43,7 +43,7 @@
}
function BTa()
{
var ih="<tr><th>Active</th><th>Hour</th><th>Minute</th><th>Macro</th><th>M</th><th>T</th><th>W</th><th>T</th><th>F</th><th>S</th><th>S</th></tr>";
var ih="<tr><th>Active</th><th>Hour</th><th>Minute</th><th>Preset</th><th>M</th><th>T</th><th>W</th><th>T</th><th>F</th><th>S</th><th>S</th></tr>";
for (i=0;i<8;i++)
{
ih+="<tr><td><input name=\"W"+i+"\" id=\"W"+i+"\" type=\"number\" style=\"display:none\"><input id=\"W"+i+"0\" type=\"checkbox\"></td><td><input name=\"H"+i+"\" type=\"number\" min=\"0\" max=\"24\"></td><td><input name=\"N"+i+"\" type=\"number\" min=\"0\" max=\"59\"></td><td><input name=\"T"+i+"\" type=\"number\" min=\"0\" max=\"16\"></td>";
@ -134,32 +134,17 @@
Countdown Goal:<br>
Year: 20 <input name="CY" type="number" min="0" max="99" required> Month: <input name="CI" type="number" min="1" max="12" required> Day: <input name="CD" type="number" min="1" max="31" required><br>
Hour: <input name="CH" type="number" min="0" max="23" required> Minute: <input name="CM" type="number" min="0" max="59" required> Second: <input name="CS" type="number" min="0" max="59" required><br>
<h3>Advanced Macros</h3>
Define API macros here:<br>
1: <input name="M1" maxlength="64"><br>
2: <input name="M2" maxlength="64"><br>
3: <input name="M3" maxlength="64"><br>
4: <input name="M4" maxlength="64"><br>
5: <input name="M5" maxlength="64"><br>
6: <input name="M6" maxlength="64"><br>
7: <input name="M7" maxlength="64"><br>
8: <input name="M8" maxlength="64"><br>
9: <input name="M9" maxlength="64"><br>
10: <input name="M10" maxlength="64"><br>
11: <input name="M11" maxlength="64"><br>
12: <input name="M12" maxlength="64"><br>
13: <input name="M13" maxlength="64"><br>
14: <input name="M14" maxlength="64"><br>
15: <input name="M15" maxlength="64"><br>
16: <input name="M16" maxlength="64"><br><br>
<i>Use 0 for the default action instead of a macro</i><br>
Boot Macro: <input name="MB" type="number" min="0" max="16" required><br>
Alexa On/Off Macros: <input name="A0" type="number" min="0" max="16" required> <input name="A1" type="number" min="0" max="16" required><br>
Button short press macro: Macro: <input name="MP" type="number" min="0" max="16" required><br>
<h3>Macro presets</h3>
<b>Macros have moved!</b><br>
<i>Presets now also can be used as macros to save both JSON and HTTP API commands.<br>
Just enter the preset id below!</i>
<i>Use 0 for the default action instead of a preset</i><br>
Alexa On/Off Preset: <input name="A0" type="number" min="0" max="16" required> <input name="A1" type="number" min="0" max="16" required><br>
Button short press Preset: Macro: <input name="MP" type="number" min="0" max="16" required><br>
Long Press: <input name="ML" type="number" min="0" max="16" required> Double press: <input name="MD" type="number" min="0" max="16" required><br>
Countdown-Over Macro: <input name="MC" type="number" min="0" max="16" required><br>
Timed-Light-Over Macro: <input name="MN" type="number" min="0" max="16" required><br>
Time-Controlled Macros:<br>
Countdown-Over Preset: <input name="MC" type="number" min="0" max="16" required><br>
Timed-Light-Over Presets: <input name="MN" type="number" min="0" max="16" required><br>
<h3>Time-controlled presets</h3>
<div style="display: inline-block">
<table id="TMT">
</table></div><hr>

View File

@ -176,7 +176,7 @@ bool deserializeState(JsonObject root)
tr = ccnf[F("time")] | -1;
if (tr >= 2) presetCycleTime = tr;
JsonObject nl = root[F("nl")];
JsonObject nl = root["nl"];
nightlightActive = nl["on"] | nightlightActive;
nightlightDelayMins = nl[F("dur")] | nightlightDelayMins;
nightlightMode = nl[F("fade")] | nightlightMode; //deprecated

View File

@ -298,7 +298,6 @@ WLED_GLOBAL byte countdownYear _INIT(20), countdownMonth _INIT(1); // Countdow
WLED_GLOBAL byte countdownDay _INIT(1) , countdownHour _INIT(0);
WLED_GLOBAL byte countdownMin _INIT(0) , countdownSec _INIT(0);
WLED_GLOBAL byte macroBoot _INIT(0); // macro loaded after startup
WLED_GLOBAL byte macroNl _INIT(0); // after nightlight delay over
WLED_GLOBAL byte macroCountdown _INIT(0);
WLED_GLOBAL byte macroAlexaOn _INIT(0), macroAlexaOff _INIT(0);

View File

@ -178,7 +178,7 @@ void loadSettingsFromEEPROM()
readStringFromEEPROM(2165, cronixieDisplay, 6);
cronixieBacklight = EEPROM.read(2171);
macroBoot = EEPROM.read(2175);
//macroBoot = EEPROM.read(2175);
macroAlexaOn = EEPROM.read(2176);
macroAlexaOff = EEPROM.read(2177);
macroButton = EEPROM.read(2178);
@ -208,8 +208,9 @@ void loadSettingsFromEEPROM()
timerHours[i] = EEPROM.read(2260 + i);
timerMinutes[i] = EEPROM.read(2270 + i);
timerWeekday[i] = EEPROM.read(2280 + i);
timerMacro[i] = EEPROM.read(2290 + i);
timerMacro[i] = EEPROM.read(2290 + i) + 16; //add 16 to work with macro --> preset mapping
if (timerWeekday[i] == 0) timerWeekday[i] = 255;
if (timerMacro[i] == 0) timerWeekday[i] = timerWeekday[i] & 0b11111110;
}
}
@ -432,7 +433,7 @@ void deEEP() {
char nbuf[16];
sprintf(nbuf, "%d", index + 16);
JsonObject pObj = sObj.createNestedObject(nbuf);
sprintf_P(nbuf, "ZMacro %d", index);
sprintf_P(nbuf, "Z Macro %d", index);
pObj["n"] = nbuf;
pObj["win"] = m;
}