Help with two-way long-range wireless communication between two ESP32s

Thread Starter

mva007

Joined Oct 26, 2021
12
My current setup involves sending-receiving few variable values, implemented using a struct variable, wirelessly between two ESP32s which are both physically present in the same room, using ESPNow. Each data is sent/rx at an interval of 15ms. This setup is working flawlessly for me. I'm also heavily using the callback functions of ESPNow both at data transmission and reception.

Following is the actual struct variable that is being sent and rx b/w the two boards:
Capture.PNG


However my new setup requires the two ESP32 boards to be present in different rooms at different floors of the building.

My question is, which communication protocol should I use now in my new setup for the same wireless communication requirements between the two boards?
- Is there a way I can still use ESPNow but with some sort of extended range?
- Is this possible using WiFi? But won't this create a problem of change in IP address at each power-on/off of either of the two boards?
- Is there any other method?

To reiterate my requirements:
- Two-way long-range wireless communication b/w 2 ESP32s
- Sending multiple variable values at a time
- Min. data transmission interval of 15ms
- Availability of callback function
- Can be coded in Arduino IDE

Please try to provide relevant tutorials/codes/documentation for the solution that you will be suggesting.
Also ask me any further details you require to answer my query.

Thanks in advance!
 

Ya’akov

Joined Jan 27, 2019
9,079
Welcome to AAC.

If you can live with the possibility of lost samples, ESPNow broadcast mode with a larger antenna on the receiver side might work.
 

Thread Starter

mva007

Joined Oct 26, 2021
12
Welcome to AAC.

If you can live with the possibility of lost samples, ESPNow broadcast mode with a larger antenna on the receiver side might work.
Well I actually cannot loose samples. Is there a way to achieve a communication channel between the 2 ESPs connected to a LAN in station mode?
 

Ya’akov

Joined Jan 27, 2019
9,079
Well I actually cannot loose samples. Is there a way to achieve a communication channel between the 2 ESPs connected to a LAN in station mode?
Certainly you could use WiFi, my only concern would be latency. You’d probably need to use a dedicated AP and it would be best if you used UDP instead of TCP to reduce the overhead. While there is a chance of losing a packet with UDP since it has no guaranteed delivery, on a dedicated AP it is very unlikely. UDP avoids the overhead of TCP.
 

Thread Starter

mva007

Joined Oct 26, 2021
12
Certainly you could use WiFi, my only concern would be latency. You’d probably need to use a dedicated AP and it would be best if you used UDP instead of TCP to reduce the overhead. While there is a chance of losing a packet with UDP since it has no guaranteed delivery, on a dedicated AP it is very unlikely. UDP avoids the overhead of TCP.
I tested the bare minimum code for UDP and I was able to communicate between the 2 ESPs but there was some packet loss. I sent 1000 packets and I was loosing around 30 with a delay b/w consecutive packets of 20ms and around 15 with a 30ms delay.

Since the two ESPs were kept in different rooms, the packets must be routing through multiple routers( I think atleast 1/2 routers between the source and destination router), FYI I was using my university WiFi.

So is there anything else I can do other than trial-error with increasing this delay in-between sending the packets, to reduce {ideally 0 :) } packet loss?

I want a 0 packet loss in UDP because in ESP-NOW, which is also connectionless protocol, I was able to get 0 packet loss. Is this even possible in UDP practically, or am I looking at the wrong algorithm here!

I took the code from here and modified it do my UDP tests: https://Ajaynirmal@bitbucket.org/Ajaynirmal/workspace/snippets/XLr6Bj/udp_communication_ajay_r
 

Ya’akov

Joined Jan 27, 2019
9,079
The reason for 0 packet loss in ESP-Now was the signal strength. As the RSSI got smaller, you would start to see dropped packets. In the case of UDP it would be contention for the router. That’s one reason I said it would require a dedicated router, the other being you latency requirement. I am not Sure your requirements can be practically met using the hardware you have.

While UDP doesn’t offer guaranteed delivery, it is also can be lossless. You just need to ensure that the channel is not loaded more than it can tolerate. Your university network is not going to provide that (except possibly late at night). This would normally be handled with retries, but your latency requirement makes that impractical.
 

Thread Starter

mva007

Joined Oct 26, 2021
12
I found a probable solution using TCP-Websockets in client-server configuration. The TCP ensures no data is lost and Websockets enables server to send data to the client without being requested for.

I have tested the link by placing the two ESPs in separate rooms, making sure the data gets routed via at least two routers and sent test data in JSON format.

Sharing the necessary links here, hope these will be of help to somebody out there...

Code repo link: https://github.com/mo-thunderz/Esp32toEsp32JsonCommunication
Library repo link: https://github.com/Links2004/arduinoWebSockets
 
Top