Little more detail required on segments and individual LED control using JSON

Sorry - I wanted to do some more experimentation to rule out obvious problems before posting here - so had a weird double post, apologies!

Hi I am trying to create a controller program that could do with some control over individual LEDs within segments using JSON. I am using C# to create a program to do some advanced control of WLED to support a fully interactive games table. [I will post details in Projects & source once I get closer to completion!]. Also note, I am relatively new to this type of programming so my questions may be a little naĂŻve.

I would like to use the JSON API for individual LED control to manage player info bars so I don’t need to create my own branch; easier for maintainability and easy adoption by others.

Normally to use JSON I construct a data class and use C# functionality to serialise/deserialise between the two. However I am finding it hard to work out the data class for individual LED control so just manage that manually; it works but I am having difficulty targeting a segment id as the documentation here is a little lacking in that area. It could do with an extended sample JSON example.

These work fine:

{"seg":{"i":[10,20,[255,0,0],50,60,[0,128,0],110,120,[0,0,255]]}}
{"seg":[{"i":[10,20,[255,0,0],50,60,[0,128,0],110,120,[0,0,255]]}]}

It just targets the first segment - i.e. 0. However when I try to target other segments I cannot work out how to insert the id into the JSON request. These targeting segment 1 seem to either create exceptions:

{"seg":{"i":["id":1,10,20,[255,0,0],50,60,[0,128,0],110,120,[0,0,255]]}}
{"seg":1,{"i":[10,20,[255,0,0],50,60,[0,128,0],110,120,[0,0,255]]}}

Or provides a good OK response but does nothing at all:

{"seg":[{"id":1,"i":[10,20,[255,0,0],50,60,[0,128,0],110,120,[0,0,255]]}]}

So obviously I am not “getting” how segments can be targeted properly. Hopefully a quick example can help me. Thanks!

If one of those ARE meant to work (e.g.: the last one, which does seem almost sensible) then perhaps I am missing something else; eg: a pre-requisite to establish the segment under normal use first. Or I cannot target an individual segment, I always have to provide a list of all segment data sequentially. Any help would be useful. Thanks in advance!

1 Like

If you want to set both segment, do this:

{"seg": [{"i":[10,20,[255,0,0],50,60,[0,128,0],110,120,[0,0,255]]},
	     {"i":[10,20,[255,0,0],50,60,[0,128,0],110,120,[0,0,255]]}]
}

If you only want to set the second segment, do this:

{"seg": [{}, {"i":[10,20,[255,0,0],50,60,[0,128,0],110,120,[0,0,255]]}]}

Many thanks, Artacus. That should sort me out nicely. I thought you could directly address a segment with an id… that was where I went wrong. Should be easy enough to work around!

Thanks again!

@frunk I think your last one should work
{"seg":[{"id":1,"i":[10,20,[255,0,0],50,60,[0,128,0],110,120,[0,0,255]]}]}
something similar kind of works for me
{"seg":[{"id":3,"i":[1,2,[0,0,255]]}]}
this sets the 1st 2 LEDs to blue on segment 4 (starting from 1).
The reason I say kind of works is that the LEDs are dim, I’ve tried setting brightness in several different ways and can’t figure out why, I came across this when I was looking for info on what I might be doing wrong.
I also tried how @Artacus suggested using {}, for each segment I didn’t care about, and the brightness is the same as when I include id to pick the segment.