Communication between device

hello

im a new user of thinger io,
im tried to communicate between an esp8266 (esp01) and a esp32 for sending value of sensor.

i have tested this
http://docs.thinger.io/arduino/#coding-communication-between-devices but i can’t get the information.

i post my code, if you have an idea why i don’t received data i like you

the esp8266, he read data from a DHT11 sensor

/* 
 *  test dialogue ESP01 avec DHT11 vers thinger io 
 *  pour envoie info temperature et humidité
 *  fonctionne sans pb
 *  modif pour envoie info pour recup par esp32
*/


// déclaration thinger io
#define THINGER_SERVER "xxx"  // serveur local
#define USERNAME "xxx"
#define DEVICE_ID "esp01_temp1"
#define DEVICE_CREDENTIAL "xxx


// déclaration librairies
#include <ESP8266WiFi.h>
#include <ThingerESP8266.h>
#include <DHT.h>
#include <DHT_U.h>


// déclaration wifi

#define SSID "xxx"
#define SSID_PASSWORD "xxx"

// connection thinger io

ThingerESP8266 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);

// déclaration dht11
#define DHTPIN            2         // Pin which is connected to the DHT sensor.
#define DHTTYPE           DHT11     // DHT 11 
DHT_Unified dht(DHTPIN, DHTTYPE);
uint32_t delayMS;


// definition variable
int temp1;
int humi1;



void setup() {

  thing.add_wifi(SSID, SSID_PASSWORD);

  // resource output example (i.e. reading a sensor value)

thing["resourceOnTemp01"] << [](pson& in){
        int temp1 = in["temp1ontemp1"];
        int humi1 = in["humi1onhumi1"];
        // Work with the updated parameters here
    };


  
// ligne en dessous ok affichage dashboard
//  thing["temp1"] >> outputValue(temp1);
//  thing["humi1"] >> outputValue(humi1);

  // début dht
  dht.begin();
  sensor_t sensor;
  dht.temperature().getSensor(&sensor);
  dht.humidity().getSensor(&sensor);
  delayMS = sensor.min_delay / 1000;



}

void loop() {
  delay(delayMS);
  sensors_event_t event;  
  dht.temperature().getEvent(&event);
  temp1 = event.temperature;
  dht.humidity().getEvent(&event);
  humi1 = event.relative_humidity;
  thing.handle();


}

and the ESP32 store the value on local variable

/*
 * teste dialogue ESP32 ecran Nextion
 * TX pin nextion => pin D4 esp32
 * RX pin nextion => pin D2 esp32
 * GND relié
 * 
 * 
 * voir pout utiliser librairies de base (itead nextion)
 * dans ihm nextion modifier nombre de caractere temp (pas de négatif inférieur a 10 sinon)
 * faire fonction map pour valeur con pour 10°C 30°C pour bloquer bug
 * 
 */

// déclaration thinger io
#define THINGER_SERVER "xxx"  // serveur local
#define USERNAME "xxx"
#define DEVICE_ID "esp32"
#define DEVICE_CREDENTIAL "xxx"


// déclaration librairies
#include <Nextion.h>
#include <WiFiClientSecure.h>
#include <ThingerESP32.h>


// déclaration wifi

#define SSID "xxx"
#define SSID_PASSWORD "xxx"

// connection thinger io

ThingerESP32 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);


// déclaration liaison série avec Nextion

Nextion myNextion(Serial1, 9600); //create a Nextion object named myNextion using the nextion serial port @ 9600bps

// déclaration bouton

bool bt0 =false; // bouton on off freecooling (bool = true ou false) identique boolean

// déclaration zone texte

int temp1 = 20; // int va de 2²-15 a 2²15
int humi1 = 20;
int temp2 = 20;
int temp3 = 20;
int temp4 = 20;
byte con1 = 20; // byte va de 0 à 255
byte con2 = 20;
byte con3 = 20;
byte con4 = 20;

/* fin des déclaration */



