Introduction: NodeMCU (ESP8266) As Provider of Yahoo Weather
I've developed small library that can be used to access Yahoo Weather over NodeMCU and than provide it over serial port. This can be connected to anything with serial port with - for example Arduino. In such case you have simple way of accessing weather for your Arduino projects :)
When connecting ESP8266 to Arduino you will need voltage divider to convert 5v from Arduino to 3.3v.
Here is the source code: https://github.com/maciejmiklas/NodeMCUUtils
Step 1: YahooWeather.lua
yahooWeather.lua script provides access to Yahoo weather.
yaw.start() will obtain weather immediately and keep refreshing it every yaw.syncPeriodSec seconds. Weather data itself is stored in yahooWeather.lua -> yaw.weather, you will find there further documentation. In the example below you can see how to get wether for Munich and update it periodically:
require "yahooWeather" require "wlan" yaw.city = "munich" yaw.country = "de" wlan.setup("free wlan", "12345678") -- update weather every 17 minutes yaw.syncPeriodSec = 1020 yaw.responseCallback = function() print("Weather for today:", yaw.weather.date) print(yaw.weather.low, yaw.weather.high, yaw.weather.text) print("Weather for tomorrow:", yaw.weather.date) print(yaw.weather.low, yaw.weather.high, yaw.weather.text) end -- start weather update timer yaw.start()
Weather for today: 01 Sep 2016 18 25 Partly Cloudy Weather for tomorrow: 02 Sep 201616 25 Partly Cloudy
Step 2: Serial API
Script below registers Serial API Interface providing access to weather. Weather itself will get updated every 17 minutes.
require "serialAPI" require "serialAPIYahooWeather" yaw.city = "munich" yaw.country = "de" yaw.syncPeriodSec = 1020 -- 17 min -- setup wlan required by NTP clokc wlan.setup("fred", "1234567890") -- start serial API by enabling gpio and uart sapi.start() -- start yahoo weather with serial API yaw.start()
Now you can execute few simple commands over serial:
# weather description for today YF1 text Rain And Snow # weather description for tomorrow YF2 text Showers # not existing command YF1 min ERR:serialAPIYahooWeather.lua:6: attempt to concatenate field '?' (a nil value) # max temp for tomorrow >YF2 low 1 # weather date for today >YF1 date 09 Nov 2016
We have a be nice policy.
Please be positive and constructive.