DisplayPages.h Code for each of the seven display pages.
Figures 3 through 9 show the
weather clock in operation. Each of
these images typify what I refer to as
a display page. Each display page
shows different information (refer to
LCD driver code specific to the Adafruit 1.8” (black
tab) display utilizing the hardware SPI interface of
ESP8266_ST7735.h Header file for the LCD driver code above.
Table 4), but all pages have a series
of seven small circles at the bottom
of the page to indicate which display
page is currently being shown.
Main program. Initializes the hardware, logs into the
local Wi-Fi network, and then installs the NTP code
as the time provider. It then manages the display of
the pages on the LCD.
When the weather clock
software first starts, there is (usually)
a short delay while three things
happen. First, the weather clock logs
into the local Wi-Fi network. Next,
the NTP clock code initializes and
makes a request over the Internet to
retrieve the time from an NTP time
server. Finally, weather data is
requested and retrieved from
myweather2.com. If all is well, the
first display page with the Wi-Fi icon
and credits is selected (Figure 3).
Icons.h Data for the Wi-Fi, sun, and moon icons. Data is in xbm format.
Misc.h Code for reading and writing the ESP8266’s EEPROM.
Functions for sending UDP packets to NTP servers
and retrieving the GMT time and converting it to
TGFunctions.h Misc functions for formatting text and graphical data for display on the LCD.
Weather class for sending weather data requests to
myweather2.com for retrieving the JSON data
stream returned, and then parsing the data to extract
the pertinent weather attributes for display by the
various display pages.
Weather.h Header file for the weather class above.
After a programmable length of time, the other
six display pages are sequentially shown. After
display page 7 (the NTP clock) is displayed, the
sequence repeats starting with display page 1.
Library Function Source
By default, time data is retrieved every five
minutes; weather data is retrieved every 15
minutes; and display pages are changed every
NOTE: This library had
to be modified for use
with the ESP8266, so it
is not the stock library.
Text and graphics
functions for the LCD
12 seconds. Of course, each of these time
intervals can be changed in the software. I
should point out that the acquisition of
weather and time data is completely disjoint
from its display. That is, these two processes
happen completely independent of each other.
improved version of
the Arduino library
ArduinoJson JSON parser https://github.com/bblan chon/ArduinoJson
The operation of the weather clock can best be
understood by examining the code in the file
Display Page Number Information Displayed
1 Wi-Fi Logo and Credits
ESP8266WeatherClock.ino. A Finite State Machine (FSM)
contained in the loop() function orchestrates everything.
Technically, an FSM is:
2 Current Weather Conditions
3 Day Conditions Forecast
“A model of a computational system, consisting of a
set of states, a set of possible inputs, and a rule to map
each state to another state, or to itself, for any of the
November 2016 25
4 Night Conditions Forecast
5 Next Day Conditions Forecast
6 Next Night Conditions Forecast
7 NTP Time and Data Display
Sounds daunting, but don’t let the definition scare
you. The operation is really quite simple. The weather
clock’s FSM is defined by this series of states:
which will each be described shortly. In addition, there is a
variable called state which tells the state machine which
state it is currently in. Transitions between the states
happen when certain events or inputs occur. The FSM is
guaranteed to be in one of the defined states every time
through the loop() function.
INIT, CHECK_EVENTS, ACQUIRE_DATA, ADVANCE_DISPLAY,