B4R Question Does B4R have a way of reading JSON files?

RHays

New Member
Licensed User
Longtime User
Sorry, still new to this, and I have been looking but have not seen much. I want to pull data from Dark Sky API and get the current weather where I am at. If I have to build something I will look into it but I did not want to reinvent the wheel if it is already there. I saw a library out there for B4J, and I know B4R is new. So if anyone can point me in the right direction.

Thanks
Rick
 

warwound

Expert
Licensed User
Longtime User
I used ArduinoJson library in a project based on a Mega2560 (programming in the arduino IDE) and it worked very well.
On microcontrollers with less memory there could be problems but the Mega2560 has loads of memory.

I've not got into b4r, preferring the arduino IDE.
Can the above library be used in b4r?
 
Last edited:
Upvote 0

RHays

New Member
Licensed User
Longtime User
Thanks everyone for your suggestion, as said kinda new to all this, I will look at this ArduinoJson. I will also look at the ByteConverter as suggested to see if that will get me by, as yes micro is small and so is the memory, something else I have to get use too.

Can I suggest a simple JSON library for the arduino, as more boards are becoming wifi enabled (ESP8266, ESP32, etc.) and it is very common to get data returned from API's as JSON, just a basic parser to an object.

I found this on the web: https://blog.squix.org/2016/10/esp8266-weather-station-color-code-published.html. This looked like fun, and gave me a goal. I have not looked at the code nor do I want too. I just want to take there idea and build it. I get my weather from Dark Sky API, this is a JSON return data string.

So I may have more questions in the future but for now thanks for the help.

Thanks
Rick
 
Upvote 0

RHays

New Member
Licensed User
Longtime User
This is from: https://darksky.net/dev/docs/forecast

----------

When you send this to Dark Sky API
https://api.darksky.net/forecast/0123456789abcdef9876543210fedcba/42.3601,-71.0589

----------

You get this back from the API

