Coding Help send data from esp to dasboard "Temperature" from Open Weather

Hi my idea is show in the dashboard temperature outside (open weather) and inside from sensor, i do not found how to send the temperature :frowning:

What is working ? i can see the weather data in serial monitor, and I´ve mills() send from ESP to the dashboard.
But i try several ways to send the openweather data to dasboard and always get an error.

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <Arduino_JSON.h>
#include <ThingerESP8266.h> // Thinger
#include <NTPClient.h> // Thinger
#include <WiFiUdp.h> // Thinger
#define USERNAME “and***” // Thinger
#define DEVICE_ID “node***” // Thinger
#define DEVICE_CREDENTIAL “Nxb$dw*******” // Thinger
ThingerESP8266 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL);
const char* ssid = “TP-";
const char
password = "no
***”;

String my_Api_Key = “e1e11b7969e4ea11abad3e947ba****”;

String my_city = “Buenos Aires”; //specify your city
String my_country_code = “AR”; //specify your country code

unsigned long last_time = 0;
unsigned long timer_delay = 30000;

String json_array;
WiFiClient wifiClient;

unsigned long timert = 0;

void setup() {

// digital pin control example (i.e. turning on/off a light, a relay, configuring a parameter, etc) // thinger.io
thing[“led”] << digitalPin(LED_BUILTIN);

// resource output example (i.e. reading a sensor value) // thinger.io
thing[“millis”] >> outputValue(millis());
thing[“timert”] >> outputValue(timert);

Serial.begin(115200);

WiFi.begin(ssid, password);
Serial.println(“Connecting to WIFI…”);
while(WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("IP Address: ");
Serial.println(WiFi.localIP());

Serial.println(“First set of readings will appear after 10 seconds”);
}

void loop() {

timert = (millis() - last_time);

if ( timert > timer_delay) {

if(WiFi.status()== WL_CONNECTED){
  String server = "http://api.openweathermap.org/data/2.5/weather?q=" + my_city + "," + my_country_code + "&APPID=" + my_Api_Key + "&units=metric";
  
  json_array = GET_Request(server.c_str());
   Serial.println(json_array);
  JSONVar my_obj = JSON.parse(json_array);

  if (JSON.typeof(my_obj) == "undefined") {
    Serial.println("Parsing input failed!");
    return;
  }

 // Serial.print("JSON object = ");
 //  Serial.println(my_obj);
  Serial.print("Temp: ");
  Serial.println(my_obj["main"]["temp"]);

  Serial.print("Pres: ");
  Serial.println(my_obj["main"]["pressure"]);
  Serial.print("Hum: ");
  Serial.println(my_obj["main"]["humidity"]);
  Serial.print("S.ter: ");
  Serial.println(my_obj["main"]["feels_like"]);
  Serial.print("T.min: ");
  Serial.println(my_obj["main"]["temp_min"]);
 Serial.print("T.max: ");
 Serial.println(my_obj["main"]["temp_max"]);
 Serial.print("Press: ");
 Serial.println(my_obj["main"]["pressure"]);

 
}
else {
  Serial.println("WiFi Disconnected");
}
last_time = millis();

}
}

String GET_Request(const char* server) {
HTTPClient http;
http.begin(wifiClient,server);
int httpResponseCode = http.GET();

String payload = “{}”;

if (httpResponseCode>0) {
Serial.print("HTTP Response code: ");
Serial.println(httpResponseCode);
payload = http.getString();
}
else {
Serial.print("Error code: ");
Serial.println(httpResponseCode);
}
http.end();

return payload;

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

Serial Monitor :
HTTP Response code: 200
{“coord”:{“lon”:-58.3772,“lat”:-34.6132},“weather”:[{“id”:800,“main”:“Clear”,“description”:“clear sky”,“icon”:“01n”}],“base”:“stations”,“main”:{“temp”:12.87,“feels_like”:12.09,“temp_min”:9.82,“temp_max”:13.85,“pressure”:1019,“humidity”:72},“visibility”:10000,“wind”:{“speed”:3.6,“deg”:20},“clouds”:{“all”:0},“dt”:1655169844,“sys”:{“type”:1,“id”:8224,“country”:“AR”,“sunrise”:1655117877,“sunset”:1655153361},“timezone”:-10800,“id”:3435910,“name”:“Buenos Aires”,“cod”:200}
Temp: 12.87
Pres: 1019
Hum: 72
S.ter: 12.09
T.min: 9.82
T.max: 13.85
Press: 1019

Hi,

Where is the error? I have not seen it into the serial console debug.

Add #define _DEBUG_ at the very first line of the skecth, to enable the thinger debug.

And please paste the code in the right way if you want us to read it, select it all and use the “</>” button at the menu.

Hope this helps.

Tanks for your answer, I’m newbie it is the code copied from arduino ide. the previous code have no errors, works fine. But I tried several ways to pass the temperature data to the dashboard and get errors , I do not know how to do it.

I show you what i tried :

=============================


#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <Arduino_JSON.h>
#include <ThingerESP8266.h>  // Thinger
#include <NTPClient.h>  // Thinger
#include <WiFiUdp.h> // Thinger
#define USERNAME "andr**"    // Thinger
#define DEVICE_ID "node****" // Thinger
#define DEVICE_CREDENTIAL "Nxb$dwaJf*****" // Thinger
ThingerESP8266 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL); 
const char* ssid = "TP-***";
const char* password = "no****";

String my_Api_Key = "e1e11b7969e4ea11abad3e947ba*****";

String my_city = "Buenos Aires"; //specify your city
String my_country_code = "AR"; //specify your country code

unsigned long last_time = 0;
unsigned long timer_delay = 30000;


String json_array;
WiFiClient wifiClient;

unsigned long timert = 0;


void setup() {

   // digital pin control example (i.e. turning on/off a light, a relay, configuring a parameter, etc)  // thinger.io
  thing["led"] << digitalPin(LED_BUILTIN);

  // resource output example (i.e. reading a sensor value)  // thinger.io
  thing["millis"] >> outputValue(millis());
  thing["timert"] >> outputValue(timert);
  thing["temperature"] >> [](pson& out){
      out = my_obj["main"]["temp"];
                                         };
  Serial.begin(115200);

  WiFi.begin(ssid, password);
  Serial.println("Connecting to WIFI...");
  while(WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("IP Address: ");
  Serial.println(WiFi.localIP());
 
  Serial.println("First set of readings will appear after 10 seconds");
}

void loop() {


  
 timert = (millis() - last_time);
  
  if ( timert > timer_delay) {
  
    if(WiFi.status()== WL_CONNECTED){
      String server = "http://api.openweathermap.org/data/2.5/weather?q=" + my_city + "," + my_country_code + "&APPID=" + my_Api_Key + "&units=metric";
      
      json_array = GET_Request(server.c_str());
       Serial.println(json_array);
      JSONVar my_obj = JSON.parse(json_array);
  
      if (JSON.typeof(my_obj) == "undefined") {
        Serial.println("Parsing input failed!");
        return;
      }
    
     // Serial.print("JSON object = ");
     //  Serial.println(my_obj);
      Serial.print("Temp: ");
      Serial.println(my_obj["main"]["temp"]);
    
      Serial.print("Pres: ");
      Serial.println(my_obj["main"]["pressure"]);
      Serial.print("Hum: ");
      Serial.println(my_obj["main"]["humidity"]);
      Serial.print("S.ter: ");
      Serial.println(my_obj["main"]["feels_like"]);
      Serial.print("T.min: ");
      Serial.println(my_obj["main"]["temp_min"]);
     Serial.print("T.max: ");
     Serial.println(my_obj["main"]["temp_max"]);
     Serial.print("Press: ");
     Serial.println(my_obj["main"]["pressure"]);
   
     
    }
    else {
      Serial.println("WiFi Disconnected");
    }
    last_time = millis();
  }
}

String GET_Request(const char* server) {
  HTTPClient http;    
  http.begin(wifiClient,server);
  int httpResponseCode = http.GET();
  
  String payload = "{}"; 
  
  if (httpResponseCode>0) {
    Serial.print("HTTP Response code: ");
    Serial.println(httpResponseCode);
    payload = http.getString();
  }
  else {
    Serial.print("Error code: ");
    Serial.println(httpResponseCode);
  }
  http.end();

  return payload;
  
  thing.handle();  // thinger.io
}

============================
The error in this is : **
** 38 | out = my_obj[“main”][“temp”];

** | ^~~~~~**
exit status 1
’my_obj’ was not declared in this scope

==================================

an other try with :
thing[“Temp1”] >> outputValue(my_obj[“main”][“temp”]);

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <Arduino_JSON.h>
#include <ThingerESP8266.h>  // Thinger
#include <NTPClient.h>  // Thinger
#include <WiFiUdp.h> // Thinger
#define USERNAME "andreszz"    // Thinger
#define DEVICE_ID "nodemcuaz" // Thinger
#define DEVICE_CREDENTIAL "Nxb$dwaJfk*****" 
// Thinger
ThingerESP8266 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL); 
const char* ssid = "TP-**";
const char* password = "not****";

String my_Api_Key = "e1e11b7969e4ea11abad3e947****";

String my_city = "Buenos Aires"; //specify your city
String my_country_code = "AR"; //specify your country code

unsigned long last_time = 0;
unsigned long timer_delay = 30000;


String json_array;
WiFiClient wifiClient;

unsigned long timert = 0;


void setup() {

   // digital pin control example (i.e. turning on/off a light, a relay, configuring a parameter, etc)  // thinger.io
  thing["led"] << digitalPin(LED_BUILTIN);

  // resource output example (i.e. reading a sensor value)  // thinger.io
  thing["millis"] >> outputValue(millis());
  thing["timert"] >> outputValue(timert);
  thing["Temp1"] >> outputValue(my_obj["main"]["temp"]);
  Serial.begin(115200);

  WiFi.begin(ssid, password);
  Serial.println("Connecting to WIFI...");
  while(WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("IP Address: ");
  Serial.println(WiFi.localIP());
 
  Serial.println("First set of readings will appear after 10 seconds");
}

void loop() {


  
 timert = (millis() - last_time);
  
  if ( timert > timer_delay) {
  
    if(WiFi.status()== WL_CONNECTED){
      String server = "http://api.openweathermap.org/data/2.5/weather?q=" + my_city + "," + my_country_code + "&APPID=" + my_Api_Key + "&units=metric";
      
      json_array = GET_Request(server.c_str());
       Serial.println(json_array);
      JSONVar my_obj = JSON.parse(json_array);
  
      if (JSON.typeof(my_obj) == "undefined") {
        Serial.println("Parsing input failed!");
        return;
      }
    
     // Serial.print("JSON object = ");
     //  Serial.println(my_obj);
      Serial.print("Temp: ");
      Serial.println(my_obj["main"]["temp"]);
    
      Serial.print("Pres: ");
      Serial.println(my_obj["main"]["pressure"]);
      Serial.print("Hum: ");
      Serial.println(my_obj["main"]["humidity"]);
      Serial.print("S.ter: ");
      Serial.println(my_obj["main"]["feels_like"]);
      Serial.print("T.min: ");
      Serial.println(my_obj["main"]["temp_min"]);
     Serial.print("T.max: ");
     Serial.println(my_obj["main"]["temp_max"]);
     Serial.print("Press: ");
     Serial.println(my_obj["main"]["pressure"]);
   
     
    }
    else {
      Serial.println("WiFi Disconnected");
    }
    last_time = millis();
  }
}

String GET_Request(const char* server) {
  HTTPClient http;    
  http.begin(wifiClient,server);
  int httpResponseCode = http.GET();
  
  String payload = "{}"; 
  
  if (httpResponseCode>0) {
    Serial.print("HTTP Response code: ");
    Serial.println(httpResponseCode);
    payload = http.getString();
  }
  else {
    Serial.print("Error code: ");
    Serial.println(httpResponseCode);
  }
  http.end();

  return payload;
  
  thing.handle();  // thinger.io
}

=======================
error : ‘my_obj’ was not declared in this scope

Hi,

my_obj is not declared in the sketch, that’s why the compiler does not know what is it.

This is the shorthand way of defining a resource on the thinger platform thing["timert"] >> outputValue(timert);, it allows you to handle just one variable.

I recommend you to check the coding guide, there you will find how to define a multiple outputs in the same resource.

Hope this helps.