Weather Data from OpenWeatherMap

To get local weather information you do not need an own weather station. There are a lot of web-based weather stations collecting weather data from local weather stations around the world. To get an overview look for Top 10 Weather APIs.

If you want to use their weather data you have to consider the limited ressources of the ESP8266/NodeMCU devices. It is not possible to operate payloads of a few Kilobytes . The TCP/IP stack has its limitations.

I tried Yahoo Weather and Weather Underground but their responses were to big in size. After looking around I found openweathermap.org which offers a lot of data but fitting with the ressources of  ESP8266.

If you want to use this information you have to register at openweathermap.org to get an API key. I will name it myAPPID here. A free account offers no more than 60 calls/min respectively no more than 50’000 calls/day. This is quite enough for a call every minute.

The following call will request the data for my location:

http://api.openweathermap.org/data/2.5/weather?q=Altendorf,CH&APPID=myAPPID.

The response looks like

{“coord”:{“lon”:8.83,”lat”:47.19},”weather”:[{“id”:804,”main”:”Clouds”,”description”:”overcast clouds”,”icon”:”04d”}],”base”:”cmc stations”,”main”:{“temp”:282.67,”pressure”:1029,”humidity”:81,”temp_min”:282.15,”temp_max”:283.15},”wind”:{“speed”:1.5,”deg”:140},”rain”:{“3h”:0.0175},”clouds”:{“all”:90},”dt”:1450273800,”sys”:{“type”:3,”id”:6007,”message”:0.004,”country”:”CH”,”sunrise”:1450249519,”sunset”:1450280128},”id”:2661776,”name”:”Altendorf”,”cod”:200}

The NodeMCU application has to call the server and has to evaluate the response sent from server back to the NodeMCU device. The NodeMCU (Lua) script getWeather.lua is saved at Sourceforge.

weather

After downloading the script getWeather.lua to the the NodeMCU device we will get weather data every minute.

Access data to the router and the API key myAPPID are saved in the file credentials.lua  called from init.lua to hide them.

 

Advertisements
Weather Data from OpenWeatherMap

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s