New feature

Devices that talk to each other in real time

This post introduces a new feature released in the latest server updates and Arduino libraries (starting at 2.5.0): inter-device communication in real time, both for devices of the same account and for devices from different accounts.

In Thinger.io, devices can communicate with each other through the Internet in real time. Imagine you have two ESP8266, or any other microcontroller connected to the Internet, that need 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 another device in your office, your car, and so on. In this context, it can be very useful that your devices communicate in real time to share information, so they can complete complex actions.

Diagram titled Thinger.io Communication Between Devices: cars, houses and ESP8266 boards on both sides exchange two-way arrows with a Thinger.io cloud in the centre
Devices in a home, an office or a car exchange calls in real time through Thinger.io.

Two cases

Same account or different accounts

There are two possibilities: communication between devices from the same account, and communication between devices from different accounts. Thinger.io covers both alternatives.

Devices of the same account

  • As simple as calling a new function in your code, call_device
  • It specifies the target device id, the target resource, and optional data to transmit in the call

Devices of different accounts

  • Also covered by Thinger.io
  • How to call a device from a different account is described in the Arduino documentation

Worked example

deviceB calls a resource on deviceA

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

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

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

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

In this way, the device deviceB is calling the resource resourceOnA in device deviceA as required.

At the time of writing (2016) this communication was done in unicast, with plans for supporting multicast schemes.

Go further

Send data in the call, or call another account

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

Make your devices work together

Communication between devices, step by step, in the coding guide of the Thinger.io documentation.