Communication between devices that doesn’t require a server
Why would you you want to have your Arduino’s, ESP8266 and ESP32 devices to be able to communicate to each other without using a central server?
Simple, a central server can fail, or, if the server is not on the local network, the connection to the server can be interrupted (no internet connection).
This can have a negative impact on anyone who needs regular access to the internet, especially to the people who are working in a business setting. On saying that, they can always look for better connectivity solutions, like those you can find at Fusion Connect, (https://www.fusionconnect.com/products/connectivity/t1/) so they don’t have to worry about problems concerning their server or network. No one likes the idea of having no internet connection.
So for my home control system I defined in the requirements that devices should be able to communicate with each other without the need of a server. I think you can call that a multi-point bi-directional communication without a central server.
Assuming we have 5 sensor/actuator devices and 2 control devices in the system the communication would look like
Ouch, that looks complicated. How to handle all these different connections?
Looking on the 7 blocks in the diagram, 5 devices are sensors/actuators and should send out there status to everyone else. 2 devices are control devices and should listen to all status messages.
Using UDP broadcast, the sending part can be solved easy. UDP broadcast means that a data packet is sent over the local network with an IP mask instead of an IP address. So instead of sending an UDP packet to 192.168.1.321, the packet is sent to 192.168.1.255. This mask means that all devices in the IP address range of 192.168.1.0 to 192.168.1.254 can receive this packet, if they are listening to the matching port number.
So the sending part looks like
Each sensor/actuator device broadcasts its status and 2 (or more) control devices listen to this broadcasts.
Now this looks already simpler. For communication of commands, each sensor/actuator device opens a TCP server (not a web server !!! that would be too much overhead). Commands can be send to any sensor/actuator device through this TCP channel. Controllers and sensor/actuators that need to send commands open a TCP client connection to the TCP server of the device that should receive the command. In principal that looks like
Not so complicated anymore. But how do the control devices know which sensor/actuator IP belongs to which device.
This is solved with
a) the UDP broadcast, which gives the control devices the IP address of the sending sensor/actuator
b) the status message itself, which includes information about the device and the location of the device.
With this two informations the control devices can build up a network map with all available sensor/actuator devices, their capabilities and their location.
This is the simplified explanation how a multi-point bi-directional communication without a central server could look like. And it works now since 3 years for me. And even if my ISP here cuts me off the internet again, my home control system continues to work as long as my local WiFi is working.