Hello- I'm trying to send 3 Integers from an Esp32 Controller to an Esp32 Receiver. I'm having a hard time understanding how to identify each Integer, so that the Receiver interprets them in the correct order. Do I need to send some kind of identifier with each Integer? I'm sending these 3 Integers every millisecond.
Controller code:
Serial.println(Int1);
Serial.println(Int2);
Serial.println(Int3);
The Receiver code uses Serial.parseInt() to identify a received Integer. Question: How should the Receiver check each Integer, to make sure it is the intended one, and doesn't confuse Int1 with Int2, etc? For example, the Receiver code might start executing at Int2, and therefore reading the first Integer with Serial.parseInt() would return Int2 and not Int1. Therefore it is important to identify the start and end of each message, and receive each Integer in order. Any help with this would be greatly appreciated.
Serial Communication: Sending 3 Integers
-
- Posts: 167
- Joined: Sun May 22, 2022 2:42 pm
Re: Serial Communication: Sending 3 Integers
That's what framing protocols are for. For payloads small as these, I'd use json on the serial console.
-
- Posts: 826
- Joined: Mon Jul 22, 2019 3:20 pm
Re: Serial Communication: Sending 3 Integers
yep, json, or send them all as a single record with a defined structure.
Code: Select all
Serial.printf("%d\t%d\t%d\n", Int1, Int2, Int3);
Re: Serial Communication: Sending 3 Integers
Thanks for the help. I've never used Json before, but I'm looking into it now. Question: is there a speed limit when sending Integers like this between boards using serial communication? For example, could I send/receive 3 Integers every 10 microseconds if I wanted to? At what point would the communication start to fail, or messages get dropped? Also, does the distance between the boards matter? Ideally I want to place the boards about 15 ft apart.
-
- Posts: 167
- Joined: Sun May 22, 2022 2:42 pm
Re: Serial Communication: Sending 3 Integers
You can easily compute how long it takes to send your data, you have all the variables like UART bitrate and number of bits to send, etc.
Who is online
Users browsing this forum: No registered users and 56 guests