2020-11-04 10:04:40 +00:00
# include "wled.h"
2021-07-07 06:12:03 +00:00
# include "wled_ethernet.h"
2020-11-04 10:04:40 +00: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-10 23:11:16 +00:00
bool deserializeConfig ( JsonObject doc , bool fromFS ) {
2021-11-03 13:52:22 +00:00
bool needsSave = false ;
2021-03-04 11:10:18 +00:00
//int rev_major = doc["rev"][0]; // 1
//int rev_minor = doc["rev"][1]; // 0
2020-11-04 10:04:40 +00:00
2020-11-07 22:54:56 +00:00
//long vid = doc[F("vid")]; // 2010020
2020-11-04 10:04:40 +00:00
2024-08-17 13:09:41 +00:00
# ifdef WLED_USE_ETHERNET
2021-08-23 12:14:48 +00:00
JsonObject ethernet = doc [ F ( " eth " ) ] ;
CJSON ( ethernetType , ethernet [ " type " ] ) ;
// NOTE: Ethernet configuration takes priority over other use of pins
WLED : : instance ( ) . initEthernet ( ) ;
2024-08-17 13:09:41 +00:00
# endif
2021-08-23 12:14:48 +00:00
2021-03-13 21:04:37 +00:00
JsonObject id = doc [ " id " ] ;
2020-11-07 22:54:56 +00:00
getStringFromJson ( cmDNS , id [ F ( " mdns " ) ] , 33 ) ;
getStringFromJson ( serverDescription , id [ F ( " name " ) ] , 33 ) ;
2024-08-17 13:09:41 +00:00
# ifndef WLED_DISABLE_ALEXA
2020-11-07 22:54:56 +00:00
getStringFromJson ( alexaInvocationName , id [ F ( " inv " ) ] , 33 ) ;
2024-08-17 13:09:41 +00:00
# endif
2021-08-10 15:11:17 +00:00
CJSON ( simplifiedUI , id [ F ( " sui " ) ] ) ;
2020-11-04 10:04:40 +00:00
2023-09-10 16:52:14 +00:00
JsonObject nw = doc [ " nw " ] ;
# ifndef WLED_DISABLE_ESPNOW
CJSON ( enableESPNow , nw [ F ( " espnow " ) ] ) ;
getStringFromJson ( linked_remote , nw [ F ( " linked_remote " ) ] , 13 ) ;
linked_remote [ 12 ] = ' \0 ' ;
# endif
2024-01-20 23:30:15 +00:00
size_t n = 0 ;
JsonArray nw_ins = nw [ " ins " ] ;
if ( ! nw_ins . isNull ( ) ) {
// as password are stored separately in wsec.json when reading configuration vector resize happens there, but for dynamic config we need to resize if necessary
if ( nw_ins . size ( ) > 1 & & nw_ins . size ( ) > multiWiFi . size ( ) ) multiWiFi . resize ( nw_ins . size ( ) ) ; // resize constructs objects while resizing
for ( JsonObject wifi : nw_ins ) {
JsonArray ip = wifi [ " ip " ] ;
JsonArray gw = wifi [ " gw " ] ;
JsonArray sn = wifi [ " sn " ] ;
char ssid [ 33 ] = " " ;
char pass [ 65 ] = " " ;
IPAddress nIP = ( uint32_t ) 0U , nGW = ( uint32_t ) 0U , nSN = ( uint32_t ) 0x00FFFFFF ; // little endian
getStringFromJson ( ssid , wifi [ F ( " ssid " ) ] , 33 ) ;
getStringFromJson ( pass , wifi [ " psk " ] , 65 ) ; // password is not normally present but if it is, use it
for ( size_t i = 0 ; i < 4 ; i + + ) {
CJSON ( nIP [ i ] , ip [ i ] ) ;
CJSON ( nGW [ i ] , gw [ i ] ) ;
CJSON ( nSN [ i ] , sn [ i ] ) ;
}
if ( strlen ( ssid ) > 0 ) strlcpy ( multiWiFi [ n ] . clientSSID , ssid , 33 ) ; // this will keep old SSID intact if not present in JSON
if ( strlen ( pass ) > 0 ) strlcpy ( multiWiFi [ n ] . clientPass , pass , 65 ) ; // this will keep old password intact if not present in JSON
multiWiFi [ n ] . staticIP = nIP ;
multiWiFi [ n ] . staticGW = nGW ;
multiWiFi [ n ] . staticSN = nSN ;
if ( + + n > = WLED_MAX_WIFI_COUNT ) break ;
}
}
2020-11-04 10:04:40 +00:00
2024-01-20 23:30:15 +00:00
JsonArray dns = nw [ F ( " dns " ) ] ;
if ( ! dns . isNull ( ) ) {
for ( size_t i = 0 ; i < 4 ; i + + ) {
CJSON ( dnsAddress [ i ] , dns [ i ] ) ;
}
2020-11-04 10:04:40 +00:00
}
2021-03-13 21:04:37 +00:00
JsonObject ap = doc [ " ap " ] ;
2020-11-07 22:54:56 +00:00
getStringFromJson ( apSSID , ap [ F ( " ssid " ) ] , 33 ) ;
2020-11-04 10:04:40 +00:00
getStringFromJson ( apPass , ap [ " psk " ] , 65 ) ; //normally not present due to security
2020-11-07 22:54:56 +00:00
//int ap_pskl = ap[F("pskl")];
CJSON ( apChannel , ap [ F ( " chan " ) ] ) ;
2020-11-04 10:04:40 +00:00
if ( apChannel > 13 | | apChannel < 1 ) apChannel = 1 ;
2020-11-07 22:54:56 +00:00
CJSON ( apHide , ap [ F ( " hide " ) ] ) ;
2020-11-04 10:04:40 +00:00
if ( apHide > 1 ) apHide = 1 ;
2020-11-07 22:54:56 +00:00
CJSON ( apBehavior , ap [ F ( " behav " ) ] ) ;
2020-11-04 10:04:40 +00:00
/*
2021-03-13 21:04:37 +00:00
JsonArray ap_ip = ap [ " ip " ] ;
2024-07-11 19:22:58 +00:00
for ( unsigned i = 0 ; i < 4 ; i + + ) {
2020-11-04 10:04:40 +00:00
apIP [ i ] = ap_ip ;
2021-03-03 21:04:24 +00:00
}
*/
2020-11-04 10:04:40 +00:00
2024-06-23 12:08:18 +00:00
JsonObject wifi = doc [ F ( " wifi " ) ] ;
noWifiSleep = ! ( wifi [ F ( " sleep " ) ] | ! noWifiSleep ) ; // inverted
//noWifiSleep = !noWifiSleep;
CJSON ( force802_3g , wifi [ F ( " phy " ) ] ) ; //force phy mode g?
# ifdef ARDUINO_ARCH_ESP32
CJSON ( txPower , wifi [ F ( " txpwr " ) ] ) ;
txPower = min ( max ( ( int ) txPower , ( int ) WIFI_POWER_2dBm ) , ( int ) WIFI_POWER_19_5dBm ) ;
# endif
2020-11-04 10:04:40 +00:00
2020-11-07 22:54:56 +00:00
JsonObject hw = doc [ F ( " hw " ) ] ;
2020-11-04 10:04:40 +00:00
2021-08-23 12:14:48 +00:00
// initialize LED pins and lengths prior to other HW (except for ethernet)
2022-02-04 09:10:37 +00:00
JsonObject hw_led = hw [ " led " ] ;
2020-11-04 10:04:40 +00:00
2023-11-15 18:37:07 +00:00
uint16_t total = hw_led [ F ( " total " ) ] | strip . getLengthTotal ( ) ;
2023-12-29 22:07:29 +00:00
uint16_t ablMilliampsMax = hw_led [ F ( " maxpwr " ) ] | BusManager : : ablMilliampsMax ( ) ;
BusManager : : setMilliampsMax ( ablMilliampsMax ) ;
2023-12-09 18:03:33 +00:00
Bus : : setGlobalAWMode ( hw_led [ F ( " rgbwm " ) ] | AW_GLOBAL_DISABLED ) ;
2024-08-17 13:09:41 +00:00
CJSON ( strip . correctWB , hw_led [ " cct " ] ) ;
CJSON ( strip . cctFromRgb , hw_led [ F ( " cr " ) ] ) ;
2024-03-28 15:03:06 +00:00
CJSON ( cctICused , hw_led [ F ( " ic " ) ] ) ;
2022-03-08 01:16:33 +00:00
CJSON ( strip . cctBlending , hw_led [ F ( " cb " ) ] ) ;
Bus : : setCCTBlend ( strip . cctBlending ) ;
strip . setTargetFps ( hw_led [ " fps " ] ) ; //NOP if 0, default 42 FPS
2023-06-30 19:12:59 +00:00
CJSON ( useGlobalLedBuffer , hw_led [ F ( " ld " ) ] ) ;
2020-11-04 10:04:40 +00:00
2022-07-10 20:23:25 +00:00
# ifndef WLED_DISABLE_2D
2022-05-08 08:50:48 +00:00
// 2D Matrix Settings
JsonObject matrix = hw_led [ F ( " matrix " ) ] ;
if ( ! matrix . isNull ( ) ) {
strip . isMatrix = true ;
2023-02-12 12:18:30 +00:00
CJSON ( strip . panels , matrix [ F ( " mpc " ) ] ) ;
2023-01-02 19:56:00 +00:00
strip . panel . clear ( ) ;
2022-05-08 08:50:48 +00:00
JsonArray panels = matrix [ F ( " panels " ) ] ;
2024-05-12 09:12:13 +00:00
int s = 0 ;
2022-05-08 08:50:48 +00:00
if ( ! panels . isNull ( ) ) {
2023-01-02 19:56:00 +00:00
strip . panel . reserve ( max ( 1U , min ( ( size_t ) strip . panels , ( size_t ) WLED_MAX_PANELS ) ) ) ; // pre-allocate memory for panels
2022-05-08 08:50:48 +00:00
for ( JsonObject pnl : panels ) {
2023-01-02 19:56:00 +00:00
WS2812FX : : Panel p ;
CJSON ( p . bottomStart , pnl [ " b " ] ) ;
CJSON ( p . rightStart , pnl [ " r " ] ) ;
CJSON ( p . vertical , pnl [ " v " ] ) ;
CJSON ( p . serpentine , pnl [ " s " ] ) ;
CJSON ( p . xOffset , pnl [ " x " ] ) ;
CJSON ( p . yOffset , pnl [ " y " ] ) ;
CJSON ( p . height , pnl [ " h " ] ) ;
CJSON ( p . width , pnl [ " w " ] ) ;
strip . panel . push_back ( p ) ;
if ( + + s > = WLED_MAX_PANELS | | s > = strip . panels ) break ; // max panels reached
2022-05-08 08:50:48 +00:00
}
2023-01-02 19:56:00 +00:00
} else {
// fallback
WS2812FX : : Panel p ;
strip . panels = 1 ;
p . height = p . width = 8 ;
p . xOffset = p . yOffset = 0 ;
p . options = 0 ;
strip . panel . push_back ( p ) ;
2022-05-08 08:50:48 +00:00
}
2023-02-12 12:18:30 +00:00
// cannot call strip.setUpMatrix() here due to already locked JSON buffer
2022-05-08 08:50:48 +00:00
}
2022-07-10 20:23:25 +00:00
# endif
2022-05-08 08:50:48 +00:00
2021-01-30 23:38:27 +00:00
JsonArray ins = hw_led [ " ins " ] ;
2023-01-06 08:24:29 +00:00
2021-05-10 23:11:16 +00:00
if ( fromFS | | ! ins . isNull ( ) ) {
2024-06-12 16:00:00 +00:00
DEBUG_PRINTF_P ( PSTR ( " Heap before buses: %d \n " ) , ESP . getFreeHeap ( ) ) ;
2024-05-12 09:12:13 +00:00
int s = 0 ; // bus iterator
2023-12-29 22:07:29 +00:00
if ( fromFS ) BusManager : : removeAll ( ) ; // can't safely manipulate busses directly in network callback
2024-07-07 12:18:51 +00:00
unsigned mem = 0 ;
2024-06-12 16:00:00 +00:00
// determine if it is sensible to use parallel I2S outputs on ESP32 (i.e. more than 5 outputs = 1 I2S + 4 RMT)
bool useParallel = false ;
# if defined(ARDUINO_ARCH_ESP32) && !defined(ARDUINO_ARCH_ESP32S2) && !defined(ARDUINO_ARCH_ESP32S3) && !defined(ARDUINO_ARCH_ESP32C3)
unsigned digitalCount = 0 ;
2024-07-07 12:18:51 +00:00
unsigned maxLedsOnBus = 0 ;
unsigned maxChannels = 0 ;
2024-06-12 16:00:00 +00:00
for ( JsonObject elm : ins ) {
unsigned type = elm [ " type " ] | TYPE_WS2812_RGB ;
2024-07-07 12:18:51 +00:00
unsigned len = elm [ " len " ] | DEFAULT_LED_COUNT ;
2024-08-24 09:35:32 +00:00
if ( ! Bus : : isDigital ( type ) ) continue ;
if ( ! Bus : : is2Pin ( type ) ) {
2024-07-07 12:18:51 +00:00
digitalCount + + ;
unsigned channels = Bus : : getNumberOfChannels ( type ) ;
if ( len > maxLedsOnBus ) maxLedsOnBus = len ;
if ( channels > maxChannels ) maxChannels = channels ;
}
2024-06-12 16:00:00 +00:00
}
2024-07-07 12:18:51 +00:00
DEBUG_PRINTF_P ( PSTR ( " Maximum LEDs on a bus: %u \n Digital buses: %u \n " ) , maxLedsOnBus , digitalCount ) ;
2024-06-12 16:00:00 +00:00
// we may remove 300 LEDs per bus limit when NeoPixelBus is updated beyond 2.9.0
2024-07-07 12:18:51 +00:00
if ( maxLedsOnBus < = 300 & & digitalCount > 5 ) {
DEBUG_PRINTLN ( F ( " Switching to parallel I2S. " ) ) ;
2024-06-12 16:00:00 +00:00
useParallel = true ;
BusManager : : useParallelOutput ( ) ;
2024-07-07 12:18:51 +00:00
mem = BusManager : : memUsage ( maxChannels , maxLedsOnBus , 8 ) ; // use alternate memory calculation
2024-06-12 16:00:00 +00:00
}
# endif
2024-07-07 12:18:51 +00:00
2021-05-10 23:11:16 +00:00
for ( JsonObject elm : ins ) {
2022-12-31 16:06:18 +00:00
if ( s > = WLED_MAX_BUSSES + WLED_MIN_VIRTUAL_BUSSES ) break ;
2021-05-10 23:11:16 +00:00
uint8_t pins [ 5 ] = { 255 , 255 , 255 , 255 , 255 } ;
2021-05-18 13:45:34 +00:00
JsonArray pinArr = elm [ " pin " ] ;
2021-05-10 23:11:16 +00:00
if ( pinArr . size ( ) = = 0 ) continue ;
2024-07-07 12:18:51 +00:00
//pins[0] = pinArr[0];
2024-06-12 16:00:00 +00:00
unsigned i = 0 ;
2021-05-10 23:11:16 +00:00
for ( int p : pinArr ) {
2021-05-18 13:45:34 +00:00
pins [ i + + ] = p ;
2021-05-10 23:11:16 +00:00
if ( i > 4 ) break ;
}
2022-02-04 09:10:37 +00:00
uint16_t length = elm [ " len " ] | 1 ;
2023-12-09 18:03:33 +00:00
uint8_t colorOrder = ( int ) elm [ F ( " order " ) ] ; // contains white channel swap option in upper nibble
2021-05-17 14:23:46 +00:00
uint8_t skipFirst = elm [ F ( " skip " ) ] ;
2021-09-11 23:15:51 +00:00
uint16_t start = elm [ " start " ] | 0 ;
2021-10-11 00:19:33 +00:00
if ( length = = 0 | | start + length > MAX_LEDS ) continue ; // zero length or we reached max. number of LEDs, just stop
2021-05-10 23:11:16 +00:00
uint8_t ledType = elm [ " type " ] | TYPE_WS2812_RGB ;
bool reversed = elm [ " rev " ] ;
2021-10-07 20:57:07 +00:00
bool refresh = elm [ " ref " ] | false ;
2024-03-07 19:21:56 +00:00
uint16_t freqkHz = elm [ F ( " freq " ) ] | 0 ; // will be in kHz for DotStar and Hz for PWM
2023-12-09 18:03:33 +00:00
uint8_t AWmode = elm [ F ( " rgbwm " ) ] | RGBW_MODE_MANUAL_ONLY ;
2024-07-07 12:18:51 +00:00
uint8_t maPerLed = elm [ F ( " ledma " ) ] | LED_MILLIAMPS_DEFAULT ;
2023-12-29 22:07:29 +00:00
uint16_t maMax = elm [ F ( " maxpwr " ) ] | ( ablMilliampsMax * length ) / total ; // rough (incorrect?) per strip ABL calculation when no config exists
2023-11-15 18:37:07 +00:00
// To disable brightness limiter we either set output max current to 0 or single LED current to 0 (we choose output max current)
2024-08-24 09:35:32 +00:00
if ( Bus : : isPWM ( ledType ) | | Bus : : isOnOff ( ledType ) | | Bus : : isVirtual ( ledType ) ) { // analog and virtual
2023-11-15 18:37:07 +00:00
maPerLed = 0 ;
maMax = 0 ;
}
2023-12-02 11:15:57 +00:00
ledType | = refresh < < 7 ; // hack bit 7 to indicate strip requires off refresh
2022-03-05 00:05:26 +00:00
if ( fromFS ) {
2023-11-15 18:37:07 +00:00
BusConfig bc = BusConfig ( ledType , pins , start , length , colorOrder , reversed , skipFirst , AWmode , freqkHz , useGlobalLedBuffer , maPerLed , maMax ) ;
2024-06-12 16:00:00 +00:00
if ( useParallel & & s < 8 ) {
2024-07-07 12:18:51 +00:00
// if for some unexplained reason the above pre-calculation was wrong, update
unsigned memT = BusManager : : memUsage ( bc ) ; // includes x8 memory allocation for parallel I2S
if ( memT > mem ) mem = memT ; // if we have unequal LED count use the largest
2024-06-12 16:00:00 +00:00
} else
mem + = BusManager : : memUsage ( bc ) ; // includes global buffer
if ( mem < = MAX_LED_MEMORY ) if ( BusManager : : add ( bc ) = = - 1 ) break ; // finalization will be done in WLED::beginStrip()
2022-03-05 00:05:26 +00:00
} else {
if ( busConfigs [ s ] ! = nullptr ) delete busConfigs [ s ] ;
2023-11-15 18:37:07 +00:00
busConfigs [ s ] = new BusConfig ( ledType , pins , start , length , colorOrder , reversed , skipFirst , AWmode , freqkHz , useGlobalLedBuffer , maPerLed , maMax ) ;
2024-07-07 12:18:51 +00:00
doInitBusses = true ; // finalization done in beginStrip()
2022-03-05 00:05:26 +00:00
}
2022-03-19 13:21:14 +00:00
s + + ;
2021-01-30 23:38:27 +00:00
}
2024-06-12 16:00:00 +00:00
DEBUG_PRINTF_P ( PSTR ( " LED buffer size: %uB \n " ) , mem ) ;
DEBUG_PRINTF_P ( PSTR ( " Heap after buses: %d \n " ) , ESP . getFreeHeap ( ) ) ;
2021-01-30 23:38:27 +00:00
}
2023-12-29 22:07:29 +00:00
if ( hw_led [ " rev " ] ) BusManager : : getBus ( 0 ) - > setReversed ( true ) ; //set 0.11 global reversed setting for first bus
2020-11-04 10:04:40 +00:00
2021-12-31 20:35:27 +00:00
// read color order map configuration
JsonArray hw_com = hw [ F ( " com " ) ] ;
if ( ! hw_com . isNull ( ) ) {
2024-09-11 14:45:39 +00:00
BusManager : : getColorOrderMap ( ) . reserve ( std : : min ( hw_com . size ( ) , ( size_t ) WLED_MAX_COLOR_ORDER_MAPPINGS ) ) ;
2021-12-31 20:35:27 +00:00
for ( JsonObject entry : hw_com ) {
2022-02-04 09:10:37 +00:00
uint16_t start = entry [ " start " ] | 0 ;
uint16_t len = entry [ " len " ] | 0 ;
2021-12-31 20:35:27 +00:00
uint8_t colorOrder = ( int ) entry [ F ( " order " ) ] ;
2024-08-22 15:15:12 +00:00
if ( ! BusManager : : getColorOrderMap ( ) . add ( start , len , colorOrder ) ) break ;
2021-12-31 20:35:27 +00:00
}
}
2021-05-19 16:39:16 +00:00
// read multiple button configuration
2021-07-01 18:51:52 +00:00
JsonObject btn_obj = hw [ " btn " ] ;
2024-02-18 14:52:36 +00:00
CJSON ( touchThreshold , btn_obj [ F ( " tt " ) ] ) ;
2023-01-03 16:36:24 +00:00
bool pull = btn_obj [ F ( " pull " ) ] | ( ! disablePullUp ) ; // if true, pullup is enabled
2023-01-03 16:15:55 +00:00
disablePullUp = ! pull ;
2024-01-20 23:30:15 +00:00
JsonArray hw_btn_ins = btn_obj [ " ins " ] ;
2021-05-19 16:39:16 +00:00
if ( ! hw_btn_ins . isNull ( ) ) {
2024-06-12 16:00:00 +00:00
// deallocate existing button pins
2024-09-19 19:44:11 +00:00
for ( unsigned b = 0 ; b < WLED_MAX_BUTTONS ; b + + ) PinManager : : deallocatePin ( btnPin [ b ] , PinOwner : : Button ) ; // does nothing if trying to deallocate a pin with PinOwner != Button
2024-06-12 16:00:00 +00:00
unsigned s = 0 ;
2021-05-19 16:39:16 +00:00
for ( JsonObject btn : hw_btn_ins ) {
CJSON ( buttonType [ s ] , btn [ " type " ] ) ;
2021-06-30 10:33:51 +00:00
int8_t pin = btn [ " pin " ] [ 0 ] | - 1 ;
2024-09-19 19:44:11 +00:00
if ( pin > - 1 & & PinManager : : allocatePin ( pin , false , PinOwner : : Button ) ) {
2021-05-21 22:13:49 +00:00
btnPin [ s ] = pin ;
2022-12-10 18:16:02 +00:00
# ifdef ARDUINO_ARCH_ESP32
// ESP32 only: check that analog button pin is a valid ADC gpio
2024-07-07 12:18:51 +00:00
if ( ( buttonType [ s ] = = BTN_TYPE_ANALOG ) | | ( buttonType [ s ] = = BTN_TYPE_ANALOG_INVERTED ) ) {
if ( digitalPinToAnalogChannel ( btnPin [ s ] ) < 0 ) {
// not an ADC analog pin
2024-09-10 13:20:34 +00:00
DEBUG_PRINTF_P ( PSTR ( " PIN ALLOC error: GPIO%d for analog button #%d is not an analog pin! \n " ) , btnPin [ s ] , s ) ;
2024-07-07 12:18:51 +00:00
btnPin [ s ] = - 1 ;
2024-09-19 19:44:11 +00:00
PinManager : : deallocatePin ( pin , PinOwner : : Button ) ;
2024-07-07 12:18:51 +00:00
} else {
analogReadResolution ( 12 ) ; // see #4040
}
2023-01-06 08:24:29 +00:00
}
2024-07-07 12:18:51 +00:00
else if ( ( buttonType [ s ] = = BTN_TYPE_TOUCH | | buttonType [ s ] = = BTN_TYPE_TOUCH_SWITCH ) )
2024-04-07 20:15:58 +00:00
{
2024-07-07 12:18:51 +00:00
if ( digitalPinToTouchChannel ( btnPin [ s ] ) < 0 ) {
// not a touch pin
2024-09-10 13:20:34 +00:00
DEBUG_PRINTF_P ( PSTR ( " PIN ALLOC error: GPIO%d for touch button #%d is not a touch pin! \n " ) , btnPin [ s ] , s ) ;
2024-07-07 12:18:51 +00:00
btnPin [ s ] = - 1 ;
2024-09-19 19:44:11 +00:00
PinManager : : deallocatePin ( pin , PinOwner : : Button ) ;
2024-07-07 12:18:51 +00:00
}
//if touch pin, enable the touch interrupt on ESP32 S2 & S3
# ifdef SOC_TOUCH_VERSION_2 // ESP32 S2 and S3 have a function to check touch state but need to attach an interrupt to do so
else
{
2024-08-01 17:49:47 +00:00
touchAttachInterrupt ( btnPin [ s ] , touchButtonISR , touchThreshold < < 4 ) ; // threshold on Touch V2 is much higher (1500 is a value given by Espressif example, I measured changes of over 5000)
2024-07-07 12:18:51 +00:00
}
# endif
2024-04-07 20:15:58 +00:00
}
2023-01-06 08:24:29 +00:00
else
2022-12-10 18:16:02 +00:00
# endif
{
if ( disablePullUp ) {
pinMode ( btnPin [ s ] , INPUT ) ;
} else {
# ifdef ESP32
pinMode ( btnPin [ s ] , buttonType [ s ] = = BTN_TYPE_PUSH_ACT_HIGH ? INPUT_PULLDOWN : INPUT_PULLUP ) ;
# else
pinMode ( btnPin [ s ] , INPUT_PULLUP ) ;
# endif
}
2022-11-26 22:56:55 +00:00
}
2021-05-21 22:13:49 +00:00
} else {
btnPin [ s ] = - 1 ;
2021-05-19 16:39:16 +00:00
}
2021-07-01 18:51:52 +00:00
JsonArray hw_btn_ins_0_macros = btn [ " macros " ] ;
2021-05-19 16:39:16 +00: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-19 16:52:20 +00:00
} else {
2021-05-20 04:45:02 +00:00
// new install/missing configuration (button 0 has defaults)
2021-07-07 08:18:00 +00:00
if ( fromFS ) {
2021-07-09 18:06:48 +00:00
// relies upon only being called once with fromFS == true, which is currently true.
2024-03-05 15:27:28 +00:00
for ( size_t s = 0 ; s < WLED_MAX_BUTTONS ; s + + ) {
2024-09-19 19:44:11 +00:00
if ( buttonType [ s ] = = BTN_TYPE_NONE | | btnPin [ s ] < 0 | | ! PinManager : : allocatePin ( btnPin [ s ] , false , PinOwner : : Button ) ) {
2024-03-05 15:27:28 +00:00
btnPin [ s ] = - 1 ;
buttonType [ s ] = BTN_TYPE_NONE ;
}
if ( btnPin [ s ] > = 0 ) {
if ( disablePullUp ) {
pinMode ( btnPin [ s ] , INPUT ) ;
} else {
# ifdef ESP32
pinMode ( btnPin [ s ] , buttonType [ s ] = = BTN_TYPE_PUSH_ACT_HIGH ? INPUT_PULLDOWN : INPUT_PULLUP ) ;
# else
pinMode ( btnPin [ s ] , INPUT_PULLUP ) ;
# endif
}
}
2021-05-20 04:45:02 +00:00
macroButton [ s ] = 0 ;
macroLongPress [ s ] = 0 ;
macroDoublePress [ s ] = 0 ;
}
2021-07-07 08:18:00 +00:00
}
2021-05-19 16:39:16 +00:00
}
2024-02-18 14:52:36 +00:00
2021-07-01 18:51:52 +00:00
CJSON ( buttonPublishMqtt , btn_obj [ " mqtt " ] ) ;
2020-11-04 10:04:40 +00:00
2024-03-05 15:27:28 +00:00
# ifndef WLED_DISABLE_INFRARED
2021-05-10 23:11:16 +00:00
int hw_ir_pin = hw [ " ir " ] [ " pin " ] | - 2 ; // 4
if ( hw_ir_pin > - 2 ) {
2024-09-19 19:44:11 +00:00
PinManager : : deallocatePin ( irPin , PinOwner : : IR ) ;
if ( PinManager : : allocatePin ( hw_ir_pin , false , PinOwner : : IR ) ) {
2021-05-10 23:11:16 +00:00
irPin = hw_ir_pin ;
} else {
irPin = - 1 ;
}
2021-01-16 23:20:31 +00:00
}
2021-03-13 21:04:37 +00:00
CJSON ( irEnabled , hw [ " ir " ] [ " type " ] ) ;
2024-03-05 15:27:28 +00:00
# endif
2022-02-06 23:40:45 +00:00
CJSON ( irApplyToAllSelected , hw [ " ir " ] [ " sel " ] ) ;
2021-01-16 23:20:31 +00:00
2021-03-04 13:24:25 +00:00
JsonObject relay = hw [ F ( " relay " ) ] ;
2024-04-21 11:37:07 +00:00
2024-04-21 18:02:00 +00:00
rlyOpenDrain = relay [ F ( " odrain " ) ] | rlyOpenDrain ;
2021-05-10 23:11:16 +00:00
int hw_relay_pin = relay [ " pin " ] | - 2 ;
if ( hw_relay_pin > - 2 ) {
2024-09-19 19:44:11 +00:00
PinManager : : deallocatePin ( rlyPin , PinOwner : : Relay ) ;
if ( PinManager : : allocatePin ( hw_relay_pin , true , PinOwner : : Relay ) ) {
2021-05-10 23:11:16 +00:00
rlyPin = hw_relay_pin ;
2024-04-21 11:37:07 +00:00
pinMode ( rlyPin , rlyOpenDrain ? OUTPUT_OPEN_DRAIN : OUTPUT ) ;
2021-05-10 23:11:16 +00:00
} else {
rlyPin = - 1 ;
}
2021-01-16 23:20:31 +00:00
}
2021-03-04 13:24:25 +00:00
if ( relay . containsKey ( " rev " ) ) {
2021-03-04 11:10:18 +00:00
rlyMde = ! relay [ " rev " ] ;
2021-03-04 13:24:25 +00:00
}
2020-11-04 10:04:40 +00:00
2022-02-01 19:02:46 +00:00
CJSON ( serialBaud , hw [ F ( " baud " ) ] ) ;
if ( serialBaud < 96 | | serialBaud > 15000 ) serialBaud = 1152 ;
updateBaudRate ( serialBaud * 100 ) ;
2022-08-07 14:43:29 +00:00
JsonArray hw_if_i2c = hw [ F ( " if " ) ] [ F ( " i2c-pin " ) ] ;
CJSON ( i2c_sda , hw_if_i2c [ 0 ] ) ;
CJSON ( i2c_scl , hw_if_i2c [ 1 ] ) ;
PinManagerPinType i2c [ 2 ] = { { i2c_sda , true } , { i2c_scl , true } } ;
2024-09-19 19:44:11 +00:00
if ( i2c_scl > = 0 & & i2c_sda > = 0 & & PinManager : : allocateMultiplePins ( i2c , 2 , PinOwner : : HW_I2C ) ) {
2022-08-07 14:43:29 +00:00
# ifdef ESP32
2024-02-06 13:47:20 +00:00
if ( ! Wire . setPins ( i2c_sda , i2c_scl ) ) { i2c_scl = i2c_sda = - 1 ; } // this will fail if Wire is initialised (Wire.begin() called prior)
2023-05-30 17:36:14 +00:00
else Wire . begin ( ) ;
# else
Wire . begin ( i2c_sda , i2c_scl ) ;
2022-08-07 14:43:29 +00:00
# endif
} else {
i2c_sda = - 1 ;
i2c_scl = - 1 ;
}
JsonArray hw_if_spi = hw [ F ( " if " ) ] [ F ( " spi-pin " ) ] ;
CJSON ( spi_mosi , hw_if_spi [ 0 ] ) ;
CJSON ( spi_sclk , hw_if_spi [ 1 ] ) ;
2022-08-25 19:57:43 +00:00
CJSON ( spi_miso , hw_if_spi [ 2 ] ) ;
PinManagerPinType spi [ 3 ] = { { spi_mosi , true } , { spi_miso , true } , { spi_sclk , true } } ;
2024-09-19 19:44:11 +00:00
if ( spi_mosi > = 0 & & spi_sclk > = 0 & & PinManager : : allocateMultiplePins ( spi , 3 , PinOwner : : HW_SPI ) ) {
2022-09-09 15:16:52 +00:00
# ifdef ESP32
SPI . begin ( spi_sclk , spi_miso , spi_mosi ) ; // SPI global uses VSPI on ESP32 and FSPI on C3, S3
# else
SPI . begin ( ) ;
# endif
2022-08-07 14:43:29 +00:00
} else {
spi_mosi = - 1 ;
2022-08-25 19:57:43 +00:00
spi_miso = - 1 ;
2022-08-07 14:43:29 +00:00
spi_sclk = - 1 ;
}
2021-03-14 10:41:55 +00:00
//int hw_status_pin = hw[F("status")]["pin"]; // -1
2020-11-04 10:04:40 +00:00
2020-11-07 22:54:56 +00:00
JsonObject light = doc [ F ( " light " ) ] ;
CJSON ( briMultiplier , light [ F ( " scale-bri " ) ] ) ;
CJSON ( strip . paletteBlend , light [ F ( " pal-mode " ) ] ) ;
2024-08-17 13:09:41 +00:00
CJSON ( strip . autoSegments , light [ F ( " aseg " ) ] ) ;
2020-11-04 10:04:40 +00:00
2023-02-12 12:18:30 +00:00
CJSON ( gammaCorrectVal , light [ " gc " ] [ " val " ] ) ; // default 2.8
2021-07-01 18:51:52 +00:00
float light_gc_bri = light [ " gc " ] [ " bri " ] ;
2023-02-12 12:18:30 +00:00
float light_gc_col = light [ " gc " ] [ " col " ] ;
if ( light_gc_bri > 1.0f ) gammaCorrectBri = true ;
else gammaCorrectBri = false ;
if ( light_gc_col > 1.0f ) gammaCorrectCol = true ;
else gammaCorrectCol = false ;
if ( gammaCorrectVal > 1.0f & & gammaCorrectVal < = 3 ) {
2023-06-10 18:43:27 +00:00
if ( gammaCorrectVal ! = 2.8f ) NeoGammaWLEDMethod : : calcGammaTable ( gammaCorrectVal ) ;
2023-02-12 12:18:30 +00:00
} else {
gammaCorrectVal = 1.0f ; // no gamma correction
gammaCorrectBri = false ;
gammaCorrectCol = false ;
}
2020-11-04 10:04:40 +00:00
2022-02-04 09:10:37 +00:00
JsonObject light_tr = light [ " tr " ] ;
CJSON ( fadeTransition , light_tr [ " mode " ] ) ;
2023-09-12 04:17:06 +00:00
CJSON ( modeBlending , light_tr [ " fx " ] ) ;
2021-04-12 19:10:47 +00:00
int tdd = light_tr [ " dur " ] | - 1 ;
2022-11-20 18:40:54 +00:00
if ( tdd > = 0 ) transitionDelay = transitionDelayDefault = tdd * 100 ;
2023-11-27 12:27:52 +00:00
strip . setTransition ( fadeTransition ? transitionDelayDefault : 0 ) ;
2021-04-12 19:10:47 +00:00
CJSON ( strip . paletteFade , light_tr [ " pal " ] ) ;
2023-03-25 20:28:30 +00:00
CJSON ( randomPaletteChangeTime , light_tr [ F ( " rpc " ) ] ) ;
2024-02-06 10:06:23 +00:00
CJSON ( useHarmonicRandomPalette , light_tr [ F ( " hrp " ) ] ) ;
2020-11-04 10:04:40 +00:00
JsonObject light_nl = light [ " nl " ] ;
2022-02-04 09:10:37 +00:00
CJSON ( nightlightMode , light_nl [ " mode " ] ) ;
2021-05-10 23:11:16 +00:00
byte prev = nightlightDelayMinsDefault ;
2022-02-04 09:10:37 +00:00
CJSON ( nightlightDelayMinsDefault , light_nl [ " dur " ] ) ;
2021-05-10 23:11:16 +00:00
if ( nightlightDelayMinsDefault ! = prev ) nightlightDelayMins = nightlightDelayMinsDefault ;
2020-11-04 10:04:40 +00:00
2020-11-07 22:54:56 +00:00
CJSON ( nightlightTargetBri , light_nl [ F ( " tbri " ) ] ) ;
2021-07-01 18:51:52 +00:00
CJSON ( macroNl , light_nl [ " macro " ] ) ;
2020-11-04 10:04:40 +00:00
2022-02-04 09:10:37 +00:00
JsonObject def = doc [ " def " ] ;
2021-11-23 12:17:33 +00:00
CJSON ( bootPreset , def [ " ps " ] ) ;
2020-11-04 10:04:40 +00:00
CJSON ( turnOnAtBoot , def [ " on " ] ) ; // true
CJSON ( briS , def [ " bri " ] ) ; // 128
JsonObject interfaces = doc [ " if " ] ;
2022-02-04 09:10:37 +00:00
JsonObject if_sync = interfaces [ " sync " ] ;
2020-11-07 22:54:56 +00:00
CJSON ( udpPort , if_sync [ F ( " port0 " ) ] ) ; // 21324
CJSON ( udpPort2 , if_sync [ F ( " port1 " ) ] ) ; // 65506
2020-11-04 10:04:40 +00:00
2023-09-10 16:52:14 +00:00
# ifndef WLED_DISABLE_ESPNOW
CJSON ( useESPNowSync , if_sync [ F ( " espnow " ) ] ) ;
# endif
2024-02-09 21:15:29 +00:00
JsonObject if_sync_recv = if_sync [ F ( " recv " ) ] ;
2020-11-04 10:04:40 +00:00
CJSON ( receiveNotificationBrightness , if_sync_recv [ " bri " ] ) ;
2021-03-13 21:04:37 +00:00
CJSON ( receiveNotificationColor , if_sync_recv [ " col " ] ) ;
2021-07-10 14:14:17 +00:00
CJSON ( receiveNotificationEffects , if_sync_recv [ " fx " ] ) ;
2024-09-10 18:02:29 +00:00
CJSON ( receiveNotificationPalette , if_sync_recv [ " pal " ] ) ;
2021-08-21 10:28:22 +00:00
CJSON ( receiveGroups , if_sync_recv [ " grp " ] ) ;
2021-12-17 10:22:20 +00:00
CJSON ( receiveSegmentOptions , if_sync_recv [ " seg " ] ) ;
2022-02-20 21:24:11 +00:00
CJSON ( receiveSegmentBounds , if_sync_recv [ " sb " ] ) ;
2020-11-04 10:04:40 +00:00
2024-02-09 21:15:29 +00:00
JsonObject if_sync_send = if_sync [ F ( " send " ) ] ;
2023-09-10 16:52:14 +00:00
CJSON ( sendNotifications , if_sync_send [ " en " ] ) ;
sendNotificationsRT = sendNotifications ;
CJSON ( notifyDirect , if_sync_send [ F ( " dir " ) ] ) ;
2021-07-01 18:51:52 +00:00
CJSON ( notifyButton , if_sync_send [ " btn " ] ) ;
CJSON ( notifyAlexa , if_sync_send [ " va " ] ) ;
CJSON ( notifyHue , if_sync_send [ " hue " ] ) ;
2021-08-21 10:28:22 +00:00
CJSON ( syncGroups , if_sync_send [ " grp " ] ) ;
2022-10-18 23:31:23 +00:00
if ( if_sync_send [ F ( " twice " ) ] ) udpNumRetries = 1 ; // import setting from 0.13 and earlier
CJSON ( udpNumRetries , if_sync_send [ " ret " ] ) ;
2020-11-07 22:54:56 +00:00
2024-03-05 15:27:28 +00:00
JsonObject if_nodes = interfaces [ " nodes " ] ;
2021-03-13 21:04:37 +00:00
CJSON ( nodeListEnabled , if_nodes [ F ( " list " ) ] ) ;
CJSON ( nodeBroadcastEnabled , if_nodes [ F ( " bcast " ) ] ) ;
JsonObject if_live = interfaces [ " live " ] ;
2023-09-10 16:52:14 +00:00
CJSON ( receiveDirect , if_live [ " en " ] ) ; // UDP/Hyperion realtime
2022-03-25 15:36:05 +00:00
CJSON ( useMainSegmentOnly , if_live [ F ( " mso " ) ] ) ;
2023-11-23 16:13:13 +00:00
CJSON ( realtimeRespectLedMaps , if_live [ F ( " rlm " ) ] ) ;
2021-03-13 21:04:37 +00:00
CJSON ( e131Port , if_live [ " port " ] ) ; // 5568
2021-10-04 17:41:20 +00:00
if ( e131Port = = DDP_DEFAULT_PORT ) e131Port = E131_DEFAULT_PORT ; // prevent double DDP port allocation
2020-11-07 22:54:56 +00:00
CJSON ( e131Multicast , if_live [ F ( " mc " ) ] ) ;
2024-01-20 23:30:15 +00:00
JsonObject if_live_dmx = if_live [ " dmx " ] ;
2020-11-07 22:54:56 +00:00
CJSON ( e131Universe , if_live_dmx [ F ( " uni " ) ] ) ;
CJSON ( e131SkipOutOfSequence , if_live_dmx [ F ( " seqskip " ) ] ) ;
CJSON ( DMXAddress , if_live_dmx [ F ( " addr " ) ] ) ;
2022-09-22 23:02:49 +00:00
if ( ! DMXAddress | | DMXAddress > 510 ) DMXAddress = 1 ;
2022-11-19 13:10:40 +00:00
CJSON ( DMXSegmentSpacing , if_live_dmx [ F ( " dss " ) ] ) ;
if ( DMXSegmentSpacing > 150 ) DMXSegmentSpacing = 0 ;
2023-02-21 16:13:15 +00:00
CJSON ( e131Priority , if_live_dmx [ F ( " e131prio " ) ] ) ;
if ( e131Priority > 200 ) e131Priority = 200 ;
2022-02-04 09:10:37 +00:00
CJSON ( DMXMode , if_live_dmx [ " mode " ] ) ;
2020-11-07 22:54:56 +00:00
tdd = if_live [ F ( " timeout " ) ] | - 1 ;
2020-11-04 10:04:40 +00:00
if ( tdd > = 0 ) realtimeTimeoutMs = tdd * 100 ;
2020-11-07 22:54:56 +00: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 10:04:40 +00:00
2024-08-17 13:09:41 +00:00
# ifndef WLED_DISABLE_ALEXA
2021-07-01 18:51:52 +00:00
CJSON ( alexaEnabled , interfaces [ " va " ] [ F ( " alexa " ) ] ) ; // false
CJSON ( macroAlexaOn , interfaces [ " va " ] [ " macros " ] [ 0 ] ) ;
CJSON ( macroAlexaOff , interfaces [ " va " ] [ " macros " ] [ 1 ] ) ;
2022-10-25 21:42:26 +00:00
CJSON ( alexaNumPresets , interfaces [ " va " ] [ " p " ] ) ;
2024-08-17 13:09:41 +00:00
# endif
2022-10-25 21:42:26 +00:00
2024-08-15 14:18:34 +00:00
# ifndef WLED_DISABLE_MQTT
2021-03-13 21:04:37 +00:00
JsonObject if_mqtt = interfaces [ " mqtt " ] ;
CJSON ( mqttEnabled , if_mqtt [ " en " ] ) ;
2023-09-01 23:05:45 +00:00
getStringFromJson ( mqttServer , if_mqtt [ F ( " broker " ) ] , MQTT_MAX_SERVER_LEN + 1 ) ;
2021-03-13 21:04:37 +00:00
CJSON ( mqttPort , if_mqtt [ " port " ] ) ; // 1883
2020-11-07 22:54:56 +00:00
getStringFromJson ( mqttUser , if_mqtt [ F ( " user " ) ] , 41 ) ;
2021-06-29 23:23:35 +00:00
getStringFromJson ( mqttPass , if_mqtt [ " psk " ] , 65 ) ; //normally not present due to security
2020-11-07 22:54:56 +00:00
getStringFromJson ( mqttClientID , if_mqtt [ F ( " cid " ) ] , 41 ) ;
2020-11-04 10:04:40 +00:00
2023-09-01 23:05:45 +00:00
getStringFromJson ( mqttDeviceTopic , if_mqtt [ F ( " topics " ) ] [ F ( " device " ) ] , MQTT_MAX_TOPIC_LEN + 1 ) ; // "wled/test"
getStringFromJson ( mqttGroupTopic , if_mqtt [ F ( " topics " ) ] [ F ( " group " ) ] , MQTT_MAX_TOPIC_LEN + 1 ) ; // ""
2023-05-28 20:50:19 +00:00
CJSON ( retainMqttMsg , if_mqtt [ F ( " rtn " ) ] ) ;
2021-05-07 09:51:48 +00:00
# endif
2020-11-04 10:04:40 +00:00
2021-05-07 09:51:48 +00:00
# ifndef WLED_DISABLE_HUESYNC
2021-07-01 18:51:52 +00:00
JsonObject if_hue = interfaces [ " hue " ] ;
2021-03-13 21:04:37 +00:00
CJSON ( huePollingEnabled , if_hue [ " en " ] ) ;
CJSON ( huePollLightId , if_hue [ " id " ] ) ;
2020-11-07 22:54:56 +00:00
tdd = if_hue [ F ( " iv " ) ] | - 1 ;
2020-11-04 10:04:40 +00:00
if ( tdd > = 2 ) huePollIntervalMs = tdd * 100 ;
2021-03-13 21:04:37 +00:00
JsonObject if_hue_recv = if_hue [ " recv " ] ;
2020-11-04 10:04:40 +00:00
CJSON ( hueApplyOnOff , if_hue_recv [ " on " ] ) ;
CJSON ( hueApplyBri , if_hue_recv [ " bri " ] ) ;
2021-03-13 21:04:37 +00:00
CJSON ( hueApplyColor , if_hue_recv [ " col " ] ) ;
2020-11-04 10:04:40 +00:00
2021-03-13 21:04:37 +00:00
JsonArray if_hue_ip = if_hue [ " ip " ] ;
2020-11-04 10:04:40 +00:00
2024-07-11 19:22:58 +00:00
for ( unsigned i = 0 ; i < 4 ; i + + )
2020-11-04 10:04:40 +00:00
CJSON ( hueIP [ i ] , if_hue_ip [ i ] ) ;
2021-05-07 09:51:48 +00:00
# endif
2020-11-04 10:04:40 +00:00
2020-11-07 22:54:56 +00:00
JsonObject if_ntp = interfaces [ F ( " ntp " ) ] ;
2021-03-13 21:04:37 +00:00
CJSON ( ntpEnabled , if_ntp [ " en " ] ) ;
2020-11-07 22:54:56 +00: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-03-05 22:05:09 +00:00
CJSON ( longitude , if_ntp [ F ( " ln " ) ] ) ;
CJSON ( latitude , if_ntp [ F ( " lt " ) ] ) ;
2020-11-04 10:04:40 +00:00
2020-11-07 22:54:56 +00:00
JsonObject ol = doc [ F ( " ol " ) ] ;
2022-03-06 23:11:43 +00:00
CJSON ( overlayCurrent , ol [ F ( " clock " ) ] ) ; // 0
2020-11-07 22:54:56 +00:00
CJSON ( countdownMode , ol [ F ( " cntdwn " ) ] ) ;
2020-11-04 10:04:40 +00:00
2021-04-12 19:10:47 +00:00
CJSON ( overlayMin , ol [ " min " ] ) ;
2020-12-10 00:28:42 +00:00
CJSON ( overlayMax , ol [ F ( " max " ) ] ) ;
CJSON ( analogClock12pixel , ol [ F ( " o12pix " ) ] ) ;
CJSON ( analogClock5MinuteMarks , ol [ F ( " o5m " ) ] ) ;
CJSON ( analogClockSecondsTrail , ol [ F ( " osec " ) ] ) ;
2023-10-26 21:36:29 +00:00
CJSON ( analogClockSolidBlack , ol [ F ( " osb " ) ] ) ;
2020-11-04 10:04:40 +00:00
//timed macro rules
2020-11-07 22:54:56 +00:00
JsonObject tm = doc [ F ( " timers " ) ] ;
JsonObject cntdwn = tm [ F ( " cntdwn " ) ] ;
JsonArray cntdwn_goal = cntdwn [ F ( " goal " ) ] ;
2020-11-04 10:04:40 +00: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 18:51:52 +00:00
CJSON ( macroCountdown , cntdwn [ " macro " ] ) ;
2020-12-31 19:47:38 +00:00
setCountdown ( ) ;
2020-11-04 10:04:40 +00:00
2021-07-01 14:40:55 +00:00
JsonArray timers = tm [ " ins " ] ;
2020-11-04 10:04:40 +00:00
uint8_t it = 0 ;
for ( JsonObject timer : timers ) {
2021-03-06 23:04:46 +00:00
if ( it > 9 ) break ;
2023-01-06 08:24:29 +00:00
if ( it < 8 & & timer [ F ( " hour " ) ] = = 255 ) it = 8 ; // hour==255 -> sunrise/sunset
2020-11-07 22:54:56 +00:00
CJSON ( timerHours [ it ] , timer [ F ( " hour " ) ] ) ;
2021-04-12 19:10:47 +00:00
CJSON ( timerMinutes [ it ] , timer [ " min " ] ) ;
2021-07-01 18:51:52 +00:00
CJSON ( timerMacro [ it ] , timer [ " macro " ] ) ;
2020-11-04 10:04:40 +00:00
2021-12-31 13:09:48 +00:00
byte dowPrev = timerWeekday [ it ] ;
2020-12-15 23:10:48 +00: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 22:54:56 +00:00
CJSON ( timerWeekday [ it ] , timer [ F ( " dow " ) ] ) ;
2020-11-04 10:04:40 +00:00
if ( timerWeekday [ it ] ! = dowPrev ) { //present in JSON
timerWeekday [ it ] < < = 1 ; //add active bit
2021-03-13 21:04:37 +00:00
int act = timer [ " en " ] | actPrev ;
2020-11-04 10:04:40 +00:00
if ( act ) timerWeekday [ it ] + + ;
}
2021-12-25 17:46:43 +00:00
if ( it < 8 ) {
2022-01-01 15:36:06 +00:00
JsonObject start = timer [ " start " ] ;
byte startm = start [ " mon " ] ;
if ( startm ) timerMonth [ it ] = ( startm < < 4 ) ;
2021-12-31 13:09:48 +00:00
CJSON ( timerDay [ it ] , start [ " day " ] ) ;
2022-01-01 15:36:06 +00: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-25 17:46:43 +00:00
}
2020-11-04 10:04:40 +00: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 22:54:56 +00:00
CJSON ( otaLock , ota [ F ( " lock " ) ] ) ;
CJSON ( wifiLock , ota [ F ( " lock-wifi " ) ] ) ;
CJSON ( aOtaEnabled , ota [ F ( " aota " ) ] ) ;
2020-11-04 10:04:40 +00:00
getStringFromJson ( otaPass , pwd , 33 ) ; //normally not present due to security
}
2020-11-04 16:17:54 +00:00
2020-11-09 10:09:47 +00:00
# ifdef WLED_ENABLE_DMX
JsonObject dmx = doc [ " dmx " ] ;
CJSON ( DMXChannels , dmx [ F ( " chan " ) ] ) ;
CJSON ( DMXGap , dmx [ F ( " gap " ) ] ) ;
2021-09-11 23:15:51 +00:00
CJSON ( DMXStart , dmx [ " start " ] ) ;
2020-11-09 10:09:47 +00:00
CJSON ( DMXStartLED , dmx [ F ( " start-led " ) ] ) ;
2020-12-21 20:04:21 +00:00
JsonArray dmx_fixmap = dmx [ F ( " fixmap " ) ] ;
2021-11-09 23:29:04 +00:00
for ( int i = 0 ; i < dmx_fixmap . size ( ) ; i + + ) {
if ( i > 14 ) break ;
2020-12-21 20:04:21 +00:00
CJSON ( DMXFixtureMap [ i ] , dmx_fixmap [ i ] ) ;
2020-11-09 10:09:47 +00:00
}
2021-11-30 22:10:23 +00:00
CJSON ( e131ProxyUniverse , dmx [ F ( " e131proxy " ) ] ) ;
2020-11-09 10:09:47 +00:00
# endif
2020-11-11 14:50:15 +00:00
2021-04-29 15:44:31 +00:00
DEBUG_PRINTLN ( F ( " Starting usermod config. " ) ) ;
2020-11-11 14:50:15 +00:00
JsonObject usermods_settings = doc [ " um " ] ;
2021-06-24 23:26:15 +00:00
if ( ! usermods_settings . isNull ( ) ) {
2024-09-19 19:44:11 +00:00
needsSave = ! UsermodManager : : readFromConfig ( usermods_settings ) ;
2021-06-24 23:26:15 +00:00
}
2021-05-10 23:11:16 +00:00
2021-11-03 13:52:22 +00:00
if ( fromFS ) return needsSave ;
2022-03-19 13:21:14 +00:00
// if from /json/cfg
2021-05-10 23:11:16 +00:00
doReboot = doc [ F ( " rb " ) ] | doReboot ;
2022-03-19 13:21:14 +00:00
if ( doInitBusses ) return false ; // no save needed, will do after bus init in wled.cpp loop
2021-11-12 22:33:10 +00:00
return ( doc [ " sv " ] | true ) ;
2021-05-10 23:11:16 +00:00
}
2024-03-07 19:21:56 +00:00
static const char s_cfg_json [ ] PROGMEM = " /cfg.json " ;
2021-05-10 23:11:16 +00:00
void deserializeConfigFromFS ( ) {
bool success = deserializeConfigSec ( ) ;
2024-03-22 19:49:13 +00:00
# ifdef WLED_ADD_EEPROM_SUPPORT
2021-05-10 23:11:16 +00:00
if ( ! success ) { //if file does not exist, try reading from EEPROM
deEEPSettings ( ) ;
2021-06-24 23:26:15 +00:00
return ;
2021-05-10 23:11:16 +00:00
}
2024-03-22 19:49:13 +00:00
# endif
2021-05-10 23:11:16 +00:00
2021-11-14 15:56:34 +00:00
if ( ! requestJSONBufferLock ( 1 ) ) return ;
2021-05-10 23:11:16 +00:00
DEBUG_PRINTLN ( F ( " Reading settings from /cfg.json... " ) ) ;
2024-03-07 19:21:56 +00:00
success = readObjectFromFile ( s_cfg_json , nullptr , pDoc ) ;
2022-10-25 15:11:31 +00:00
if ( ! success ) { // if file does not exist, optionally try reading from EEPROM and then save defaults to FS
releaseJSONBufferLock ( ) ;
2022-07-30 09:04:04 +00:00
# ifdef WLED_ADD_EEPROM_SUPPORT
2021-06-24 23:26:15 +00:00
deEEPSettings ( ) ;
2022-07-30 09:04:04 +00:00
# endif
2022-10-25 15:11:31 +00:00
// save default values to /cfg.json
// call readFromConfig() with an empty object so that usermods can initialize to defaults prior to saving
JsonObject empty = JsonObject ( ) ;
2024-09-19 19:44:11 +00:00
UsermodManager : : readFromConfig ( empty ) ;
2022-10-25 15:11:31 +00:00
serializeConfig ( ) ;
// init Ethernet (in case default type is set at compile time)
# ifdef WLED_USE_ETHERNET
WLED : : instance ( ) . initEthernet ( ) ;
# endif
2021-05-10 23:11:16 +00:00
return ;
}
2021-08-23 12:14:48 +00:00
// NOTE: This routine deserializes *and* applies the configuration
// Therefore, must also initialize ethernet from this function
2023-12-21 20:30:17 +00:00
JsonObject root = pDoc - > as < JsonObject > ( ) ;
bool needsSave = deserializeConfig ( root , true ) ;
2021-11-12 22:33:10 +00:00
releaseJSONBufferLock ( ) ;
2021-11-03 13:52:22 +00:00
2022-10-25 15:11:31 +00:00
if ( needsSave ) serializeConfig ( ) ; // usermods required new parameters
2020-11-04 10:04:40 +00:00
}
2020-11-05 21:54:13 +00:00
void serializeConfig ( ) {
2020-11-07 22:54:56 +00:00
serializeConfigSec ( ) ;
2020-11-06 21:12:48 +00:00
DEBUG_PRINTLN ( F ( " Writing settings to /cfg.json... " ) ) ;
2021-11-14 15:56:34 +00:00
if ( ! requestJSONBufferLock ( 2 ) ) return ;
2020-11-04 10:04:40 +00:00
2023-12-23 21:56:07 +00:00
JsonObject root = pDoc - > to < JsonObject > ( ) ;
2023-12-21 20:30:17 +00:00
JsonArray rev = root . createNestedArray ( " rev " ) ;
2020-11-04 10:04:40 +00:00
rev . add ( 1 ) ; //major settings revision
rev . add ( 0 ) ; //minor settings revision
2023-12-21 20:30:17 +00:00
root [ F ( " vid " ) ] = VERSION ;
2020-11-04 10:04:40 +00:00
2023-12-21 20:30:17 +00:00
JsonObject id = root . createNestedObject ( " id " ) ;
2020-11-07 22:54:56 +00:00
id [ F ( " mdns " ) ] = cmDNS ;
id [ F ( " name " ) ] = serverDescription ;
2024-08-17 13:09:41 +00:00
# ifndef WLED_DISABLE_ALEXA
2020-11-07 22:54:56 +00:00
id [ F ( " inv " ) ] = alexaInvocationName ;
2024-08-17 13:09:41 +00:00
# endif
2021-08-10 15:11:17 +00:00
id [ F ( " sui " ) ] = simplifiedUI ;
2020-11-04 10:04:40 +00:00
2023-12-21 20:30:17 +00:00
JsonObject nw = root . createNestedObject ( " nw " ) ;
2023-09-10 16:52:14 +00:00
# ifndef WLED_DISABLE_ESPNOW
nw [ F ( " espnow " ) ] = enableESPNow ;
nw [ F ( " linked_remote " ) ] = linked_remote ;
# endif
2020-11-04 10:04:40 +00:00
JsonArray nw_ins = nw . createNestedArray ( " ins " ) ;
2024-01-20 23:30:15 +00:00
for ( size_t n = 0 ; n < multiWiFi . size ( ) ; n + + ) {
JsonObject wifi = nw_ins . createNestedObject ( ) ;
wifi [ F ( " ssid " ) ] = multiWiFi [ n ] . clientSSID ;
wifi [ F ( " pskl " ) ] = strlen ( multiWiFi [ n ] . clientPass ) ;
JsonArray wifi_ip = wifi . createNestedArray ( " ip " ) ;
JsonArray wifi_gw = wifi . createNestedArray ( " gw " ) ;
JsonArray wifi_sn = wifi . createNestedArray ( " sn " ) ;
for ( size_t i = 0 ; i < 4 ; i + + ) {
wifi_ip . add ( multiWiFi [ n ] . staticIP [ i ] ) ;
wifi_gw . add ( multiWiFi [ n ] . staticGW [ i ] ) ;
wifi_sn . add ( multiWiFi [ n ] . staticSN [ i ] ) ;
}
}
2020-11-04 10:04:40 +00:00
2024-01-20 23:30:15 +00:00
JsonArray dns = nw . createNestedArray ( F ( " dns " ) ) ;
for ( size_t i = 0 ; i < 4 ; i + + ) {
dns . add ( dnsAddress [ i ] ) ;
2020-11-04 10:04:40 +00:00
}
2023-12-21 20:30:17 +00:00
JsonObject ap = root . createNestedObject ( " ap " ) ;
2020-11-07 22:54:56 +00:00
ap [ F ( " ssid " ) ] = apSSID ;
ap [ F ( " pskl " ) ] = strlen ( apPass ) ;
ap [ F ( " chan " ) ] = apChannel ;
2020-12-19 16:09:39 +00:00
ap [ F ( " hide " ) ] = apHide ;
2020-11-07 22:54:56 +00:00
ap [ F ( " behav " ) ] = apBehavior ;
2020-11-04 10:04:40 +00:00
JsonArray ap_ip = ap . createNestedArray ( " ip " ) ;
ap_ip . add ( 4 ) ;
ap_ip . add ( 3 ) ;
ap_ip . add ( 2 ) ;
ap_ip . add ( 1 ) ;
2024-01-20 23:30:15 +00:00
JsonObject wifi = root . createNestedObject ( F ( " wifi " ) ) ;
2020-11-07 22:54:56 +00:00
wifi [ F ( " sleep " ) ] = ! noWifiSleep ;
2024-01-10 18:40:59 +00:00
wifi [ F ( " phy " ) ] = force802_3g ;
2024-06-23 12:08:18 +00:00
# ifdef ARDUINO_ARCH_ESP32
wifi [ F ( " txpwr " ) ] = txPower ;
# endif
2020-11-04 10:04:40 +00:00
2024-06-23 12:08:18 +00:00
# ifdef WLED_USE_ETHERNET
2023-12-21 20:30:17 +00:00
JsonObject ethernet = root . createNestedObject ( " eth " ) ;
2021-03-13 21:04:37 +00:00
ethernet [ " type " ] = ethernetType ;
2021-07-07 06:12:03 +00:00
if ( ethernetType ! = WLED_ETH_NONE & & ethernetType < WLED_NUM_ETH_TYPES ) {
JsonArray pins = ethernet . createNestedArray ( " pin " ) ;
2024-07-11 19:22:58 +00:00
for ( unsigned p = 0 ; p < WLED_ETH_RSVD_PINS_COUNT ; p + + ) pins . add ( esp32_nonconfigurable_ethernet_pins [ p ] . pin ) ;
2021-08-27 17:48:55 +00:00
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 ) ;
2021-07-07 06:12:03 +00:00
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 ;
}
}
2024-06-23 12:08:18 +00:00
# endif
2021-01-15 09:37:45 +00:00
2024-01-20 23:30:15 +00:00
JsonObject hw = root . createNestedObject ( F ( " hw " ) ) ;
2020-11-04 10:04:40 +00:00
JsonObject hw_led = hw . createNestedObject ( " led " ) ;
2023-11-15 18:37:07 +00:00
hw_led [ F ( " total " ) ] = strip . getLengthTotal ( ) ; //provided for compatibility on downgrade and per-output ABL
2023-12-29 22:07:29 +00:00
hw_led [ F ( " maxpwr " ) ] = BusManager : : ablMilliampsMax ( ) ;
hw_led [ F ( " ledma " ) ] = 0 ; // no longer used
2024-08-17 13:09:41 +00:00
hw_led [ " cct " ] = strip . correctWB ;
hw_led [ F ( " cr " ) ] = strip . cctFromRgb ;
2024-03-28 15:03:06 +00:00
hw_led [ F ( " ic " ) ] = cctICused ;
2022-03-08 01:16:33 +00:00
hw_led [ F ( " cb " ) ] = strip . cctBlending ;
hw_led [ " fps " ] = strip . getTargetFps ( ) ;
2023-02-14 00:33:06 +00:00
hw_led [ F ( " rgbwm " ) ] = Bus : : getGlobalAWMode ( ) ; // global auto white mode override
2023-06-30 19:12:59 +00:00
hw_led [ F ( " ld " ) ] = useGlobalLedBuffer ;
2020-11-04 10:04:40 +00:00
2022-07-10 20:23:25 +00:00
# ifndef WLED_DISABLE_2D
2022-05-08 08:50:48 +00:00
// 2D Matrix Settings
if ( strip . isMatrix ) {
JsonObject matrix = hw_led . createNestedObject ( F ( " matrix " ) ) ;
2023-01-02 19:56:00 +00:00
matrix [ F ( " mpc " ) ] = strip . panels ;
2022-05-08 08:50:48 +00:00
JsonArray panels = matrix . createNestedArray ( F ( " panels " ) ) ;
2024-05-15 13:35:14 +00:00
for ( size_t i = 0 ; i < strip . panel . size ( ) ; i + + ) {
2022-05-08 08:50:48 +00:00
JsonObject pnl = panels . createNestedObject ( ) ;
pnl [ " b " ] = strip . panel [ i ] . bottomStart ;
pnl [ " r " ] = strip . panel [ i ] . rightStart ;
pnl [ " v " ] = strip . panel [ i ] . vertical ;
pnl [ " s " ] = strip . panel [ i ] . serpentine ;
2023-01-02 19:56:00 +00:00
pnl [ " x " ] = strip . panel [ i ] . xOffset ;
pnl [ " y " ] = strip . panel [ i ] . yOffset ;
pnl [ " h " ] = strip . panel [ i ] . height ;
pnl [ " w " ] = strip . panel [ i ] . width ;
2022-05-08 08:50:48 +00:00
}
}
2022-07-10 20:23:25 +00:00
# endif
2022-05-08 08:50:48 +00:00
2020-11-04 10:04:40 +00:00
JsonArray hw_led_ins = hw_led . createNestedArray ( " ins " ) ;
2024-05-15 13:35:14 +00:00
for ( size_t s = 0 ; s < BusManager : : getNumBusses ( ) ; s + + ) {
2023-12-29 22:07:29 +00:00
Bus * bus = BusManager : : getBus ( s ) ;
2021-01-16 23:20:31 +00:00
if ( ! bus | | bus - > getLength ( ) = = 0 ) break ;
2021-01-21 00:21:16 +00:00
JsonObject ins = hw_led_ins . createNestedObject ( ) ;
2021-09-11 23:15:51 +00:00
ins [ " start " ] = bus - > getStart ( ) ;
2022-02-04 09:10:37 +00:00
ins [ " len " ] = bus - > getLength ( ) ;
2021-01-21 00:21:16 +00:00
JsonArray ins_pin = ins . createNestedArray ( " pin " ) ;
uint8_t pins [ 5 ] ;
uint8_t nPins = bus - > getPins ( pins ) ;
2024-05-12 09:12:13 +00:00
for ( int i = 0 ; i < nPins ; i + + ) ins_pin . add ( pins [ i ] ) ;
2021-01-21 00:21:16 +00:00
ins [ F ( " order " ) ] = bus - > getColorOrder ( ) ;
2023-07-06 19:16:29 +00:00
ins [ " rev " ] = bus - > isReversed ( ) ;
2021-05-17 14:23:46 +00:00
ins [ F ( " skip " ) ] = bus - > skippedLeds ( ) ;
2021-10-16 13:13:30 +00:00
ins [ " type " ] = bus - > getType ( ) & 0x7F ;
2021-10-07 20:57:07 +00:00
ins [ " ref " ] = bus - > isOffRefreshRequired ( ) ;
2023-02-14 00:33:06 +00:00
ins [ F ( " rgbwm " ) ] = bus - > getAutoWhiteMode ( ) ;
2023-04-27 22:27:19 +00:00
ins [ F ( " freq " ) ] = bus - > getFrequency ( ) ;
2023-11-15 18:37:07 +00:00
ins [ F ( " maxpwr " ) ] = bus - > getMaxCurrent ( ) ;
ins [ F ( " ledma " ) ] = bus - > getLEDCurrent ( ) ;
2021-01-16 23:20:31 +00:00
}
2020-11-04 10:04:40 +00:00
2021-12-31 20:35:27 +00:00
JsonArray hw_com = hw . createNestedArray ( F ( " com " ) ) ;
2023-12-29 22:07:29 +00:00
const ColorOrderMap & com = BusManager : : getColorOrderMap ( ) ;
2024-05-15 13:35:14 +00:00
for ( size_t s = 0 ; s < com . count ( ) ; s + + ) {
2021-12-31 20:35:27 +00:00
const ColorOrderMapEntry * entry = com . get ( s ) ;
if ( ! entry ) break ;
JsonObject co = hw_com . createNestedObject ( ) ;
2022-02-04 09:10:37 +00:00
co [ " start " ] = entry - > start ;
co [ " len " ] = entry - > len ;
2021-12-31 20:35:27 +00:00
co [ F ( " order " ) ] = entry - > colorOrder ;
}
2021-05-19 16:39:16 +00:00
// button(s)
2020-11-04 10:04:40 +00:00
JsonObject hw_btn = hw . createNestedObject ( " btn " ) ;
2021-05-20 04:45:02 +00:00
hw_btn [ " max " ] = WLED_MAX_BUTTONS ; // just information about max number of buttons (not actually used)
2022-11-26 22:56:55 +00:00
hw_btn [ F ( " pull " ) ] = ! disablePullUp ;
2020-11-04 10:04:40 +00:00
JsonArray hw_btn_ins = hw_btn . createNestedArray ( " ins " ) ;
2021-07-09 14:25:23 +00:00
// configuration for all buttons
2024-05-12 09:12:13 +00:00
for ( int i = 0 ; i < WLED_MAX_BUTTONS ; i + + ) {
2021-07-09 14:25:23 +00:00
JsonObject hw_btn_ins_0 = hw_btn_ins . createNestedObject ( ) ;
2021-05-19 16:39:16 +00:00
hw_btn_ins_0 [ " type " ] = buttonType [ i ] ;
2021-07-09 14:25:23 +00:00
JsonArray hw_btn_ins_0_pin = hw_btn_ins_0 . createNestedArray ( " pin " ) ;
2021-05-19 16:39:16 +00:00
hw_btn_ins_0_pin . add ( btnPin [ i ] ) ;
2021-07-09 14:25:23 +00:00
JsonArray hw_btn_ins_0_macros = hw_btn_ins_0 . createNestedArray ( " macros " ) ;
2021-05-19 16:39:16 +00: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 14:25:23 +00:00
2021-05-19 20:32:50 +00:00
hw_btn [ F ( " tt " ) ] = touchThreshold ;
2021-07-01 18:51:52 +00:00
hw_btn [ " mqtt " ] = buttonPublishMqtt ;
2020-11-04 10:04:40 +00:00
2021-03-20 22:59:17 +00:00
JsonObject hw_ir = hw . createNestedObject ( " ir " ) ;
2024-03-05 15:27:28 +00:00
# ifndef WLED_DISABLE_INFRARED
2021-03-20 22:59:17 +00:00
hw_ir [ " pin " ] = irPin ;
hw_ir [ " type " ] = irEnabled ; // the byte 'irEnabled' does contain the IR-Remote Type ( 0=disabled )
2024-03-05 15:27:28 +00:00
# endif
2022-02-06 23:40:45 +00:00
hw_ir [ " sel " ] = irApplyToAllSelected ;
2020-11-04 10:04:40 +00:00
2021-03-13 21:04:37 +00:00
JsonObject hw_relay = hw . createNestedObject ( F ( " relay " ) ) ;
hw_relay [ " pin " ] = rlyPin ;
2021-03-04 11:10:18 +00:00
hw_relay [ " rev " ] = ! rlyMde ;
2024-04-21 18:02:00 +00:00
hw_relay [ F ( " odrain " ) ] = rlyOpenDrain ;
2021-01-16 23:20:31 +00:00
2022-02-01 19:02:46 +00:00
hw [ F ( " baud " ) ] = serialBaud ;
2022-08-07 14:43:29 +00:00
JsonObject hw_if = hw . createNestedObject ( F ( " if " ) ) ;
JsonArray hw_if_i2c = hw_if . createNestedArray ( " i2c-pin " ) ;
hw_if_i2c . add ( i2c_sda ) ;
hw_if_i2c . add ( i2c_scl ) ;
JsonArray hw_if_spi = hw_if . createNestedArray ( " spi-pin " ) ;
hw_if_spi . add ( spi_mosi ) ;
hw_if_spi . add ( spi_sclk ) ;
2022-08-25 19:57:43 +00:00
hw_if_spi . add ( spi_miso ) ;
2022-08-07 14:43:29 +00:00
2021-01-16 23:20:31 +00:00
//JsonObject hw_status = hw.createNestedObject("status");
2021-03-13 21:04:37 +00:00
//hw_status["pin"] = -1;
2021-01-16 23:20:31 +00:00
2023-12-21 20:30:17 +00:00
JsonObject light = root . createNestedObject ( F ( " light " ) ) ;
2020-11-07 22:54:56 +00:00
light [ F ( " scale-bri " ) ] = briMultiplier ;
light [ F ( " pal-mode " ) ] = strip . paletteBlend ;
2024-08-17 13:09:41 +00:00
light [ F ( " aseg " ) ] = strip . autoSegments ;
2020-11-04 10:04:40 +00:00
JsonObject light_gc = light . createNestedObject ( " gc " ) ;
2023-02-17 19:36:35 +00:00
light_gc [ " bri " ] = ( gammaCorrectBri ) ? gammaCorrectVal : 1.0f ; // keep compatibility
light_gc [ " col " ] = ( gammaCorrectCol ) ? gammaCorrectVal : 1.0f ; // keep compatibility
2023-02-12 12:18:30 +00:00
light_gc [ " val " ] = gammaCorrectVal ;
2020-11-04 10:04:40 +00:00
JsonObject light_tr = light . createNestedObject ( " tr " ) ;
2022-02-04 09:10:37 +00:00
light_tr [ " mode " ] = fadeTransition ;
2023-09-12 04:17:06 +00:00
light_tr [ " fx " ] = modeBlending ;
2021-04-12 19:10:47 +00:00
light_tr [ " dur " ] = transitionDelayDefault / 100 ;
light_tr [ " pal " ] = strip . paletteFade ;
2023-03-25 20:28:30 +00:00
light_tr [ F ( " rpc " ) ] = randomPaletteChangeTime ;
2024-02-06 10:06:23 +00:00
light_tr [ F ( " hrp " ) ] = useHarmonicRandomPalette ;
2020-11-04 10:04:40 +00:00
JsonObject light_nl = light . createNestedObject ( " nl " ) ;
2022-02-04 09:10:37 +00:00
light_nl [ " mode " ] = nightlightMode ;
2021-04-12 19:10:47 +00:00
light_nl [ " dur " ] = nightlightDelayMinsDefault ;
2020-11-07 22:54:56 +00:00
light_nl [ F ( " tbri " ) ] = nightlightTargetBri ;
2021-07-01 18:51:52 +00:00
light_nl [ " macro " ] = macroNl ;
2020-11-04 10:04:40 +00:00
2023-12-21 20:30:17 +00:00
JsonObject def = root . createNestedObject ( " def " ) ;
2021-11-23 12:17:33 +00:00
def [ " ps " ] = bootPreset ;
2020-11-04 10:04:40 +00:00
def [ " on " ] = turnOnAtBoot ;
def [ " bri " ] = briS ;
2023-12-21 20:30:17 +00:00
JsonObject interfaces = root . createNestedObject ( " if " ) ;
2020-11-04 10:04:40 +00:00
JsonObject if_sync = interfaces . createNestedObject ( " sync " ) ;
2020-11-07 22:54:56 +00:00
if_sync [ F ( " port0 " ) ] = udpPort ;
if_sync [ F ( " port1 " ) ] = udpPort2 ;
2020-11-04 10:04:40 +00:00
2023-09-10 16:52:14 +00:00
# ifndef WLED_DISABLE_ESPNOW
if_sync [ F ( " espnow " ) ] = useESPNowSync ;
# endif
2024-02-09 21:15:29 +00:00
JsonObject if_sync_recv = if_sync . createNestedObject ( F ( " recv " ) ) ;
2020-11-04 10:04:40 +00:00
if_sync_recv [ " bri " ] = receiveNotificationBrightness ;
2021-03-13 21:04:37 +00:00
if_sync_recv [ " col " ] = receiveNotificationColor ;
2022-02-20 21:24:11 +00:00
if_sync_recv [ " fx " ] = receiveNotificationEffects ;
2024-09-10 18:02:29 +00:00
if_sync_recv [ " pal " ] = receiveNotificationPalette ;
2021-08-21 10:28:22 +00:00
if_sync_recv [ " grp " ] = receiveGroups ;
2021-12-17 10:22:20 +00:00
if_sync_recv [ " seg " ] = receiveSegmentOptions ;
2022-02-20 21:24:11 +00:00
if_sync_recv [ " sb " ] = receiveSegmentBounds ;
2020-11-04 10:04:40 +00:00
2024-02-09 21:15:29 +00:00
JsonObject if_sync_send = if_sync . createNestedObject ( F ( " send " ) ) ;
2023-09-10 16:52:14 +00:00
if_sync_send [ " en " ] = sendNotifications ;
2020-11-07 22:54:56 +00:00
if_sync_send [ F ( " dir " ) ] = notifyDirect ;
2021-07-01 18:51:52 +00:00
if_sync_send [ " btn " ] = notifyButton ;
if_sync_send [ " va " ] = notifyAlexa ;
if_sync_send [ " hue " ] = notifyHue ;
2021-08-21 10:28:22 +00:00
if_sync_send [ " grp " ] = syncGroups ;
2022-10-18 23:31:23 +00:00
if_sync_send [ " ret " ] = udpNumRetries ;
2020-11-07 22:54:56 +00:00
2024-03-05 15:27:28 +00:00
JsonObject if_nodes = interfaces . createNestedObject ( " nodes " ) ;
2021-03-13 21:04:37 +00:00
if_nodes [ F ( " list " ) ] = nodeListEnabled ;
if_nodes [ F ( " bcast " ) ] = nodeBroadcastEnabled ;
2020-11-07 22:54:56 +00:00
JsonObject if_live = interfaces . createNestedObject ( " live " ) ;
2023-09-10 16:52:14 +00:00
if_live [ " en " ] = receiveDirect ; // UDP/Hyperion realtime
2022-03-25 15:36:05 +00:00
if_live [ F ( " mso " ) ] = useMainSegmentOnly ;
2023-11-23 16:13:13 +00:00
if_live [ F ( " rlm " ) ] = realtimeRespectLedMaps ;
2021-03-13 21:04:37 +00:00
if_live [ " port " ] = e131Port ;
2020-11-07 22:54:56 +00: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 ;
2023-02-21 16:13:15 +00:00
if_live_dmx [ F ( " e131prio " ) ] = e131Priority ;
2020-11-07 22:54:56 +00:00
if_live_dmx [ F ( " addr " ) ] = DMXAddress ;
2022-11-19 13:10:40 +00:00
if_live_dmx [ F ( " dss " ) ] = DMXSegmentSpacing ;
2022-02-04 09:10:37 +00:00
if_live_dmx [ " mode " ] = DMXMode ;
2021-08-19 16:24:41 +00:00
2020-11-07 22:54:56 +00: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 10:04:40 +00:00
2023-09-10 16:52:14 +00:00
# ifndef WLED_DISABLE_ALEXA
2020-11-04 10:04:40 +00:00
JsonObject if_va = interfaces . createNestedObject ( " va " ) ;
2020-11-07 22:54:56 +00:00
if_va [ F ( " alexa " ) ] = alexaEnabled ;
2020-11-04 10:04:40 +00:00
JsonArray if_va_macros = if_va . createNestedArray ( " macros " ) ;
if_va_macros . add ( macroAlexaOn ) ;
if_va_macros . add ( macroAlexaOff ) ;
2021-05-07 09:51:48 +00:00
2022-10-25 21:42:26 +00:00
if_va [ " p " ] = alexaNumPresets ;
2023-09-10 16:52:14 +00:00
# endif
2022-10-25 21:42:26 +00:00
2024-08-15 14:18:34 +00:00
# ifndef WLED_DISABLE_MQTT
2020-11-04 10:04:40 +00:00
JsonObject if_mqtt = interfaces . createNestedObject ( " mqtt " ) ;
2021-03-13 21:04:37 +00:00
if_mqtt [ " en " ] = mqttEnabled ;
2020-11-07 22:54:56 +00:00
if_mqtt [ F ( " broker " ) ] = mqttServer ;
2021-03-13 21:04:37 +00:00
if_mqtt [ " port " ] = mqttPort ;
2020-11-07 22:54:56 +00:00
if_mqtt [ F ( " user " ) ] = mqttUser ;
if_mqtt [ F ( " pskl " ) ] = strlen ( mqttPass ) ;
if_mqtt [ F ( " cid " ) ] = mqttClientID ;
2023-05-28 20:50:19 +00:00
if_mqtt [ F ( " rtn " ) ] = retainMqttMsg ;
2020-11-04 10:04:40 +00:00
2021-03-13 21:04:37 +00:00
JsonObject if_mqtt_topics = if_mqtt . createNestedObject ( F ( " topics " ) ) ;
2020-11-07 22:54:56 +00:00
if_mqtt_topics [ F ( " device " ) ] = mqttDeviceTopic ;
if_mqtt_topics [ F ( " group " ) ] = mqttGroupTopic ;
2021-05-07 09:51:48 +00:00
# endif
2020-11-04 10:04:40 +00:00
2021-05-07 09:51:48 +00:00
# ifndef WLED_DISABLE_HUESYNC
2020-11-04 10:04:40 +00:00
JsonObject if_hue = interfaces . createNestedObject ( " hue " ) ;
2021-03-13 21:04:37 +00:00
if_hue [ " en " ] = huePollingEnabled ;
if_hue [ " id " ] = huePollLightId ;
2020-11-07 22:54:56 +00:00
if_hue [ F ( " iv " ) ] = huePollIntervalMs / 100 ;
2020-11-04 10:04:40 +00:00
2024-02-09 21:15:29 +00:00
JsonObject if_hue_recv = if_hue . createNestedObject ( F ( " recv " ) ) ;
2020-11-04 10:04:40 +00:00
if_hue_recv [ " on " ] = hueApplyOnOff ;
if_hue_recv [ " bri " ] = hueApplyBri ;
2021-03-13 21:04:37 +00:00
if_hue_recv [ " col " ] = hueApplyColor ;
2020-11-04 10:04:40 +00:00
JsonArray if_hue_ip = if_hue . createNestedArray ( " ip " ) ;
2024-07-11 19:22:58 +00:00
for ( unsigned i = 0 ; i < 4 ; i + + ) {
2020-11-04 10:04:40 +00:00
if_hue_ip . add ( hueIP [ i ] ) ;
}
2021-05-07 09:51:48 +00:00
# endif
2020-11-04 10:04:40 +00:00
JsonObject if_ntp = interfaces . createNestedObject ( " ntp " ) ;
2021-03-13 21:04:37 +00:00
if_ntp [ " en " ] = ntpEnabled ;
2020-11-07 22:54:56 +00:00
if_ntp [ F ( " host " ) ] = ntpServerName ;
if_ntp [ F ( " tz " ) ] = currentTimezone ;
if_ntp [ F ( " offset " ) ] = utcOffsetSecs ;
if_ntp [ F ( " ampm " ) ] = useAMPM ;
2021-03-05 22:05:09 +00:00
if_ntp [ F ( " ln " ) ] = longitude ;
if_ntp [ F ( " lt " ) ] = latitude ;
2020-11-04 10:04:40 +00:00
2023-12-21 20:30:17 +00:00
JsonObject ol = root . createNestedObject ( " ol " ) ;
2022-03-06 23:11:43 +00:00
ol [ F ( " clock " ) ] = overlayCurrent ;
2020-11-07 22:54:56 +00:00
ol [ F ( " cntdwn " ) ] = countdownMode ;
2020-11-04 10:04:40 +00:00
2021-04-12 19:10:47 +00:00
ol [ " min " ] = overlayMin ;
2020-12-10 00:28:42 +00:00
ol [ F ( " max " ) ] = overlayMax ;
ol [ F ( " o12pix " ) ] = analogClock12pixel ;
ol [ F ( " o5m " ) ] = analogClock5MinuteMarks ;
ol [ F ( " osec " ) ] = analogClockSecondsTrail ;
2023-10-26 21:36:29 +00:00
ol [ F ( " osb " ) ] = analogClockSolidBlack ;
2020-12-10 00:28:42 +00:00
2023-12-21 20:30:17 +00:00
JsonObject timers = root . createNestedObject ( F ( " timers " ) ) ;
2020-11-04 10:04:40 +00:00
2021-03-13 21:04:37 +00:00
JsonObject cntdwn = timers . createNestedObject ( F ( " cntdwn " ) ) ;
JsonArray goal = cntdwn . createNestedArray ( F ( " goal " ) ) ;
2020-11-04 10:04:40 +00:00
goal . add ( countdownYear ) ; goal . add ( countdownMonth ) ; goal . add ( countdownDay ) ;
goal . add ( countdownHour ) ; goal . add ( countdownMin ) ; goal . add ( countdownSec ) ;
2021-07-01 18:51:52 +00:00
cntdwn [ " macro " ] = macroCountdown ;
2020-11-04 10:04:40 +00:00
JsonArray timers_ins = timers . createNestedArray ( " ins " ) ;
2024-07-11 19:22:58 +00:00
for ( unsigned i = 0 ; i < 10 ; i + + ) {
2021-03-09 12:24:20 +00:00
if ( timerMacro [ i ] = = 0 & & timerHours [ i ] = = 0 & & timerMinutes [ i ] = = 0 ) continue ; // sunrise/sunset get saved always (timerHours=255)
2020-11-04 10:04:40 +00:00
JsonObject timers_ins0 = timers_ins . createNestedObject ( ) ;
2021-03-13 21:04:37 +00:00
timers_ins0 [ " en " ] = ( timerWeekday [ i ] & 0x01 ) ;
2020-11-07 22:54:56 +00:00
timers_ins0 [ F ( " hour " ) ] = timerHours [ i ] ;
2021-04-12 19:10:47 +00:00
timers_ins0 [ " min " ] = timerMinutes [ i ] ;
2021-07-01 18:51:52 +00:00
timers_ins0 [ " macro " ] = timerMacro [ i ] ;
2020-11-07 22:54:56 +00:00
timers_ins0 [ F ( " dow " ) ] = timerWeekday [ i ] > > 1 ;
2021-12-25 17:46:43 +00:00
if ( i < 8 ) {
2022-01-01 15:36:06 +00:00
JsonObject start = timers_ins0 . createNestedObject ( " start " ) ;
2021-12-31 13:09:48 +00:00
start [ " mon " ] = ( timerMonth [ i ] > > 4 ) & 0xF ;
start [ " day " ] = timerDay [ i ] ;
2022-01-01 15:36:06 +00:00
JsonObject end = timers_ins0 . createNestedObject ( " end " ) ;
end [ " mon " ] = timerMonth [ i ] & 0xF ;
2021-12-31 13:09:48 +00:00
end [ " day " ] = timerDayEnd [ i ] ;
2021-12-25 17:46:43 +00:00
}
2020-11-04 10:04:40 +00:00
}
2023-12-21 20:30:17 +00:00
JsonObject ota = root . createNestedObject ( " ota " ) ;
2020-11-07 22:54:56 +00:00
ota [ F ( " lock " ) ] = otaLock ;
ota [ F ( " lock-wifi " ) ] = wifiLock ;
ota [ F ( " pskl " ) ] = strlen ( otaPass ) ;
ota [ F ( " aota " ) ] = aOtaEnabled ;
2020-11-08 22:44:10 +00:00
# ifdef WLED_ENABLE_DMX
2023-12-21 20:30:17 +00:00
JsonObject dmx = root . createNestedObject ( " dmx " ) ;
2020-11-08 22:44:10 +00:00
dmx [ F ( " chan " ) ] = DMXChannels ;
dmx [ F ( " gap " ) ] = DMXGap ;
2021-09-11 23:15:51 +00:00
dmx [ " start " ] = DMXStart ;
2020-11-08 22:44:10 +00:00
dmx [ F ( " start-led " ) ] = DMXStartLED ;
2021-03-13 21:04:37 +00:00
JsonArray dmx_fixmap = dmx . createNestedArray ( F ( " fixmap " ) ) ;
2024-07-11 19:22:58 +00:00
for ( unsigned i = 0 ; i < 15 ; i + + ) {
2020-11-08 22:44:10 +00:00
dmx_fixmap . add ( DMXFixtureMap [ i ] ) ;
2021-11-30 22:10:23 +00:00
}
dmx [ F ( " e131proxy " ) ] = e131ProxyUniverse ;
2020-11-08 22:44:10 +00:00
# endif
2020-11-04 10:04:40 +00:00
2023-12-21 20:30:17 +00:00
JsonObject usermods_settings = root . createNestedObject ( " um " ) ;
2024-09-19 19:44:11 +00:00
UsermodManager : : addToConfig ( usermods_settings ) ;
2020-11-11 14:50:15 +00:00
2024-03-07 19:21:56 +00:00
File f = WLED_FS . open ( FPSTR ( s_cfg_json ) , " w " ) ;
2023-12-23 21:56:07 +00:00
if ( f ) serializeJson ( root , f ) ;
2020-11-06 21:12:48 +00:00
f . close ( ) ;
2021-11-12 22:33:10 +00:00
releaseJSONBufferLock ( ) ;
2022-09-14 20:28:06 +00:00
doSerializeConfig = false ;
2020-11-04 16:17:54 +00:00
}
2024-03-07 19:21:56 +00:00
static const char s_wsec_json [ ] PROGMEM = " /wsec.json " ;
2020-11-04 16:17:54 +00:00
//settings in /wsec.json, not accessible via webserver, for passwords and tokens
2020-11-05 21:54:13 +00:00
bool deserializeConfigSec ( ) {
2020-11-06 21:12:48 +00:00
DEBUG_PRINTLN ( F ( " Reading settings from /wsec.json... " ) ) ;
2021-11-14 15:56:34 +00:00
if ( ! requestJSONBufferLock ( 3 ) ) return false ;
2020-11-04 16:17:54 +00:00
2024-03-07 19:21:56 +00:00
bool success = readObjectFromFile ( s_wsec_json , nullptr , pDoc ) ;
2021-11-03 13:52:22 +00:00
if ( ! success ) {
2021-11-12 22:33:10 +00:00
releaseJSONBufferLock ( ) ;
2021-11-03 13:52:22 +00:00
return false ;
}
2020-11-06 21:12:48 +00:00
2023-12-21 20:30:17 +00:00
JsonObject root = pDoc - > as < JsonObject > ( ) ;
2024-01-20 23:30:15 +00:00
size_t n = 0 ;
JsonArray nw_ins = root [ " nw " ] [ " ins " ] ;
if ( ! nw_ins . isNull ( ) ) {
if ( nw_ins . size ( ) > 1 & & nw_ins . size ( ) > multiWiFi . size ( ) ) multiWiFi . resize ( nw_ins . size ( ) ) ; // resize constructs objects while resizing
for ( JsonObject wifi : nw_ins ) {
char pw [ 65 ] = " " ;
getStringFromJson ( pw , wifi [ " psk " ] , 65 ) ;
strlcpy ( multiWiFi [ n ] . clientPass , pw , 65 ) ;
if ( + + n > = WLED_MAX_WIFI_COUNT ) break ;
}
}
2020-11-04 16:17:54 +00:00
2023-12-21 20:30:17 +00:00
JsonObject ap = root [ " ap " ] ;
2020-11-04 16:17:54 +00:00
getStringFromJson ( apPass , ap [ " psk " ] , 65 ) ;
2023-12-21 20:30:17 +00:00
[[maybe_unused]] JsonObject interfaces = root [ " if " ] ;
2020-11-04 16:17:54 +00:00
2024-08-15 14:18:34 +00:00
# ifndef WLED_DISABLE_MQTT
2021-03-13 21:04:37 +00:00
JsonObject if_mqtt = interfaces [ " mqtt " ] ;
2021-06-29 23:23:35 +00:00
getStringFromJson ( mqttPass , if_mqtt [ " psk " ] , 65 ) ;
2021-05-07 09:51:48 +00:00
# endif
2020-11-04 16:17:54 +00:00
2021-05-07 09:51:48 +00:00
# ifndef WLED_DISABLE_HUESYNC
2021-07-01 18:51:52 +00:00
getStringFromJson ( hueApiKey , interfaces [ " hue " ] [ F ( " key " ) ] , 47 ) ;
2021-05-07 09:51:48 +00:00
# endif
2020-11-05 21:54:13 +00:00
2023-12-21 20:30:17 +00:00
getStringFromJson ( settingsPIN , root [ " pin " ] , 5 ) ;
2022-03-01 22:37:28 +00:00
correctPIN = ! strlen ( settingsPIN ) ;
2023-12-21 20:30:17 +00:00
JsonObject ota = root [ " ota " ] ;
2020-11-07 22:54:56 +00: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 21:12:48 +00:00
2021-11-12 22:33:10 +00:00
releaseJSONBufferLock ( ) ;
2020-11-06 21:12:48 +00:00
return true ;
2020-11-04 16:17:54 +00:00
}
2020-11-05 21:54:13 +00:00
void serializeConfigSec ( ) {
2020-11-06 21:12:48 +00:00
DEBUG_PRINTLN ( F ( " Writing settings to /wsec.json... " ) ) ;
2021-11-14 15:56:34 +00:00
if ( ! requestJSONBufferLock ( 4 ) ) return ;
2020-11-06 21:12:48 +00:00
2023-12-23 21:56:07 +00:00
JsonObject root = pDoc - > to < JsonObject > ( ) ;
2023-12-21 20:30:17 +00:00
JsonObject nw = root . createNestedObject ( " nw " ) ;
2020-11-06 21:12:48 +00:00
JsonArray nw_ins = nw . createNestedArray ( " ins " ) ;
2024-01-20 23:30:15 +00:00
for ( size_t i = 0 ; i < multiWiFi . size ( ) ; i + + ) {
JsonObject wifi = nw_ins . createNestedObject ( ) ;
wifi [ F ( " psk " ) ] = multiWiFi [ i ] . clientPass ;
}
2020-11-06 21:12:48 +00:00
2023-12-21 20:30:17 +00:00
JsonObject ap = root . createNestedObject ( " ap " ) ;
2020-11-06 21:12:48 +00:00
ap [ " psk " ] = apPass ;
2023-12-21 20:30:17 +00:00
[[maybe_unused]] JsonObject interfaces = root . createNestedObject ( " if " ) ;
2024-08-15 14:18:34 +00:00
# ifndef WLED_DISABLE_MQTT
2020-11-06 21:12:48 +00:00
JsonObject if_mqtt = interfaces . createNestedObject ( " mqtt " ) ;
if_mqtt [ " psk " ] = mqttPass ;
2021-05-07 09:51:48 +00:00
# endif
# ifndef WLED_DISABLE_HUESYNC
2020-11-06 21:12:48 +00:00
JsonObject if_hue = interfaces . createNestedObject ( " hue " ) ;
2020-11-07 22:54:56 +00:00
if_hue [ F ( " key " ) ] = hueApiKey ;
2021-05-07 09:51:48 +00:00
# endif
2020-11-06 21:12:48 +00:00
2023-12-21 20:30:17 +00:00
root [ " pin " ] = settingsPIN ;
2022-03-01 22:37:28 +00:00
2023-12-21 20:30:17 +00:00
JsonObject ota = root . createNestedObject ( " ota " ) ;
2020-11-07 22:54:56 +00:00
ota [ F ( " pwd " ) ] = otaPass ;
ota [ F ( " lock " ) ] = otaLock ;
ota [ F ( " lock-wifi " ) ] = wifiLock ;
ota [ F ( " aota " ) ] = aOtaEnabled ;
2020-11-04 16:17:54 +00:00
2024-03-07 19:21:56 +00:00
File f = WLED_FS . open ( FPSTR ( s_wsec_json ) , " w " ) ;
2023-12-23 21:56:07 +00:00
if ( f ) serializeJson ( root , f ) ;
2020-11-06 21:12:48 +00:00
f . close ( ) ;
2021-11-12 22:33:10 +00:00
releaseJSONBufferLock ( ) ;
2020-12-21 20:04:21 +00:00
}