Displays the current weather, date, and time
Dependencies: mbed MbedJSONValue mbed-rtos 4DGL-uLCD-SE ESP8266NodeMCUInterface
Welcome to the Smart Weather Clock, which uses WiFi and Bluetooth to give the user a clear date, time, and weather for the day.
This wiki serves to document
- What components you'll need
- How these components will be connected
- How the code gets all the information it needs
Components
LCD Screen
The LCD screen is a 128x128 pixel full color LCD by 4D Systems. A wonderful introduction can be found here.
In the simplest case, we'll only use one screen, but we can (and perhaps should) augment the design to include two.
Import library4DGL-uLCD-SE
Fork of 4DGL lib for uLCD-144-G2. Different command values needed. See https://mbed.org/users/4180_1/notebook/ulcd-144-g2-128-by-128-color-lcd/ for instructions and demo code.
You can buy it from sparkfun.
5V Adapter
The adapter allows us to feed much more power to the MBED and, critically, decouples us from a computer. It's important to remember that on the barrel jack adapter (i.e., the part that goes in the breadboard), the pin closest to the jack is 5V, and the back pin is Ground.
You can get the adapter here, and the barrel jack adapter here
Bluetooth UART Module
This module allows us to interface with the mbed via bluetooth and the ever-helpful AdaFruit Bluetooth App. A great introduction can be found here.
We'll use it to allow the user to set some defaults and API keys. This is stored in persistent flash storage on the LPC 1768 (See the Local File System, but you'll need an SD card if you're using a different MBED device.
You can get the Bluetooth module here.
WiFi Module
The WiFi module is also from AdaFruit, like the Bluetooth module. This allows us to interface with different WiFi networks for internet connectivity. A nice introduction is here.
You can get the WiFi module here.
WiFi Interface!
The current WiFi interface (found here) has some major problems - we're using an augmented version in our code!
Connections
5V Input for MBED
Before you connect the MBED to 5V from the wall, Make sure you have connected it correctly! If you don't, you could brick the MBED.
Thankfully, this is easy to test - when you think you have hooked up the 5V Jack correctly, try lighting a single LED (with a 10K resistor in series). If it lights up - you're good!
Alternatively, you could just plug in the MBED via USB, and just not have the MBED run on the +5V. You'll still need the Wall Adapter, however.
WiFi Module
The WiFi Module has two Grounds - you must connect both!
MBED | 5V Barrel Jack |
---|---|
Vin | +5V (back pin) |
Gnd | Gnd (pin closest to jack) |
MBED | uLCD Cable |
---|---|
5V | 5V |
Gnd | Gnd |
P09 | TX |
P10 | RX |
P11 | Reset |
MBED | Bluetooth UART |
---|---|
5V | Vin |
Gnd | Gnd |
Gnd | CTS |
P27 | TXO |
P28 | RXI |
MBED | WiFi Module |
---|---|
5V | V+ |
Gnd | Gnd |
Gnd | Gnd |
P13 | RX |
P14 | TX |
P15 | Reset |
Code
The code works in a fairly logical order:
- Connect to the given WiFi, and check that we have all of our API keys
- Get the current location via the IP API
- Get the current time via the TimeZoneDB
- Get the current weather via the OpenWeatherMap API
- Continually update the weather, once per minute
Some caveats:
- Memory seems to be an issue. If I had to guess, it would be the MbedJSONValue JSON parser - instantiating a third one seems to always lead to an MBED OS Fault or an MBED Memory Allocation fault. More insight is needed here.
- The off-the-shelf ESP8226 Interface doesn't handle receiving correctly - I had to augment the library with recv and recv2. It works in most simple practical use cases.
History
Make new node off by default
2019-05-24, by alexhrao [Fri, 24 May 2019 23:36:49 +0000] rev 13
Make new node off by default
Add demo for new node support
2019-05-24, by alexhrao [Fri, 24 May 2019 23:36:32 +0000] rev 12
Add demo for new node support
Add limited support for the new lua interpreter
2019-05-24, by alexhrao [Fri, 24 May 2019 23:19:29 +0000] rev 11
Add limited support for the new lua interpreter
Cleanup
2019-05-18, by alexhrao [Sat, 18 May 2019 17:57:20 +0000] rev 10
Cleanup
Change to use new keyword instead of manual instantiation
2019-04-05, by alexhrao [Fri, 05 Apr 2019 18:34:14 +0000] rev 9
Change to use new keyword instead of manual instantiation
Update ESP8226 link
2019-04-01, by alexhrao [Mon, 01 Apr 2019 17:00:17 +0000] rev 8
Update ESP8226 link
Prepare for commit
2019-04-01, by alexhrao [Mon, 01 Apr 2019 16:56:49 +0000] rev 7
Prepare for commit
Clean up device printing and comments
2019-04-01, by alexhrao [Mon, 01 Apr 2019 16:54:53 +0000] rev 6
Clean up device printing and comments
Get rid of hard-coded User/Pass
2019-04-01, by alexhrao [Mon, 01 Apr 2019 15:27:46 +0000] rev 5
Get rid of hard-coded User/Pass
Add credentials
2019-03-31, by alexhrao [Sun, 31 Mar 2019 15:39:50 +0000] rev 4
Add credentials