Getting weather data through external API

Hi Blynk friends! I’m trying to understand how I can get data from a third part api service to Blynk.

I want to get precipitation values 1 time a day from SMHI and write that to a virtual pin. So I can make automations around them.

opendata-download-metobs.smhi.se/api/version/1.0/parameter/5/station/68560/period/latest-day/data.json

More info about the API
https://opendata.smhi.se/apidocs/metobs/demo.html?fbclid=IwAR31rh1qW5ay2lcz0fWBy7Ga1eofgywFcKiZhryCWgwb587Z5CX-5ltMfm4

What is the best way to do that? Can i do it in settings for webhooks in blynk? Or does it need to be coded in the Arduino IDE?

I’m a full blown rockie on these things FYI.

You should be able to - give it a try.

That would be my preferred solution, although I’d probably use OpenWeather. There are some examples of how to do this with OpenWeather on the forum if you search.

Pete.

1 Like

Well, ive been struggeling with it for a day now :joy:

And I’ve been getting some data but I have no idea what it is.

I added this link in the webhook url in settings for dev in Blynk. I get ok as respond when I’m doing the test button thing.

opendata-download-metobs.smhi.se/api/version/1.0/parameter/5/station/68560/period/latest-day/data.json

I would like to se how something else is setup that way. Could some one share a screenshot so I perhaps can understand it a little better?

Well, ive been struggeling with it for a day now :joy:

And I’ve been getting some data but I have no idea what it is.

Running this service on AWS Lambda seams like something that generally is recommended on the forum?

Sorry, don’t understand the question.

Pete.

Is it the same data you get when you past that url into a browser?

Pete.

It should be, right? But I format that pin as number, not string. So I’m not sure?

This is my setup at the moment in the api settings. That does not do the job. Is there a really simple thing I don’t see? Can I select the value in some way so it just writes that? Would love for it to be that simple so I can add other sources the same way.

It was simply a question.
As you’re using a url that ends in .json then I would assume you’d use Custom JSON for the content type, but TBH I’m not going to spend any time reading the docs for your web service API.

You’re calling an API which returns a lot of data that needs to be parsed. That’s not a simple task, so the answer is no.

Pete.

Thanks a lot Pete! Parsed was a new word on my list. That took me to postman for testing. And there i’m sucsesfully getting the specific value I want in the console.

bodydata = JSON.parse(responseBody)
value = bodydata.value[0].value
console.log(value)

https://www.postman.com/joelkvarnsmyr/workspace/my-workspace/request/20983321-01e312f5-3fd5-40b0-81a0-2ffee68fdbb5

But still i’m nowhere… close to give up.

If 3-d party service has a response, it is forwarded back to the device/pin you specified in the webhook. Webhook response can’t be parsed on the console (while that is a good thing to have), but it can be parsed on the hardware side. In other words, webhook response is fully forwarded to the hardware.

So if your service returns json, you have to parse this json on the hardware side. In order to test this, you can just print the value when hardware receives the data in specific pin:

BLYNK_WRITE(V25){
   print(param.asStr());
}
2 Likes

You might want to look at thus example as a way of extracting one or two pieces of data from an API response.
Otherwise you can use the JSON library and use that to deserialise and extract the data.

Pete.

1 Like