Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wled json api over serial communication problems #2557

Closed
miwied opened this issue Feb 23, 2022 · 4 comments
Closed

wled json api over serial communication problems #2557

miwied opened this issue Feb 23, 2022 · 4 comments
Labels

Comments

@miwied
Copy link

miwied commented Feb 23, 2022

Hello guys and especially @Aircoookie !

my setup:

I have a "main mcu" (which is a esp32) that shall control the "wled mcu" (esp8266 d1 mini) via serial communication.
I use the WLED-0.13.0-b6 version. I compiled it myself and changed the Serial baudrate to 921600, hoping to improve serial communication.

current state:

I experimented with the json api over serial now for about 5 days, and after some success I stuck on an annoying problem / (bug?).
The communication itself works but not ALL JSON objects arrive at the wled mcu.
I've read about a "verboseResponse mode" which sometimes blocks the serial input, but I think that this is not the case with my setup.

the problem:

Unfortunately, despite successfully sending a json package, sometimes the expected change does not occur. (The package doesn't seem to be received).

demo / test code

Here you can see a very simple demo code which I wrote for sending the JSON objects:
https://github.com/miwied/wled-json-api-over-serial

Do u guys have some ideas what the problem could be and how I could fix it?
I've already had read #1173 and #1146 but unfortunately it didn't help me.

@Aircoookie
Copy link
Owner

Aircoookie commented Feb 23, 2022

Hey!
Is the color what is not applied correctly?
It seems like your code is sending e.g. {"on":true,"bri":110,"seg":[{"col":[255,255,255]}]} while it should be {"on":true,"bri":110,"seg":[{"col":[[255,255,255]]}]} (one more nested array for the color).
Otherwise, your 192 byte static JSON buffer is kind of small, once you want to send larger messages with multiple segments you need to increase it (see https://arduinojson.org/v6/assistant/ which tells you the size you need depending on what JSON you want to send)

@miwied
Copy link
Author

miwied commented Feb 23, 2022

@Aircoookie Thank you for your prompt reply!

Is the color what is not applied correctly?

Nothing is applied at all when this error occurs. Nothing changes.

https://arduinojson.org/v6/assistant/

Indeed I was using this tool for this sketch.

If I copy ur JSON object

{"on":true,"bri":110,"seg":[{"col":[[255,255,255]]}]}

and then paste it into the assistant, the code is exactly the same as I used.

StaticJsonDocument<192> doc;

doc["on"] = true;
doc["bri"] = 110;

JsonArray seg_0_col_0 = doc["seg"][0]["col"].createNestedArray();
seg_0_col_0.add(255);
seg_0_col_0.add(255);
seg_0_col_0.add(255);

serializeJson(doc, output);

@miwied
Copy link
Author

miwied commented Mar 8, 2022

Problem solved!

( @Aircoookie )
I can't exactly say why, but when I used the HardwareSerial instead of the SoftwareSerial, the communication works without any problems and without any input lag (exactly what I wanted). This solved the problem for me :)

Checkout my simple demo code if you want to use the json api over serial too:
https://github.com/miwied/wled-json-api-over-serial

@miwied miwied closed this as completed Mar 8, 2022
@Aircoookie
Copy link
Owner

Nice! SoftwareSerial is only suitable for very slow baud rates, definitely not 921600 in most cases. You should always use HW serial if possible, and in case SoftwareSerial is indispensable, use the lowest possible rate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants