# Firmware presets with Platformio,

**URL:** <https://wled.discourse.group/t/firmware-presets-with-platformio/8626>\
**Category:** Questions\
**Created:** [June 29, 2023, 2:21am UTC](https://wled.discourse.group/t/firmware-presets-with-platformio/8626 "2023-06-29T02:21:55Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Molotochek](https://yyz2.discourse-cdn.com/free1/user_avatar/wled.discourse.group/molotochek/32/5320_2.png) [@Molotochek](https://wled.discourse.group/u/Molotochek)\
**Post date:** [June 29, 2023, 2:21am UTC](https://wled.discourse.group/t/firmware-presets-with-platformio/8626/1 "2023-06-29T02:21:55Z")

</div>

I’m trying to build a bin file in PlatformIO so that after flashing the ESP all the settings are as I need…  
The third day I play, nothing happens. There is very little information on what and where to edit. Or this information is hard for me to reach. Don’t know. There would be a video on how to customize the firmware for yourself, it would be cool. Can someone teach me how to set up the items that I have indicated below and how to add a preset to autoload?

**LED & Hardware setup**

- 

> [@](#):
>
> Enable automatic brightness limiter: ❌

**Hardware setup**

- 

> [@](#):
>
> **LED outputs 1:** 🚾2️⃣ 8️⃣ 1️⃣ #️⃣

- 

> [@](#):
>
> **Color Order:** 🟥 🟩 🟦

- 

> [@](#):
>
> **Start** : 0️⃣

- 

> [@](#):
>
> **Length** : 6️⃣ 0️⃣ 0️⃣

- 

> [@](#):
>
> **GPIO** : 5️⃣

- 

> [@](#):
>
> **Button 0 GPIO:** 0️⃣ **- Pushbutton**

**Defaults**

- 

> [@](#):
>
> **Turn LEDs on after power up/reset:** ✅

- 

> [@](#):
>
> **Default brightness:** 2️⃣ 5️⃣ 5️⃣ **(0-255)**

- 

> [@](#):
>
> **Apply preset:** 1️⃣**at boot (0 uses defaults)**

_This is a preset API that should run when the controller is turned on._

**Preset No. 1**  
_API comand_

```auto
{"transition":0,"on":true,"tb":0,"bri":255,"mainseg":0,"seg":[{"id":0,"start":0,"stop":600,"grp":1,"spc":0,"of":0,"on":true,"frz":false,"bri":255,"cct":127,"col":[[255,255,255],[0,0,0],[0,0,0]],"fx":98,"sx":8,"ix":98,"pal":0,"sel":true,"rev":false,"mi":false},{"stop":0},{"stop":0},{"stop":0},{"stop":0},{"stop":0},{"stop":0},{"stop":0},{"stop":0},{"stop":0},{"stop":0},{"stop":0},{"stop":0},{"stop":0},{"stop":0},{"stop":0}]}
```

---

<div class="post-metadata">

**Author:** ![tonyno](https://yyz2.discourse-cdn.com/free1/user_avatar/wled.discourse.group/tonyno/32/242_2.png) [@tonyno](https://wled.discourse.group/u/tonyno)\
**Post date:** [June 29, 2023, 3:50pm UTC](https://wled.discourse.group/t/firmware-presets-with-platformio/8626/2 "2023-06-29T15:50:32Z")

</div>

It would be much easier to configure a unit then clone it to the others.

---

<div class="post-metadata">

**Author:** ![Molotochek](https://yyz2.discourse-cdn.com/free1/user_avatar/wled.discourse.group/molotochek/32/5320_2.png) [@Molotochek](https://wled.discourse.group/u/Molotochek)\
**Post date:** [June 29, 2023, 5:11pm UTC](https://wled.discourse.group/t/firmware-presets-with-platformio/8626/3 "2023-06-29T17:11:32Z")

</div>

I want to put a controller in my mom’s house. I don’t live there. If the device freezes and you will need to do a hard reset (holding the 0 button). She will have to do all the settings on a new one? She won’t be able to do it. So it would be convenient to flash the controller with an already configured firmware.

---

<div class="post-metadata">

**Author:** ![Molotochek](https://yyz2.discourse-cdn.com/free1/user_avatar/wled.discourse.group/molotochek/32/5320_2.png) [@Molotochek](https://wled.discourse.group/u/Molotochek)\
**Post date:** [June 29, 2023, 5:54pm UTC](https://wled.discourse.group/t/firmware-presets-with-platformio/8626/4 "2023-06-29T17:54:44Z")

</div>

Am I on the right track?

wled00/wled.h (line 327 // LED CONFIG)

---

<div class="post-metadata">

**Author:** ![tonyno](https://yyz2.discourse-cdn.com/free1/user_avatar/wled.discourse.group/tonyno/32/242_2.png) [@tonyno](https://wled.discourse.group/u/tonyno)\
**Post date:** [June 30, 2023, 12:46am UTC](https://wled.discourse.group/t/firmware-presets-with-platformio/8626/5 "2023-06-30T00:46:10Z")

</div>

That’s one place and there are others. Some things cannot be set when building. This is why I suggested setting one up and cloning it.

---

<div class="post-metadata">

**Author:** ![Molotochek](https://yyz2.discourse-cdn.com/free1/user_avatar/wled.discourse.group/molotochek/32/5320_2.png) [@Molotochek](https://wled.discourse.group/u/Molotochek)\
**Post date:** [June 30, 2023, 10:25am UTC](https://wled.discourse.group/t/firmware-presets-with-platformio/8626/6 "2023-06-30T10:25:33Z")

</div>

What I have done so far…

> [@Molotochek](#):
>
> **Enable automatic brightness limiter:** ❌

Along the way wled00\data\settings\_leds.htm found a form. I see that there is an input type = “checkbox”, but I still don’t understand how to remove the checkbox. I also did not find which one to put build\_flags in platformio\_override.ini . Found only -D ABL\_MILLIAMPS\_DEFAULT=  
But this is a current limit, not a mode shutdown.

> [@Molotochek](#):
>
> **LED outputs 1:** 🚾 2️⃣ 8️⃣ 1️⃣ #️⃣

This option is already set by default.

> [@](#):
>
> **Color Order:** 🟥🟩🟦

platformio\_override.ini – build\_flags – -D DEFAULT\_LED\_COLOR\_ORDER=1

> [@](#):
>
> **Length** 6️⃣ 0️⃣ 0️⃣

platformio\_override.ini – build\_flags – -D DEFAULT\_LED\_COUNT=600  
“Wled.h” – #define DEFAULT\_LED\_COUNT 600  
“Wled.h” – WLED\_GLOBAL byte overlayMin \_INIT(0), overlayMax \_INIT(DEFAULT\_LED\_COUNT - 600);

> [@](#):
>
> **GPIO** 5️⃣

platformio\_override.ini – build\_flags – -D LEDPIN=5

> [@](#):
>
> **Button0 GPIO:** 0️⃣ **- Pushbutton**

platformio\_override.ini – build\_flags – -D BTNPIN=0

> [@Molotochek](#):
>
> **Turn LEDs on after power up/reset:** ✅

“Wled.h” – WLED\_GLOBAL bool turnOnAtBoot \_INIT(true);

> [@Molotochek](#):
>
> **Default brightness:** 2️⃣ 5️⃣ 5️⃣ **(0-255)**

“Wled.h” – WLED\_GLOBAL byte briS \_INIT(255);

> [@Molotochek](#):
>
> **Apply preset** 1️⃣ **at boot (0 uses defaults)**

“Wled.h” – WLED\_GLOBAL byte bootPreset \_INIT(1);

\*\*It remains to find point 1. and add the preset API.  
**Preset No. 1**  
_API comand_

```auto
{"transition":0,"on":true,"tb":0,"bri":255,"mainseg":0,"seg":[{"id":0,"start":0,"stop":600,"grp":1,"spc":0,"of":0,"on":true,"frz":false,"bri":255,"cct":127,"col":[[255,255,255],[0,0,0],[0,0,0]],"fx":98,"sx":8,"ix":98,"pal":0,"sel":true,"rev":false,"mi":false},{"stop":0},{"stop":0},{"stop":0},{"stop":0},{"stop":0},{"stop":0},{"stop":0},{"stop":0},{"stop":0},{"stop":0},{"stop":0},{"stop":0},{"stop":0},{"stop":0},{"stop":0}]}
```

**ere to add it API, I have no idea!**

---

<div class="post-metadata">

**Author:** ![blazoncek](https://yyz2.discourse-cdn.com/free1/user_avatar/wled.discourse.group/blazoncek/32/1886_2.png) [@blazoncek](https://wled.discourse.group/u/blazoncek)\
**Post date:** [July 16, 2023, 6:10am UTC](https://wled.discourse.group/t/firmware-presets-with-platformio/8626/7 "2023-07-16T06:10:23Z")

</div>

Why don’t you just upload cfg.json after a device is set up? Or prepare a LittleFS file system and upload/flash it to device after flashing a binary?

Unless you want to keep maintaining custom binary it is best to use prepared config files and upload them during flashing or set-up of devices. Or using backup/restore functionality built into WLED.

---

<div class="post-metadata">

**Author:** ![Molotochek](https://yyz2.discourse-cdn.com/free1/user_avatar/wled.discourse.group/molotochek/32/5320_2.png) [@Molotochek](https://wled.discourse.group/u/Molotochek)\
**Post date:** [August 9, 2023, 8:34pm UTC](https://wled.discourse.group/t/firmware-presets-with-platformio/8626/8 "2023-08-09T20:34:25Z")

</div>

I explain once again why I need it (already asked above).  
I made lighting in my mom’s house. I live in another city, far from her. The operation of the controller is set up as follows: when the light is turned on, preset No. 1 starts (the LEDs of the tape begin to sequentially fill in white). As soon as all the LEDs are filled, preset No. 2 is turned on (this is the Solid mode, all the LEDs on the tape shine evenly until you turn off the light). So, it happens that the controller freezes and only a factory reset helps when the button is pressed\> 10 seconds. After that, you need to restore the settings  
“cfg.json” and “presets.json”, mom can’t do that. So I want to register all the settings in the development environment and compile the firmware so that when resetting to the factory settings with the button, the controller reboots and my settings are already in the file system.

---

<div class="post-metadata">

**Author:** ![blazoncek](https://yyz2.discourse-cdn.com/free1/user_avatar/wled.discourse.group/blazoncek/32/1886_2.png) [@blazoncek](https://wled.discourse.group/u/blazoncek)\
**Post date:** [August 10, 2023, 10:06am UTC](https://wled.discourse.group/t/firmware-presets-with-platformio/8626/9 "2023-08-10T10:06:38Z")

</div>

When you do “factory reset” all flash data (file system) is erased. None of the presets will survive that and you cannot “compile them into source code”.  
For configuration, some settings you can define at compile time, but not all. You will need to check source files to see what can be redefined at compile time. Start with `wled.h` and `const.h`. There are also usermod `.h` files as well as a few other core files.

What you can do to help yourself is create a usermod that will play certain effects as you want them. This will survive any factory reset.

Apart from that, consider creating a VPN connection or password protected reverse proxy at your mom’s place to help her with WLED issues.

And finally I have about 20+ devices at home and about 10 at friends and relatives. None of them required a factory reset in 2-3 years they are in use. I would suspect something is wrong with your hardware or other environment setting. If you’ve modified code (I suspect you did) then start revising those changes.

---

<div class="post-metadata">

**Author:** ![Molotochek](https://yyz2.discourse-cdn.com/free1/user_avatar/wled.discourse.group/molotochek/32/5320_2.png) [@Molotochek](https://wled.discourse.group/u/Molotochek)\
**Post date:** [August 11, 2023, 10:40am UTC](https://wled.discourse.group/t/firmware-presets-with-platformio/8626/10 "2023-08-11T10:40:04Z")

</div>

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Hey Blaz!  
Everything is fine with the code. I live in Ukraine, and here moronic neighbors launch rockets at us.  
Since winter, these freaks have been hitting all our electrical substations with rockets. Here, household appliances do not withstand power surges and burn out, what can we say about the controller freezing, it’s strange that it works at all. Such are the things.

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Do you suspect that I have changed the program code? 😉  
Of course I changed it! Why else would I start this thread?  
The main thing that I understood, before climbing into the development environment, do not forget to create a backup copy. 😉

I’m currently tinkering with version WLED\_0.14.0-b1, my tape is WS2815. I thought that I would now quickly set the default LED type to “WS2815 (12 mA)” and disable “ABL” by unchecking the checkbox.  
But after looking at the code, I realized that there was no need to rush. The ABL function was twisted there with the types of LEDs in such a way that I still cannot fully track its operation. They probably made it so that the currents corresponded to the tapes and there were no preloads. In general, I still have to contend with her )))

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

> [@blazoncek](#):
>
> “factory reset”, all flash memory (file system) data is erased. None of the presets will survive this and you won’t be able to “compile them to source”

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Well, I would not be so categorical!  
I remember that I wrote to you and the guys from the chat on discord that I could compile with presets and that the presets would not fall off with a Factory reset. It just needs a little time.

Let’s make it so that I am not a balabol, I will now compile the firmware for you (although I have not yet fully configured it for myself, but that is already cosmetic trifles and they do not apply to presets)  
Flash the device, reload, on the Main page you will see the added presets. Go to the “Security & Update” tab and click “Factory reset” \> “SAVE”. After the reboot, you will see the presets in their places.

You can even do this:  
Flash, go to the Main page, Delete all presets. They will be removed…  
Do a “Factory reset” and after the reboot, the presets will again be in their places.

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

---

<div class="post-metadata">

**Author:** ![blazoncek](https://yyz2.discourse-cdn.com/free1/user_avatar/wled.discourse.group/blazoncek/32/1886_2.png) [@blazoncek](https://wled.discourse.group/u/blazoncek)\
**Post date:** [August 11, 2023, 12:23pm UTC](https://wled.discourse.group/t/firmware-presets-with-platformio/8626/11 "2023-08-11T12:23:28Z")

</div>

I am very sorry for you and all of the people of Ukraine. War is a terrible thing.

As for the WLED I can only describe what standard version does.  
But it looks you do not care or do not want to listen.

The “factory reset” is just an erase function and yes, you can change that so that files persist in your own fork.  
You can of course also add whatever you want to boot procedure as WLED is OSS for the people that want to tinker.

I hope you will have much success with adapting WLED to accommodate your needs. And my heart is with you for the war to end soon. God bless.

---

<div class="post-metadata">

**Author:** ![Molotochek](https://yyz2.discourse-cdn.com/free1/user_avatar/wled.discourse.group/molotochek/32/5320_2.png) [@Molotochek](https://wled.discourse.group/u/Molotochek)\
**Post date:** [August 12, 2023, 2:06am UTC](https://wled.discourse.group/t/firmware-presets-with-platformio/8626/12 "2023-08-12T02:06:49Z")

</div>

> [@blazoncek](#):
>
> As for the WLED I can only describe what standard version does.  
> But it looks you do not care or do not want to listen.

Blaz, I’m listening to you carefully. And I perfectly understand what the “Factory reset” command does.

I was just interested in the question of how to bypass the cleaning of the preset. I am not a programmer and it is difficult for me to understand the program code, but it is very interesting!  
I have this controller installed only to turn on the light beautifully. Any flashing lights, whistles, I don’t need them there. Essentially, I only need one preset/effect at the time of on.

In the “presets.cpp” file, I saw that when the device is loaded, the program checks the file system for the presence of the “presets.json” file, and if it does not exist, it creates it with a null object value.  
I decided to write a line with the objects of my preset to this file.

Here is the code that I added to the “presets.cpp” file

```auto
  void initPresetsFile() {
  if (WLED_FS.exists(getFileName())) return;

  // Create a JSON object for our initial preset
  
  StaticJsonDocument<2048> doc;
  JsonObject sObj = doc.to<JsonObject>();
  
  // Code for preset # 0
  
  JsonObject presetObj = sObj.createNestedObject("0");
  presetObj[""] = "";

  // Code for preset # 1

  JsonObject presetObj1 = sObj.createNestedObject("1");
  presetObj1["tb"] = 0;
  presetObj1["on"] = true;
  presetObj1["bri"] = 255;
  presetObj1["transition"] = 7;
  presetObj1["mainseg"] = 0;
  presetObj1["n"] = "Start";
  JsonArray segArray = presetObj1.createNestedArray("seg");

  JsonObject segObj1 = segArray.createNestedObject();
  segObj1["id"] = 0;
  segObj1["start"] = 0;
  segObj1["stop"] = 300;
  segObj1["grp"] = 1;
  segObj1["spc"] = 0;
  segObj1["of"] = 0;
  segObj1["on"] = true;
  segObj1["frz"] = false;
  segObj1["bri"] = 255;
  segObj1["cct"] = 127;

  JsonArray colArray = segObj1.createNestedArray("col");
  JsonArray innerArray1 = colArray.createNestedArray();
  innerArray1.add(255);
  innerArray1.add(255);
  innerArray1.add(255);

  JsonArray innerArray2 = colArray.createNestedArray();
  innerArray2.add(0);
  innerArray2.add(0);
  innerArray2.add(0);

  JsonArray innerArray3 = colArray.createNestedArray();
  innerArray3.add(255);
  innerArray3.add(255);
  innerArray3.add(255);

  segObj1["fx"] = 98;
  segObj1["sx"] = 20;
  segObj1["ix"] = 100;
  segObj1["pal"] = 0;
  segObj1["sel"] = true;
  segObj1["rev"] = false;
  segObj1["mi"] = false;
  
  // Add objects {"stop": 0} for preset # 1

  for (int i = 0; i < 15; i++) {
   JsonObject segObj1_stop = segArray1.createNestedObject();
   segObj1_stop["stop"] = 0;
  }

  // Create a "presets.json" file and write the JSON object into it

  File f = WLED_FS.open(getFileName(), "w");
   if (!f) {
    errorFlag = ERR_FS_GENERAL;
    return;
  }
   serializeJson(doc, f);
   f.close();

  // Free the memory used for the JSON object
  
  doc.clear();

```

  
So far everything is working fine. It turns out that I hardcore my preset into the firmware. Could you please tell me if this approach has the right to exist? It seems like there should be no problems in further work?

> [@blazoncek](#):
>
> I hope you will have much success with adapting WLED to accommodate your needs. And my heart is with you for the war to end soon. God bless.

**Thanks for support!  
Glory to Ukraine!**

---

<div class="post-metadata">

**Author:** ![viktor6](https://yyz2.discourse-cdn.com/free1/user_avatar/wled.discourse.group/viktor6/32/8811_2.png) [@viktor6](https://wled.discourse.group/u/viktor6)\
**Post date:** [November 16, 2024, 8:27am UTC](https://wled.discourse.group/t/firmware-presets-with-platformio/8626/13 "2024-11-16T08:27:58Z")

</div>

How else can I add a playlist?

```auto
{
    "0": {},
    "1": {
        "on": true,
        "bri": 125,
        "transition": 7,
        "mainseg": 0,
        "seg": [{
                "id": 0,
                "start": 0,
                "stop": 100,
                "grp": 1,
                "spc": 0,
                "of": 0,
                "on": true,
                "frz": false,
                "bri": 255,
                "cct": 127,
                "set": 0,
                "col": [[255, 160, 0], [0, 0, 0], [0, 0, 0]],
                "fx": "r",
                "sx": 128,
                "ix": 128,
                "pal": 0,
                "c1": 128,
                "c2": 128,
                "c3": 16,
                "sel": true,
                "rev": false,
                "mi": false,
                "o1": false,
                "o2": false,
                "o3": false,
                "si": 0,
                "m12": 1
            }
        ],
        "n": "AllRandomPreset"
    },
    "2": {
        "playlist": {
            "ps": [1],
            "dur": [300],
            "transition": [30],
            "repeat": 0,
            "end": 0,
            "r": 0
        },
        "on": true,
        "n": "AllRandomPlaylist"
    }
}

```
