• 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

how to get the main weather string variable from openweathermap.org onto sd card

Q&A Forum › how to get the main weather string variable from openweathermap.org onto sd card
0 Vote Up Vote Down
David Barker asked 2 years ago
17 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 2 years ago

Hi.
Can you provide more details?
What have you achieved so far? What are your difficulties?
Are you following a specific project as a starting point?
What board are you using?
Regards,
Sara

0 Vote Up Vote Down
David Barker answered 2 years ago

Hi Sara
Board esp32 with sd card , bme280 sensor and openweatherMap . Object -to compare inside and outside conditions
I have amalagamated 2 tutorials
I  Code ESP32 HTTP GET OpenWeatherMap.org
2 ESP32 Data Logging to microSD Card
It is working perfectly.
But now I want to import the following information from open weather “ weather” and Main” and “Description “ and upload to sd card
Relavent part of openweather
“weather”: [
    {
      “id”: 803,
      “main”: “Clouds”,
      “description”: “broken clouds”,
      “icon”: “04d”
    }
  ],
 
If you could help that would be great
Regards David

0 Vote Up Vote Down
Sara Santos Staff answered 2 years ago

Hi.
 
First, you need to save the information on String variables.
For example, from the code, you know you can get that information as follows:
myObject[“weather”][“main”]
and
myObject[“weather”][“description”]
 
After having the information saved on String variables, you just need to write to the microSD card using the functions on that tutorial. In that scenario, the dataMessage variable would be a concatenation of the two strings you want to save.
 
I’m not sure if my explanation was a bit confusing.
 
Let me know if you need further help.
Regards,
Sara
 

0 Vote Up Vote Down
David Barker answered 2 years ago

thanks for that Sara
I have tried the above but unfortunately it does not work.
the problem I think is because these two variables are wrapped around  by square brackets [ ]
“weather”: [
    {
      “id”: 803,
      “main”: “Clouds”,
      “description”: “broken clouds”,
      “icon”: “04d”
    }
  ],
and to make it work these brackets need to be removed.  Can you help with this
thanks
regards David

0 Vote Up Vote Down
Sara Santos Staff answered 2 years ago

Hi.
When you say it doesn’t work, what happens exactly?
Can you show me the code you’re trying to run or the error you’re getting?
Regards,
Sara

0 Vote Up Vote Down
David Barker answered 2 years ago

Hi Sara

Serial.println(myObject[“weather”][“main”]);
is captured on the serial monitor as
weather:null
regards
David

0 Vote Up Vote Down
Sara Santos Staff answered 2 years ago

Hi.
You’re right.
Because of the square brackets, you get the value as follows:

Serial.println(myObject[“weather”][0][“main”]);

The same for the other value.
Let me know if this solves the issue.
Regards,
Sara

0 Vote Up Vote Down
David Barker answered 2 years ago

hi Sara
yes that works   – Avery elegant solution Thanks
I am now trying to upload to SD card with no success with this code

String weather = “”;

  String weather = (myObject[“weather”][0][“main”]);
If you could put me right that would be great
regards
david

0 Vote Up Vote Down
David Barker answered 2 years ago

hi Sara
yes that works   – Avery elegant solution Thanks
I am now trying to upload to SD card with no success with this code

String weather = “”;

  String weather = (myObject[“weather”][0][“main”]);
If you could put me right that would be great
regards
david

0 Vote Up Vote Down
Sara Santos Staff answered 2 years ago

Hi again.
What is the issue you’re facing when trying to write to the microSD card?
Do you get any errors?
Regards,
Sara

0 Vote Up Vote Down
David Barker answered 2 years ago

hi
no i do not get any errors but it does not record the data to the sd card.  Just to let you know all other integer variables are being successfully  uploaded to the card with this code

float timeO;

 timeO =int(myObject[“dt”]);

hope this helps
David

 

0 Vote Up Vote Down
Sara Santos Staff answered 2 years ago

Can you please share the relevant parts of code that save the problematic variable to the microSD card?
Regards,
Sara

0 Vote Up Vote Down
David Barker answered 2 years ago

hi
thisis the code

String weather;

weather =char(myObject[“weather”][0][“main”]);
thanks
David

0 Vote Up Vote Down
Sara Santos Staff answered 2 years ago

I’m referring to the lines of code that write to the microSD card.
REgards,
Sara

0 Vote Up Vote Down
David Barker answered 2 years ago

please find enclosed hope this is what is required

 //Concatenate all info separated by commas
    dataMessage = String(epochTime) + “,” + String(temp) + “,” + String(hum) + “,” + String(pres) + “,” + String(tempO) + “,” + String(humO) + “,” + String(presO) + “,”  + String(weather) + “\r\n”;
    Serial.print(“Saving data: “);
    Serial.println(dataMessage);
thanks

0 Vote Up Vote Down
Sara Santos Staff answered 2 years ago

Hi.
The weather variable is already a String, so I don’t think you need to convert it to a string again.
    dataMessage = String(epochTime) + “,” + String(temp) + “,” + String(hum) + “,” + String(pres) + “,” + String(tempO) + “,” + String(humO) + “,” + String(presO) + “,”  + weather + “\r\n”;
    Serial.print(“Saving data: “);
 
 

0 Vote Up Vote Down
David Barker answered 2 years ago

HI Sara
unfortunatley that does not work, But I think I have spotted the problem

Serial.println(myObject[“weather”][0][“main”]); produces weather:”Clouds” on the serial monitor ie json variable encluses in “”
So maybe we have to remove the”” before concatination  What do you think?
thanks again for your help

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

  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025
  • [eBook Updated] Learn ESP32 with Arduino IDE eBook – Version 3.2 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.