Firmware presets with Platformio,

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

Hardware setup

Defaults

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

Preset No. 1
API comand

{"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}]}

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

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.

Am I on the right track?

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

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.

What I have done so far…

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.

This option is already set by default.

platformio_override.ini – build_flags – -D DEFAULT_LED_COLOR_ORDER=1

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);

platformio_override.ini – build_flags – -D LEDPIN=5

platformio_override.ini – build_flags – -D BTNPIN=0

“Wled.h” – WLED_GLOBAL bool turnOnAtBoot _INIT(true);

“Wled.h” – WLED_GLOBAL byte briS _INIT(255);

“Wled.h” – WLED_GLOBAL byte bootPreset _INIT(1);

**It remains to find point 1. and add the preset API.
Preset No. 1
API comand

{"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!

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.

1 Like

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.

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.

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

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? :wink:
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. :wink:

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 )))

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

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

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.

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

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.

1 Like

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

  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?

Thanks for support!
Glory to Ukraine!

How else can I add a playlist?

{
    "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"
    }
}