void setup() {
  Serial.begin(9600);
  myNextion.init();
  thing.add_wifi(SSID, SSID_PASSWORD);
// info a envoyer a thinger io

    thing["con1"] >> outputValue(con1);
    thing["con2"] >> outputValue(con2);
    thing["con3"] >> outputValue(con3);
    thing["con4"] >> outputValue(con4);
    thing["bt0"] >> [](pson& out){
    out = bt0 == true ? "Freecooling ON" : "Freecooling OFF"; };




// fin setup
  }

void loop() {
  String message = myNextion.listen(); //ecoute le port série depuis nextion
  
   if (message != ""){ // if a message is received...
    Serial.println(message); //...print it out
    }
    Serial.println(temp1);
  // cette ligne est un prototype
  // void getinfo (String &message);
  // cette ligne est un appel de fonction
  getinfo (message);

  thing.handle();
 pson data;
    data["temp1ontemp1"] = temp1;
    data["humi1onhumi1"] = humi1;
    thing.call_device("esp01_temp1", "resourceOnTemp1", data);
  
}

void getinfo(String & message) {

if (message == "65 1 3 1 ff ff ff") { // bouton plus 1
con1++;
myNextion.setComponentText("con1", String(con1));
}
if (message == "65 1 4 1 ff ff ff") { // bouton moins 1
con1--; 
myNextion.setComponentText("con1", String(con1));
}
if (message == "65 1 8 1 ff ff ff") { // bouton plus 2
con2++;
myNextion.setComponentText("con2", String(con2));
}
if (message == "65 1 9 1 ff ff ff") { // bouton moins 2
con2--;
myNextion.setComponentText("con2", String(con2));
}
if (message == "65 1 a 1 ff ff ff") { // bouton plus 3
con3++; 
myNextion.setComponentText("con3", String(con3));
}
if (message == "65 1 b 1 ff ff ff") { // bouton moins 3
con3--; 
myNextion.setComponentText("con3", String(con3));
}
if (message == "65 1 c 1 ff ff ff") { // bouton plus 4
con4++; 
myNextion.setComponentText("con4", String(con4));
}
if (message == "65 1 d 1 ff ff ff") { // bouton moins 4
con4--;
myNextion.setComponentText("con4", String(con4));
}
if (message == "65 0 a 1 ff ff ff") { // bouton on off freecooling
bt0 = !bt0; } // bouton etat on off

  
}

Can you change this values by the device’s web api? I dont know why but I guess that as it is defined it cant be changed even by the device’s web api, if you can’t maybe this is the issue and it should be solved with this code.

thing["resourceOnTemp01"] << [](pson& in){
     if(in["temp1ontemp1"].is_empty()) in["temp1ontemp1"] = temp1;
     else temp1 = in["temp1ontemp1"];
     if(in["humi1onhumi1"].is_empty()) in["humi1onhumi1"] = humi1 ;
     else humi1 = in["humi1onhumi1"];
 };

Hope this helps

thanks a lot for your response,
i have tested your code but he dont work
i have enabled the debug on the esp32
and i have this
[THINGER] Writing bytes: 71 [OK]
[THINGER] Available bytes: 55

he write bytes but dont get the values from the other device.
do you have an other idea ?

thanks a lot

Can you change the values in " esp01_temp1 " from the web API?

Try to do it first with your code, if you can not, try with mine, first of all I want to know that it can be modified the variables in the device.

what do you call the web API ?

thanks a lot

EDIT:
i have found the web API,
on my own server, i have a response not found

I’m sorry, have you a response not found?

The web api access is in the device’s page, is an easy way to interact with “things” in your device, from the web console.

The idea is to verify that as were defined the input resources in the device, are able to get written from the web api, another device or the mobile app, the shortest path is the web api.

i dont have view this on the device ^^
now i have view the API
when i click on API, i dont have my "temp1ontemp1"
i need to declar it like this
thing[“temp1”] << inputValue(temp1ontemp1);
?

