Hi everybody
I’m trying to communicate two devices according to the example of the documentation section but i can’t. The idea is to set a value on Device A from Device B using call.device() function
Device A
ThingerESP8266 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);
unsigned long int previous_millis = 0;
int val1 = 0;
int val2 = 0;
void setup() {
Serial.begin(115200);
if(WiFi.status() != WL_CONNECTED)
{
Serial.print("Connecting");
WiFi.begin(SSID_NAME, SSID_PASSWORD);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println();
}
thing["resourceOnA"] << [](pson& in){
val1 = in["anyValue1"];
val2 = in["anyValue2"];
// Work with the updated parameters here
};
}
void loop() {
thing.handle();
if(millis() - previous_millis > CALL_DEVICE_INTERVAL) //Wait some time
{
Serial.println(val1);
Serial.println(val2);
}
}
Device B
ThingerESP8266 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);
unsigned long int previous_millis = 0;
void setup() {
Serial.begin(115200);
if(WiFi.status() != WL_CONNECTED)
{
Serial.print("Connecting");
WiFi.begin(SSID_NAME, SSID_PASSWORD);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println();
}
}
void loop() {
thing.handle();
// be sure to call it at an appropiate rate
if(millis() - previous_millis > CALL_DEVICE_INTERVAL)
{
previous_millis = millis();
pson data;
data["anyValue1"] = 3;
data["anyValue2"] = 43.1;
thing.call_device("deviceA", "resourceOnA", data);
}
}
In my dashboard i have other resources defined (those of the project i’ve been working in)
What is the problem? val1 and val2 are always 0
Thanks in advance