I can’t seem to get my head around working with data send from another device. This is what I want to do:
Device A collects biometric data and sends that out. I don’t want to send it to any specific device because I want more devices to be able to use the same data. That seems to be working because I can see it in my dashboard. Here is the data structure:
But now I want to work with this data in another device. Eventually I want an led to blink at the rythm of the heartbeat. Here’s my code. But I only get zero values, the led stays off. No data seems to be coming in…
The communication between devices is not designed for asking values, it is designed to send values, I mean, the device A should send values to the device B, not the device B ask for values to device A (it can be done but not by the native way).
Be careful how often do you call this instruction, because as it is written, it will be called maybe more than hundred times in a second.
I seems not logical to me that I can’t read data from one source. I seems to me that it would be much more logical to have a device output the data and I can add as many other devices I want to use that data… And also:
In the documentation they give the following example:
The deviceA defines a resource like in the following example.
setup(){
thing[“resourceOnA”] = [](){
Serial.println("Someone is calling me!");
};
}
deviceB can easily call this method by running the following command.
loop(){
thing.handle();
// be sure to call it at an appropiate rate
thing.call_device("deviceA", "resourceOnA");
}
This means that B is listening to A right? I can’t get this example to work though…
Can you please give me an example of how to do it in a non native way?
I can confirm that Ega is right. Although… this section is not very intuitive in our documentation, but I will try to explain a little more: In this example, deviceB is sending data to deviceA in an active way, but deviceB cannot request information from deviceA.
You could always do it with a double message: deviceB sends deviceA a call_device instruction sending its identifier, then deviceA resumes it and sends the data to that deviceID. Another option would be store deviceA data in a data bucket and retrieve it with the other devices but this only can be done with a Platfomr privated instance due to the bucket writting limitations.
It seems not logical according your need, but I think this feature is designed kind of “Master-Slave” communication, so the Master orders to run a procedure, or gives some values to the Slave.
So as jtrinc26 says, you can do it by a double message, kind of device B gives order to device A to send values to device B, it’s kind a request disguised
Another non native way to do it is making a HTTP request directly to the device, I like this more because you don’t need to modify the device A’s sketch, and you can access it from unlimited devices
You need to build the link to access your device’s resource (THING_NAME), just modify the fields between
The access token could be generated by the “Access tokens” link on the platform, or you can use one generated directly at the device’s dashboard, with access to “THING_NAME” resource.
You can test if its working the request by the browser, it must show you the data in a json format.
Once you have the right link to the device that you want to read the actual values, apply this, it is explained to apply with a bucket, but its the same work consulting the device by http