thanks a lot

EDIT:

like this
thing[“temp1ontemp1”] << inputValue(temp1);
thing[“humi1ontemp1”] << inputValue(humi1);

it’s ok i can view it on API and i can modify it with API

Have you done this test?

You can use

but will handle two different “things”, one for each variable you need to write in other device.

hello
yes i can modify variables in the device esp32 via the API
i have tested each code but nothing work

thanks a lot

I see the problem, esp32 does not call the variables in esp8266, the “call to the device” works writing to a remote device, not obtaining the values of other devices, so you need to set in esp8266 the call routine of the device to write the values in esp32.

I recommend that you better document what you can not or want to do, as well as the tests you have done and the results, it was not easy for me to understand where you were or what you have done, it is a waste of time if I need to ask in a post the for the result of a test that I explicitly asked you to do in a previuous post, I can not see it through your eyes, so take a little more time and document more what you have, for the people who want to help you, because I particularly ignore poorly documented publications, this recommendation applies at any forum, not just this one.

Hope this helps.

im sorry,
now i have on my esp01 (sender of information) this code

/* 
 *  test dialogue ESP01 avec DHT11 vers thinger.io 
 *  pour envoie info temperature et humidité
 *  fonctionne sans pb
 *  modif pour envoie info pour recup par esp32
*/


// déclaration thinger.io
#define THINGER_SERVER "192.168.1.32"  // serveur local
#define USERNAME "anthology"
#define DEVICE_ID "esp01_temp1"
#define DEVICE_CREDENTIAL "05qKXwqu7kY!"


// déclaration librairies
#include <ESP8266WiFi.h>
#include <ThingerESP8266.h>
#include <DHT.h>
#include <DHT_U.h>


// déclaration wifi

#define SSID "Livebox-5D04"
#define SSID_PASSWORD "6124E2F5F97E65E221DFCE1C5D"

// connection thinger.io

ThingerESP8266 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);

// déclaration dht11
#define DHTPIN            2         // Pin which is connected to the DHT sensor.
#define DHTTYPE           DHT11     // DHT 11 
DHT_Unified dht(DHTPIN, DHTTYPE);
uint32_t delayMS;


// definition variable
int temp1;
int humi1;



void setup() {

  thing.add_wifi(SSID, SSID_PASSWORD);


thing["resourceOnTemp01"] >> [](pson& out){
   out["temp1ontemp1"] =  temp1  ;
   out["humi1onhumi1"] =  humi1  ;
    // Work with the updated parameters here
    };



  // début dht
  dht.begin();
 sensor_t sensor;
   dht.temperature().getSensor(&sensor);
  dht.humidity().getSensor(&sensor);
  delayMS = sensor.min_delay / 1000;



}

void loop() {
  delay(delayMS);
  sensors_event_t event;  
  dht.temperature().getEvent(&event);
  temp1 = event.temperature;
  dht.humidity().getEvent(&event);
  humi1 = event.relative_humidity;


  
  thing.handle();


}

i received the values on my dashboard with no problem and on the API i can view this
capture%20esp01%20thingerio

on the ESP01 (when i want call the device)
i have this code

  /*
 * teste dialogue ESP32 ecran Nextion
 * TX pin nextion => pin D4 esp32
 * RX pin nextion => pin D2 esp32
 * GND relié
 * 
 * 
 * voir pout utiliser librairies de base (itead nextion)
 * dans ihm nextion modifier nombre de caractere temp (pas de négatif inférieur a 10 sinon)
 * faire fonction map pour valeur con pour 10°C 30°C pour bloquer bug
 * 
 */

// déclaration thinger.io
#define THINGER_SERVER "192.168.1.32"  // serveur local
#define USERNAME "anthology"
#define DEVICE_ID "esp32"
#define DEVICE_CREDENTIAL "pcFRd@P%7VFN"
#define _DEBUG_



// déclaration librairies
#include <Nextion.h>
#include <WiFiClientSecure.h>
#include <ThingerESP32.h>


