[SOLVED] Web Sources for Pulling in Weather Data

Does anyone know if its possible or have specific examples where a source is actually an online resource for grabbing weather data like temp humidity etc…

The use case I have is currently I have built a temp and humidity devise for monitoring the inside of my plane hanger that send data to Ubidots. Instead of adding additional censors to also monitor outside temp and humidity I’m wondering if its possible to pull this data from an online source like Weather Underground from stations that are reasonably close to my hanger.

The two scenarios I envision is either programmatically including code within my existing code to grab variables from these online sources an embedding their values it into the existing code for sending to Ubidots OR creating a Source with variables within Ubidots as an independent mechanism for grabbing this data from these online sources.

Any examples that can be shared would be great.

I did see this existing thread within the community however not really sure how to proceed. (Sorry Virgin API guy)

Thank you Community!!

Hi @kbnetguy this is a great idea. The best scenario would be to have a server pull the Weather data and then post it to Ubidots. I just made a test using the Weather Underground API and pure shell -so you don’t have to code-. You should be able to replicate this by adding this line to a cron job, say every minute. If you need help setting up the cron job, we can put it in our servers, let us know at support@ubidots.com:

curl -X POST 'things.ubidots.com/api/v1.6/variables/<YOUR-VARIABLE-ID>/values?token=YOUR-UBIDOTS-TOKEN' -H 'Content-Type:application/json' -d "{\"value\":$(echo $(curl http://api.wunderground.com/api/YOUR-WUNDERGOUND-KEY/conditions/q/CA/San_Francisco.json 2>/dev/null) | python -c 'import json,sys;obj=json.load(sys.stdin);print obj["current_observation"]["temp_c"]')}"

If you run this line every minute using a cron job, it will update your Ubidots variable with the weather of San Francisco. To get Farenheit, change “temp_c” to “temp_f”. To get another city, change “San_Francisco.json” with another name and test the URL in your browser to make sure it’s supported by Weather Underground.

The way this works is:

  1. This line makes a GET request to the Weather API. If there’s an error, it sends it to /dev/null:

    curl http://api.wunderground.com/api/b644092e5axxx168/conditions/q/CA/San_Francisco.json 2>/dev/null

  2. if ran between $( ), the shell receives the pure JSON object.

  3. Then we filtered that command with:

    | python -c ‘import json,sys;obj=json.load(sys.stdin);print obj[“current_observation”][“temp_c”]’

    which is a “mini-Python-script” to load the JSON object and decode it. Make sure your OS has Python 2.7 at least. Steps 1-3 will throw a simple number (the temperature).

  4. Then we do a POST request to Ubidots, using curl and that number we got:

    curl -X POST ‘things.ubidots.com/api/v1.6/variables/YOUR-VARIABLE-ID/values?token=YOUR-UBIDOTS-TOKEN’ -H ‘Content-Type:application/json’ -d “{“value”: HERE-WE-PLACED-THE-RESULT-OF-THE-LINES-ABOVE}”

Hope this helps

1 Like

Thank you so much Ubidots for helping create a really nice solution for ingesting a Wundergorund .JSON file. The solution allows us to write certain data points from the .json file into predefined variables on ubidots. Were able to see local weather in real time on our website. We use it as another source of information prior to wheels up on our local runway.

Thanks guys!!!

UPDATE: Thanks to our new addition, Ubidots Plugins, you can pull weather data in just a few clicks. See this article on how to pull data from OpenWeather: