How to parse webpage JSON with temperatures in it.
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Mantas Dabrovolskas
am 21 Jun. 2023
Kommentiert: Jon
am 21 Jun. 2023
I am making a simple temperature graph with Thingspeak. I want to use my cities publicly available meteorology API - https://api.meteo.lt/v1/stations/vilniaus-ams/observations/2023-06-21
How would I read the temperature data and put it onto graph (merge it with inside temperature)?
Here is how I do it with my inside temperature sensor (I used standard Matlab example and edited it - added three hours to fix my time zone):
[dustData,Timestamps]=thingSpeakRead(XXXXXXX,'Fields',1,'NumPoints',100);
plot(Timestamps+hours(3),dustData,'red');
ylabel('Degrees');
title('Temperature');
grid on;
0 Kommentare
Akzeptierte Antwort
Jon
am 21 Jun. 2023
You can use webread
data = webread('https://api.meteo.lt/v1/stations/vilniaus-ams/observations/2023-06-21')
1 Kommentar
Weitere Antworten (1)
Lakshay Rose
am 21 Jun. 2023
Hi Mantas Dabrovolskas,
As per my understanding you are trying to read the JSON data returned from the API call from the mentioned URL.
You can follow the below steps to achieve the desired result –
- Retrieve the data from the API using the “webread” function in MATLAB. The API returns data in JSON format, so you'll need to parse it to extract the temperature values.
- Retrieve the inside temperature data from “ThingSpeak” using the “thingSpeakRead” function, similar to what you already have in your code.
- Merge both the dataset and plot the graph.
You can also refer to the documentation of “webread” for further information –
1 Kommentar
Jon
am 21 Jun. 2023
From my simple example above, it seems that webread already parses the contents and returns it in a structure, so it is not necessary to use jsondecode
Communitys
Weitere Antworten in ThingSpeak Community
Siehe auch
Kategorien
Mehr zu Web Services finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!