Hi all,
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:
void setup() {
thing["Breath"] >> [](pson& out){
out["top"] = brTopVal;
out["bot"] = brBotVal;
};
thing["HeartRate"] >> [](pson& out){
out["beat"] = sendBeat; // boolean
out["hr"] = myHeartRate;
out["ibi"] = secsElapsed;
};
}
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…
boolean beat;
float hr;
float ibi;
void setup() {
Serial.begin(9600);
thing.add_wifi(SSID, SSID_PASSWORD);
// init led
pinMode(LED_BUILTIN, OUTPUT);
thing["led"] << [](pson& in){
hr = in["hr"];
ibi = in["ibi"];
beat = in["beat"];
};
}
void loop() {
thing.handle();
thing.call_device("deviceA", "HeartRate");
digitalWrite(LED_BUILTIN, beat ? HIGH : LOW); // stays off
Serial.println(hr); // output 0.0
Serial.println(ibi); // output 0.0
Serial.println(beat); // output 0
}
There must be something basic that I am not getting. I would be very grateful for any help. Thanks in advance for your time and efford. Danielle.