Read data from the web with Webhook

From UX point of view, I would like to be able to preview JSON in the app, choose the pairs that I would like to pass to the hardware.

Let’s say this is the JSON returned to V1:

{"results":{"sunrise":"5:43:55 AM","sunset":"6:55:05 PM","solar_noon":"12:19:30 PM","day_length":"13:11:10","civil_twilight_begin":"5:17:12 AM","civil_twilight_end":"7:21:47 PM","nautical_twilight_begin":"4:45:18 AM","nautical_twilight_end":"7:53:42 PM","astronomical_twilight_begin":"4:12:05 AM","astronomical_twilight_end":"8:26:55 PM"},"status":"OK"}

The interface can look like this quick draft:
Ideal interface should also parse substrings using (multiple) delimiters defined by user, for example
Space and “:” to simplify parsing further. (I’m not very good at JSONs, so it might be an unnecessary feature)

Then in the code:

hour = Blynk.parseJSON(V1, sunset[0]) // returns 6
min = Blynk.parseJSON(V1, sunset[1]) // returns 55
ampm = Blynk.parseJSON(V1, sunset[3]) // returns "PM"
3 Likes

It would be even more nice to assign a type to it. E.g. when I want a time, it could make me a time variable which I can use. In the above case it requires me to construct everything back to a time variable. It might not be needed for this kind of project, but when I’m working with multiple dates for scheduling, let’s say, parking time or walking my non-existing dog, it may come in handy to standardize everything to Unix time and have the user in the interface decide how to display it, e.g. AM, PM or 24-hour clock.

if i am using webhook to with this API: http://www.willyweather.com.au/api/docs/v2.html#forecasts-temperature

i just choose which bits of information i want?

or have i got this upside down? (I’m just checking before i get too deep into this!)

im going to try and write code so my house knows what the day might be like and configure the ventilation accordingly :slight_smile: (e.g. hot day predicted, get the cool air circulating early on, if cool day, no need to move any cool air…)

That should be basically it yes. You could write your own parser to proces the information, like I did, but the Blynk-guys obviously can improve on that and make life more easy for everyone. JSON is pretty much the standard.

cool cool! as long as i have the correct building blocks, i can usually get close (learn lots) and ask some dumb questions towards the end!

2 posts were split to a new topic: Requesting assistance with Webhook