Communication Between Devices in IoT

Picture of Alvaro Luis Bustamante
Alvaro Luis Bustamante

In this post we want to introduce a new feature released in the latests server updates and Arduino libraries (starting at 2.5.0). This feature is related to inter-device communication in real-time, both for devices of the same account, or devices from different accounts.

In Thinger.io, it is possible that devices can communicate between them trough the Internet in real-time. Imagine you have two ESP8266, or any other micro connected to the Internet, that needs to communicate for some reason. Suppose that you are building some automation mechanism, like turning on your home heater when you leave the office, or a system that automatically opens your garage door when you are getting home. One device can be established in your home, and other device in your office, your car, and so on. In this context, it can be very useful that your devices can communicate in real-time for sharing information, so they can complete complex actions.

There are two possibilities here. The first one is the communication between devices from the same account, and the second one is the communication between devices from different accounts. Thinger.io covers both alternatives.

Communication between devices (from the same account) is as simple as calling a new function in your code, called call_device. This new function allows to specify the target device id, the target resource, and optional data that can be transmitted in the call.

For example, suppose you have two devices, deviceA, and deviceB. The deviceA defines a resource like in the following example.

[cpp]
setup(){
thing[“resourceOnA”] = [](){
Serial.println("Someone is calling me!");
};
}
[/cpp]

Device deviceB can easily execute the resource resourceOnA method by calling the following method.

[cpp]
loop(){
thing.handle();
// here you can call the device resource when your condition is met
thing.call_device("deviceA", "resourceOnA");
}
[/cpp]

In this way, the device deviceB is calling the resource resourceOnA in device deviceA as required. This communication is currently done in unicast, but there are plans for supporting multicast schemes.

Take a look to the Arduino documentation to see how to transmit information while calling a device, or how to call a device from a different account.

Arduino Documentation: Communication between devices 

Do you have any doubts? Contact us!

Discover how Thinger can help your business with our All-in-One platform. 

Start building your IoT products

With the All-in-One Best Leading IoT Platform