// déclaration wifi

#define SSID "Livebox-5D04"
#define SSID_PASSWORD "6124E2F5F97E65E221DFCE1C5D"

// connection thinger.io

ThingerESP32 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);


// déclaration liaison série avec Nextion

Nextion myNextion(Serial1, 9600); //create a Nextion object named myNextion using the nextion serial port @ 9600bps

// déclaration bouton

bool bt0 =false; // bouton on off freecooling (bool = true ou false) identique boolean

// déclaration zone texte

int temp1 = 20; // int va de 2²-15 a 2²15
int humi1 = 20;
int temp2 = 20;
int temp3 = 20;
int temp4 = 20;
byte con1 = 20; // byte va de 0 à 255
byte con2 = 20;
byte con3 = 20;
byte con4 = 20;

/* fin des déclaration */



void setup() {
  Serial.begin(9600);
  myNextion.init();
  thing.add_wifi(SSID, SSID_PASSWORD);

// info a envoyer a thinger.io

thing["con1"] >> outputValue(con1);
thing["con2"] >> outputValue(con2);
thing["con3"] >> outputValue(con3);
thing["con4"] >> outputValue(con4);
thing["bt0"] >> [](pson& out){
out = bt0 == true ? "Freecooling ON" : "Freecooling OFF"; };
// fin info a envoyer a thinger.io

// info a recevoir de thinger.io

   thing["resourceOnTemp01"] << [](pson& in){
       int temp1 = in["temp1ontemp1"];
       int humi1 = in["humi1onhumi1"];
        // Work with the updated parameters here
    };
    
  /*thing["resourceOnTemp01"] << [](pson& in){
     if(in["temp1ontemp1"].is_empty()) in["temp1ontemp1"] = temp1;
     else temp1 = in["temp1ontemp1"];
     if(in["humi1onhumi1"].is_empty()) in["humi1onhumi1"] = humi1 ;
     else humi1 = in["humi1onhumi1"];
 };
*/
// fin info a recevoir de thinger.io
 
// fin setup
  }

void loop() {
  String message = myNextion.listen(); //ecoute le port série depuis nextion
  
   if (message != ""){ // if a message is received...
    Serial.println(message); //...print it out
    }
    Serial.println(temp1);
  // cette ligne est un prototype
  // void getinfo (String &message);
  // cette ligne est un appel de fonction
  getinfo (message);

 // boucle thinger.io
  thing.handle();

}

void getinfo(String & message) {

if (message == "65 1 3 1 ff ff ff") { // bouton plus 1
con1++;
myNextion.setComponentText("con1", String(con1));
}
if (message == "65 1 4 1 ff ff ff") { // bouton moins 1
con1--; 
myNextion.setComponentText("con1", String(con1));
}
if (message == "65 1 8 1 ff ff ff") { // bouton plus 2
con2++;
myNextion.setComponentText("con2", String(con2));
}
if (message == "65 1 9 1 ff ff ff") { // bouton moins 2
con2--;
myNextion.setComponentText("con2", String(con2));
}
if (message == "65 1 a 1 ff ff ff") { // bouton plus 3
con3++; 
myNextion.setComponentText("con3", String(con3));
}
if (message == "65 1 b 1 ff ff ff") { // bouton moins 3
con3--; 
myNextion.setComponentText("con3", String(con3));
}
if (message == "65 1 c 1 ff ff ff") { // bouton plus 4
con4++; 
myNextion.setComponentText("con4", String(con4));
}
if (message == "65 1 d 1 ff ff ff") { // bouton moins 4
con4--;
myNextion.setComponentText("con4", String(con4));
}
if (message == "65 0 a 1 ff ff ff") { // bouton on off freecooling
bt0 = !bt0; } // bouton etat on off
}

i can put my temp values with the API

but i can’t get device values

can you explain to me the call routine for write the values in esp32 ?

hello,

anyone have an idea ?

thanks a lot