of events to occur. First, an HTTP GET request is built up
using the API_KEY and the LOCATION_STRING, and it is
sent to myweather2.com.
The returned weather data in JSON format is stored
line by line in a buffer for later processing. JSON or
simple data structures and objects in web browser based
code. See Resources for information about JSON if you
After all the data has been retrieved, it is passed to
the ArduinoJson parser which makes the various data
items easily accessible. All of the weather attributes
displayed on the five weather pages are extracted from
the returned JSON data.
Once new weather data has been acquired, the
dataAcquisitionCount variable is reinitialized to a time in
the future when new weather data will again be required.
Finally, the state is changed to CHECK_EVENTS for the
next pass through the loop.
The ADVANCE_DISPLAY state is entered when it is
time to change the displayed page. In this state, the LCD
display is cleared and the frame which is common to all
display pages is drawn around the perimeter of the
display. The displayPageNumber variable is then
incremented and wrapped around if necessary and the
new display page is shown.
Finally, displayAdvanceCount is reinitialized and the
state variable is set back to CHECK_EVENTS for the next
pass through the loop. In case it is not obvious, the
ESP8266 spends most of its time spinning in the
CHECK_EVENTS state — only changing states occasionally
when one of the three events occur.
Astute readers may be wondering how and when the
NTP time data gets updated since there are no references
to time update in the FSM. That is because time update is
handled behind the scenes in the Time library and so
doesn’t need to be explicitly performed in the weather
clock’s FSM code.
To build a weather clock of your own, connect the
Adafruit 1.8” LCD display to the NodeMCU Amica
module and then connect a DST pushbutton switch. Next,
connect a USB cable from the NodeMCU Amica module
to your development computer. After installing the
required libraries, bring up the Arduino IDE and load the
software for this article. Edit the User Configuration data
as described previously, and then compile and upload the
If you did everything correctly, you should have a fully
functional stand-alone weather clock of your own. NV
November 2016 27
■ FIGURE 9. Display page 7: NTP time and date
■ FIGURE 8. Display page 6: Next night forecast. ■ FIGURE 7. Display page 5: Next day forecast.