{
"latitude": 47.20296790272209,
"longitude": -123.41670367098749,
"timezone": "America/Los_Angeles",
"currently": {
"time": 1453402675,
"summary": "Rain",
"icon": "rain",
"nearestStormDistance": 0,
"precipIntensity": 0.1685,
"precipIntensityError": 0.0067,
"precipProbability": 1,
"precipType": "rain",
"temperature": 48.71,
"apparentTemperature": 46.93,
"dewPoint": 47.7,
"humidity": 0.96,
"windSpeed": 4.64,
"windBearing": 186,
"visibility": 4.3,
"cloudCover": 0.73,
"pressure": 1009.7,
"ozone": 328.35
},
"minutely": {
"summary": "Rain for the hour.",
"icon": "rain",
"data": [
{
"time": 1453402620,
"precipIntensity": 0.1715,
"precipIntensityError": 0.0066,
"precipProbability": 1,
"precipType": "rain"
},
...
]
},
"hourly": {
"summary": "Rain throughout the day.",
"icon": "rain",
"data": [
{
"time": 1453399200,
"summary": "Rain",
"icon": "rain",
"precipIntensity": 0.1379,
"precipProbability": 0.85,
"precipType": "rain",
"temperature": 48.16,
"apparentTemperature": 46.41,
"dewPoint": 46.89,
"humidity": 0.95,
"windSpeed": 4.47,
"windBearing": 166,
"visibility": 3.56,
"cloudCover": 0.39,
"pressure": 1009.97,
"ozone": 328.71
},
...
]
},
"daily": {
"summary": "Light rain throughout the week, with temperatures bottoming out at 48°F on Sunday.",
"icon": "rain",
"data": [
{
"time": 1453363200,
"summary": "Rain throughout the day.",
"icon": "rain",
"sunriseTime": 1453391560,
"sunsetTime": 1453424361,
"moonPhase": 0.43,
"precipIntensity": 0.1134,
"precipIntensityMax": 0.1722,
"precipIntensityMaxTime": 1453392000,
"precipProbability": 0.87,
"precipType": "rain",
"temperatureMin": 41.42,
"temperatureMinTime": 1453363200,
"temperatureMax": 53.27,
"temperatureMaxTime": 1453417200,
"apparentTemperatureMin": 36.68,
"apparentTemperatureMinTime": 1453363200,
"apparentTemperatureMax": 53.27,
"apparentTemperatureMaxTime": 1453417200,
"dewPoint": 46.79,
"humidity": 0.95,
"windSpeed": 4.26,
"windBearing": 150,
"visibility": 4.02,
"cloudCover": 0.77,
"pressure": 1009.35,
"ozone": 326.69
},
...
]
},
"alerts": [
{
"title": "Flood Watch for Mason, WA",
"time": 1453375020,
"expires": 1453407300,
"description": "...FLOOD WATCH REMAINS IN EFFECT THROUGH LATE FRIDAY NIGHT...\nTHE FLOOD WATCH CONTINUES FOR\n* A PORTION OF NORTHWEST WASHINGTON...INCLUDING THE FOLLOWING\nCOUNTY...MASON.\n* THROUGH LATE FRIDAY NIGHT\n* A STRONG WARM FRONT WILL BRING HEAVY RAIN TO THE OLYMPICS\nTONIGHT THROUGH THURSDAY NIGHT. THE HEAVY RAIN WILL PUSH THE\nSKOKOMISH RIVER ABOVE FLOOD STAGE TODAY...AND MAJOR FLOODING IS\nPOSSIBLE.\n* A FLOOD WARNING IS IN EFFECT FOR THE SKOKOMISH RIVER. THE FLOOD\nWATCH REMAINS IN EFFECT FOR MASON COUNTY FOR THE POSSIBILITY OF\nAREAL FLOODING ASSOCIATED WITH A MAJOR FLOOD.\n",
"uri": "http://alerts.weather.gov/cap/wwaca...WA.SEWFFASEW.38e78ec64613478bb70fc6ed9c87f6e6"
},
...
],
{
"flags": {
"units": "us",
...
}
}
 
Upvote 0

pappicio

Active Member
Licensed User
Longtime User
This is from: https://darksky.net/dev/docs/forecast

----------

When you send this to Dark Sky API
https://api.darksky.net/forecast/0123456789abcdef9876543210fedcba/42.3601,-71.0589

----------

You get this back from the API

{
"latitude": 47.20296790272209,
"longitude": -123.41670367098749,
"timezone": "America/Los_Angeles",
"currently": {
"time": 1453402675,
"summary": "Rain",
"icon": "rain",
"nearestStormDistance": 0,
"precipIntensity": 0.1685,
"precipIntensityError": 0.0067,
"precipProbability": 1,
"precipType": "rain",
"temperature": 48.71,
"apparentTemperature": 46.93,
"dewPoint": 47.7,
"humidity": 0.96,
"windSpeed": 4.64,
"windBearing": 186,
"visibility": 4.3,
"cloudCover": 0.73,
"pressure": 1009.7,
"ozone": 328.35
},
"minutely": {
"summary": "Rain for the hour.",
"icon": "rain",
"data": [
{
"time": 1453402620,
"precipIntensity": 0.1715,
"precipIntensityError": 0.0066,
"precipProbability": 1,
"precipType": "rain"
},
...
]
},
"hourly": {
"summary": "Rain throughout the day.",
"icon": "rain",
"data": [
{
"time": 1453399200,
"summary": "Rain",
"icon": "rain",
"precipIntensity": 0.1379,
"precipProbability": 0.85,
"precipType": "rain",
"temperature": 48.16,
"apparentTemperature": 46.41,
"dewPoint": 46.89,
"humidity": 0.95,
"windSpeed": 4.47,
"windBearing": 166,
"visibility": 3.56,
"cloudCover": 0.39,
"pressure": 1009.97,
"ozone": 328.71
},
...
]
},
"daily": {
"summary": "Light rain throughout the week, with temperatures bottoming out at 48°F on Sunday.",
"icon": "rain",
"data": [
{
"time": 1453363200,
"summary": "Rain throughout the day.",
"icon": "rain",
"sunriseTime": 1453391560,
"sunsetTime": 1453424361,
"moonPhase": 0.43,
"precipIntensity": 0.1134,
"precipIntensityMax": 0.1722,
"precipIntensityMaxTime": 1453392000,
"precipProbability": 0.87,
"precipType": "rain",
"temperatureMin": 41.42,
"temperatureMinTime": 1453363200,
"temperatureMax": 53.27,
"temperatureMaxTime": 1453417200,
"apparentTemperatureMin": 36.68,
"apparentTemperatureMinTime": 1453363200,
"apparentTemperatureMax": 53.27,
"apparentTemperatureMaxTime": 1453417200,
"dewPoint": 46.79,
"humidity": 0.95,
"windSpeed": 4.26,
"windBearing": 150,
"visibility": 4.02,
"cloudCover": 0.77,
"pressure": 1009.35,
"ozone": 326.69
},
...
]
},
"alerts": [
{
"title": "Flood Watch for Mason, WA",
"time": 1453375020,
"expires": 1453407300,
"description": "...FLOOD WATCH REMAINS IN EFFECT THROUGH LATE FRIDAY NIGHT...\nTHE FLOOD WATCH CONTINUES FOR\n* A PORTION OF NORTHWEST WASHINGTON...INCLUDING THE FOLLOWING\nCOUNTY...MASON.\n* THROUGH LATE FRIDAY NIGHT\n* A STRONG WARM FRONT WILL BRING HEAVY RAIN TO THE OLYMPICS\nTONIGHT THROUGH THURSDAY NIGHT. THE HEAVY RAIN WILL PUSH THE\nSKOKOMISH RIVER ABOVE FLOOD STAGE TODAY...AND MAJOR FLOODING IS\nPOSSIBLE.\n* A FLOOD WARNING IS IN EFFECT FOR THE SKOKOMISH RIVER. THE FLOOD\nWATCH REMAINS IN EFFECT FOR MASON COUNTY FOR THE POSSIBILITY OF\nAREAL FLOODING ASSOCIATED WITH A MAJOR FLOOD.\n",
"uri": "http://alerts.weather.gov/cap/wwaca...WA.SEWFFASEW.38e78ec64613478bb70fc6ed9c87f6e6"
},
...
],
{
"flags": {
"units": "us",
...
}
}
I had same problem , then I used rhttputils, and job.response giva me all infos I need, I trucnate also all job.response, (around 2500 chrs, too large....) before and after, only to have less memory ovvupied by response and to have only data I need, works well!!!
 
Upvote 0
Top