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
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
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
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
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
Hi Sara
Serial.println(myObject[“weather”][“main”]);
is captured on the serial monitor as
weather:null
regards
David
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
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
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
Hi again.
What is the issue you’re facing when trying to write to the microSD card?
Do you get any errors?
Regards,
Sara
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
Can you please share the relevant parts of code that save the problematic variable to the microSD card?
Regards,
Sara
hi
thisis the code
String weather;
weather =char(myObject[“weather”][0][“main”]);
thanks
David
I’m referring to the lines of code that write to the microSD card.
REgards,
Sara
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
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: “);
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