• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

esp[32 openweathermap – convert kelvin to Centigrade

Q&A Forum › Category: ESP32 › esp[32 openweathermap – convert kelvin to Centigrade
0 Vote Up Vote Down
Steve Fisch asked 5 years ago

Sara,

 

Issue resolved – thanks for your quick response.

Steve

 

Resolved by changing variable type of  temp from float to int – I also added a C to F conversion

Revised code:

int temp;
temp = (int)(myObject[“main”][“temp”]) – 273.15; // get temperature in °C
Serial.print(“Temperature C: “);
Serial.println(temp);
int tempf;
Serial.print(“Temperature F: “);
tempf = (temp *9/5 +32);
Serial.println(tempf);

 

Hi Sara,

on page 719 of “Learn ESP32 with arduino ide regarding the openweathermap code

I want to convert the degrees Kelvin to degrees C from the code on page 720 of  “Learn ESP32 with arduino ide.”

Your code is:
(line 67) Serial.println(myObject[“main”][“temp”]);

MY CODE (which I took from  your answer from 7 months ago when you answered Domenico Carvetta’s query):

follows
float temp = (float)(myobject[“main”][“temp”]) – 273.15; // get temperature in °C
Serial.print(“Temperature C: “);
Serial.println(temp);

Q&A Forum › Showing search results for “openweathermap”
openweathermap

float temp = (float)(myobject[“main”][“temp”]) – 273.15; // get temperature in °C
Serial.print(“Temperature C: “);
Serial.println(temp);

Sara,
As far as I can tell, the only difference in code is that I use myobject rather than

//float temp = (float)(root[“main”][“temp”]) – 273.15; // get temperature in °C

ERROR LOG

Arduino: 1.8.14 Hourly Build 2020/10/09 12:33 (Windows 10), Board: “NodeMCU-32S, 80MHz, 921600”

Open_weather_map:70:28: error: ‘myobject’ was not declared in this scope
float temp = (float)(myobject[“main”][“temp”]) – 273.15; // get temperature in °C

^
exit status 1

‘myobject’ was not declared in this scope

without MY CODE serial print is:

12:03:16.121 -> HTTP Response code: 200
12:03:16.121 -> {“coord”:{“lon”:-96.7,”lat”:33.02},”weather”:[{“id”:804,”main”:”Clouds”,”description”:”overcast clouds”,”icon”:”04d”}],”base”:”stations”,”main”:{“temp”:277.35,”feels_like”:272.08,”temp_min”:276.48,”temp_max”:278.15,”pressure”:1020,”humidity”:97},”visibility”:10000,”wind”:{“speed”:5.58,”deg”:13},”clouds”:{“all”:100},”dt”:1603818038,”sys”:{“type”:3,”id”:2010018,”country”:”US”,”sunrise”:1603802459,”sunset”:1603842002},”timezone”:-18000,”id”:4719457,”name”:”Plano”,”cod”:200}
12:03:16.189 -> JSON object = {“coord”:{“lon”:-96.7,”lat”:33.02},”weather”:[{“id”:804,”main”:”Clouds”,”description”:”overcast clouds”,”icon”:”04d”}],”base”:”stations”,”main”:{“temp”:277.35,”feels_like”:272.08,”temp_min”:276.48,”temp_max”:278.15,”pressure”:1020,”humidity”:97},”visibility”:10000,”wind”:{“speed”:5.58,”deg”:13},”clouds”:{“all”:100},”dt”:1603818038,”sys”:{“type”:3,”id”:2010018,”country”:”US”,”sunrise”:1603802459,”sunset”:1603842002},”timezone”:-18000,”id”:4719457,”name”:”Plano”,”cod”:200}
12:03:16.223 -> Temperature: 277.35
12:03:16.223 -> Pressure: 1020
12:03:16.223 -> Humidity: 97
12:03:16.223 -> Wind Speed: 5.58
12:03:26.783 -> HTTP Response code: 200
12:03:26.783 -> {“coord”:{“lon”:-96.7,”lat”:33.02},”weather”:[{“id”:804,”main”:”Clouds”,”description”:”overcast clouds”,”icon”:”04d”}],”base”:”stations”,”main”:{“temp”:277.35,”feels_like”:272.08,”temp_min”:276.48,”temp_max”:278.15,”pressure”:1020,”humidity”:97},”visibility”:10000,”wind”:{“speed”:5.58,”deg”:13},”clouds”:{“all”:100},”dt”:1603818038,”sys”:{“type”:3,”id”:2010018,”country”:”US”,”sunrise”:1603802459,”sunset”:1603842002},”timezone”:-18000,”id”:4719457,”name”:”Plano”,”cod”:200}
12:03:26.820 -> JSON object = {“coord”:{“lon”:-96.7,”lat”:33.02},”weather”:[{“id”:804,”main”:”Clouds”,”description”:”overcast clouds”,”icon”:”04d”}],”base”:”stations”,”main”:{“temp”:277.35,”feels_like”:272.08,”temp_min”:276.48,”temp_max”:278.15,”pressure”:1020,”humidity”:97},”visibility”:10000,”wind”:{“speed”:5.58,”deg”:13},”clouds”:{“all”:100},”dt”:1603818038,”sys”:{“type”:3,”id”:2010018,”country”:”US”,”sunrise”:1603802459,”sunset”:1603842002},”timezone”:-18000,”id”:4719457,”name”:”Plano”,”cod”:200}
12:03:26.853 -> Temperature: 277.35
12:03:26.853 -> Pressure: 1020
12:03:26.887 -> Humidity: 97
12:03:26.887 -> Wind Speed: 5.58
12:03:37.453 -> HTTP Response code: 200
12:03:37.453 -> {“coord”:{“lon”:-96.7,”lat”:33.02},”weather”:[{“id”:804,”main”:”Clouds”,”description”:”overcast clouds”,”icon”:”04d”}],”base”:”stations”,”main”:{“temp”:277.35,”feels_like”:272.08,”temp_min”:276.48,”temp_max”:278.15,”pressure”:1020,”humidity”:97},”visibility”:10000,”wind”:{“speed”:5.58,”deg”:13},”clouds”:{“all”:100},”dt”:1603818038,”sys”:{“type”:3,”id”:2010018,”country”:”US”,”sunrise”:1603802459,”sunset”:1603842002},”timezone”:-18000,”id”:4719457,”name”:”Plano”,”cod”:200}
12:03:37.487 -> JSON object = {“coord”:{“lon”:-96.7,”lat”:33.02},”weather”:[{“id”:804,”main”:”Clouds”,”description”:”overcast clouds”,”icon”:”04d”}],”base”:”stations”,”main”:{“temp”:277.35,”feels_like”:272.08,”temp_min”:276.48,”temp_max”:278.15,”pressure”:1020,”humidity”:97},”visibility”:10000,”wind”:{“speed”:5.58,”deg”:13},”clouds”:{“all”:100},”dt”:1603818038,”sys”:{“type”:3,”id”:2010018,”country”:”US”,”sunrise”:1603802459,”sunset”:1603842002},”timezone”:-18000,”id”:4719457,”name”:”Plano”,”cod”:200}
12:03:37.523 -> Temperature: 277.35
12:03:37.523 -> Pressure: 1020
12:03:37.523 -> Humidity: 97
12:03:37.523 -> Wind Speed: 5.58

As always, thanks very much,
Steve Fisch

Question Tags: esp32 openweathermap
2 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 5 years ago

Hi Steve.
Were you able to solve your problem, then?
Regards,
Sara

0 Vote Up Vote Down
paulfjujo answered 3 years ago

hello,
a more easy way ..
is to add   
&units=metric after your API KEY 
=> Temperature display in Degrés C
 

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [eBook Updated] Learn Raspberry Pi Pico/Pico W with MicroPython eBook – Version 1.2 May 26, 2025
  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.