Home Fab Academy Notes Unsorted References (Powered by StrapDown.js) <!-- Markdown text entered here --> # IOT Clock Project This project was created to give a simplet introduction into the Internet-Of-Things using the ESP8266 chip and python programming. ## Requirements * References: * [Micropython for ESP8266](https://docs.micropython.org/en/latest/esp8266/index.html) * [Micropython on ESP8266 Workshop](http://micropython-on-wemos-d1-mini.readthedocs.io/en/latest/) * [Micropython forum](https://forum.micropython.org/) * Components * [WEMOS Electronics D1-Mini](https://wiki.wemos.cc/products:d1:d1_mini): ESP8266, [DHT-11](https://wiki.wemos.cc/products:d1_mini_shields:dht_shield) Shield, [Dual Base](https://wiki.wemos.cc/products:d1_mini_shields:dual_base) Shield. Ref: [D1-Mini Shields](https://wiki.wemos.cc/start#d1_mini_shields) * [TM1637 4-Digit LED]((http://wiki.seeed.cc/Grove-4-Digit_Display/)) Tube from Seeed Studios * Laser cut casings (option A - closed) and (optino B - open) * Connecting wires &amp; pins * 20mm heat-shrink sleeving * Blue Tack or mounting tape (25x25mm) * Tools * Laptop - Windows10, [CH340 USB](https://sparks.gogo.co.nz/ch340.html) driver, Adafruit Micropython Tool [ampy](https://github.com/adafruit/ampy), [Portable Putty](https://portableapps.com/apps/internet/putty_portable), web-browser * Micro-usb cable * Soldering iron station with fine bit * Multimeter with continuity testor * Pliers, Cutters, Wire Strippers, scissors * Wireless Router with SSID (T14Fablab/passwd) with internet access * Bill-of Materials for [Option A](iotclock-assets/IOT_BOM_Option_A.docx), [Option B](iotclock-assets/IOT_BOM_Option_A.docx) in `docx` printable format. ## Build The WeMOS D1-mini shields come unsoldered. Normal purchase is from [Alixexpress](https://www.aliexpress.com/premium/d1-mini-shield-esp8266.html) with at least a 3 week lead time. When the boards arrive, you will need to solder the Base board, the ESP8266 boards and prepare the wires. Approximate lead time: 3 days [Preparation Stage](iotprep.html) - You will need to build the firmware to include the TM1637 library and flash the firmware into the WeMOS D1. Approximate lead time: 3 hours The casings need to be fabricated as well. Approximate lead time: 1 day ### BOM This is the Bill-of-Materials for a typical build (Type A). Listings for Type A (Closed Box) and Type B (Open face) are listed below for printing. |Qty |Description |Remarks | |-----|-----------------------|----------------------------------| |1 |Dual Base WeMOS D1 Mini|| |1 |WeMos D1 Mini|ESP8266 flashed with micropython, tm1637 libraries| |1 |TM1637 LED tube|4-digit LED Tube display| |1 |DHT-11|Humidity &amp; temperature sensor| |1 |Box enclosure|Front, back,2xsides,2xtop| |1 |Wire Male Dupont Pin-Bare End - Red|3.3V| |1 |Wire Male Dupont Pin-Bare End - Black|Gnd| |1 |Wire Male Dupont Pin-Bare End - Yellow|TM1637 CLK| |1 |Wire Male Dupont Pin-Bare End - Grey|TM1637 DIO| |1 |Wire Male Dupont Pin-Bare End - Green|DHT-11 Signal| |2 |Wire Bare-Bare - Black|&nbsp;| |2 |Wire Bare-Bare - Red|&nbsp;| |10|Heat shrink sleeve|&nbsp;| For printing: [BOM type A](iotclock-assets/IOT_BOM_Option_A.docx), [BOM type B](iotclock-assets/IOT_BOM_Option_B.docx) ## Wiring configuration ![Wiring Diagram](iotclock-assets/iotclock-wiring-diagram.png "IOT Clock Wiring Diagram") The wires for the IOT project are colour coded. |Colour|Function |WeMos D1 |DHT11 |TM1637 | |------|-----------------|-----------|--------|--------| |Red |Vcc +3.3V |3.3V |Vcc |Vcc | |Black |GND Ground |Gnd |Gnd |Gnd | |Green |DHT11 data signal|D4 (GPIO 2)|Data |&nbsp; | |Yellow|TM1637 Clk |D1 (GPIO 5)|&nbsp; |Clk | |Grey |TM1637 Data IO |D2 (GPIO 4)|&nbsp; |Dio | As there are 2 components (DHT-11, TM1637) to be connected to the CPU, you need to join the Vcc and GND wires to form a y-shape to provide power and ground to them. **Note** that the ESP8266 works on **3.3V**. 1. Solder the Vcc and GND wires to form the Y-connections first. Use the heat shrink sleeving to isolate the joints. 2. Solder the Vcc, GND and DHT-11 (Green) wires to the DHT-11. Use the heat-shrink wraps to isolate the pins of the DHT-11 from each other. Use the hot-air rework station to shrink the sleevings. 3. Insert the female Dupont pins into the female socket following the sequence as shown in the image. Push the pins into the socket until you hear a 'click'. 4. Use the multitester to check your connectivity. ![WeMOS D1 Pin Mappings](iotclock-assets/esp8266-wemos-d1-mini-pinout.png) ***WeMost D1 Pins and Diagram (https://escapequotes.net/esp8266-wemos-d1-mini-pins-and-diagram/)*** ## Casing Design There are 2 casing designs - a closed box and an open face. You can choose either enclosure to house your circuit. The designs are done using Fusion 360, assembled and simulated before laying flat to be cut using a Laser cutter. <section class="info"> <a href="iotclock-assets/iotclock_A.jpg" target="_blank" <figure class="infoimg"> <img class="w320" src="iotclock-assets/iotclock_A.jpg" alt="Option A Closed Box" /> <figcaption>Option A Closed Box</figcaption> </figure> </a> <a href="iotclock-assets/iotclock_B.jpg" target="_blank" <figure class="infoimg"> <img class="w320" src="iotclock-assets/iotclock_B.jpg" alt="Option B Closed Box" /> <figcaption>Option B Open Enclosure</figcaption> </figure> </a> <div class="infoclr"></div> </section> <!--End of Section.info--> [Open Enclosure B](iot_fusion_b.html) drawing instructions for Fusion 360 ## Initial testing You will need * a PC (definitely ***NOT*** a staff PC with restrictions) * Adafruit MicroPython loader (ampy) * CH340 USB driver * local wireless network router (SSID: Fablab14, Password: XXXXXX) * MicroUSB cable ### Communicating with the ESP8266 You can get more information on the installation of the CH340/341 drivers from [sparks.gogo.nz](https://sparks.gogo.co.nz/ch340.html). Extracted from [Connecting to the ESP8266 REPL](http://docs.micropython.org/en/v1.9.3/wipy/wipy/tutorial/repl.html) ### Using the ESP8266 with Windows 1. You first need to install the [CH340 drivers](http://www.wch.cn/download/CH341SER_EXE.html) on your system. CH340 is a common chipset in use with the Chinese Uno-type boards and other peripherals. 2. Restart your system after installing the drivers. 3. Open Device Manager and look for the entry which shows the COM ports. Expand this option. 4. Plug in the USB cable which connects the ESP8266, if your drivers have been installed correctly, you will see an additional COM port listed in the Device Manager. Take note of the COM port number, you will use this to configure the Terminal Emulation program to communicate with the device. 5. Run PuTTY and enter your COM port, select the serial interface with a speed of 115200 bps, 8 bit 1 stop 0 parity. You will also need to turn OFF XON/XOFF flow control. You should save your settings so that you can return to them easily later. 6. Open the interface and you should be presented with a blank screen, press RETUEN a couple of times to get the Micropython REPL prompt. <section class="info"> <a href="iotclock-assets/device-manager-ch340.png" target="_blank" <figure class="infoimg"> <img class="w200" src="iotclock-assets/device-manager-ch340.png" alt=" Alt Text" /> <figcaption>Device Manager showing CH340 installed as COM4</figcaption> </figure> </a> <a href="iotclock-assets/putty-settings-01.png" target="_blank" <figure class="infoimg"> <img class="w200" src="iotclock-assets/putty-settings-01.png" alt=" Alt Text" /> <figcaption>PuTTY Settings for Serial transfer</figcaption> </figure> </a> <a href="iotclock-assets/putty-settings-02.png" target="_blank" <figure class="infoimg"> <img class="w200" src="iotclock-assets/putty-settings-02.png" alt=" Alt Text" /> <figcaption>PuTTY Settings for Data flow control</figcaption> </figure> </a> <a href="iotclock-assets/micropython-repl.png" target="_blank" <figure class="infoimg"> <img class="w200" src="iotclock-assets/micropython-repl.png" alt=" Alt Text" /> <figcaption>MicroPython REPL in terminal window</figcaption> </figure> </a> <div class="infoclr"></div> </section> <!--End of Section.info--> #### Ampy In order to transfer programs to/from the ESP8266 we use an application called [Adafruit MicroPython Tool (ampy)](https://learn.adafruit.com/micropython-basics-load-files-and-run-code/install-ampy). To install this application, we need to 1. Download and [install Python](https://www.python.org/). We suggest using v2.7, however v3.5/3.6 will also work. The installation would also include `pip` (Python Package Management). 2. Install ampy using `pip install adafruit-ampy`. 3. When installation is complete, you should be able to use ampy to communicte with the ESP8266 board. 4. You can get help for ampy by typing `ampy --help` in the terminal. **NOTE** You cannot run PuTTY and ampy simultaneously. In order to use ampy, you must first terminate the PuTTY connection and vice versa. <section class="info"> <a href="iotclock-assets/install_python.png" target="_blank" <figure class="infoimg"> <img class="w200" src="iotclock-assets/install_python.png" alt=" Alt Text" /> <figcaption>Python Installation</figcaption> </figure> </a> <a href="iotclock-assets/install_ampy.png" target="_blank" <figure class="infoimg"> <img class="w200" src="iotclock-assets/install_ampy.png" alt=" Alt Text" /> <figcaption>Installing ampy</figcaption> </figure> </a> <a href="iotclock-assets/ampy-help.png" target="_blank" <figure class="infoimg"> <img class="w200" src="iotclock-assets/ampy-help.png" alt=" Alt Text" /> <figcaption>ampy help information</figcaption> </figure> </a> <div class="infoclr"></div> </section> <!--End of Section.info--> ### Using the ESP8266 with Linux (Ubuntu 16.04) * Open a Terminal window, use `lsusb` to check on the devices connected. * Plug-in the ESP8266 * Use `lsusb` to check that the driver `CH340xxxxx` is active, use ls /dev/ttyUSB* to check for the port. ``` $ lsusb ... Bus 001 Device 012: ID 1a86:7523 QinHeng Electronics HL-340 USB-Serial adapter ,,, $ ls -l /dev/ttyU* crw-rw---- 1 root dialout 188, 0 Peb 19 17:22 /dev/ttyUSB0 ``` * Your board is working and connected! ### Using the ESP8266 with MACOSX (High Sierra) 1. Install the CH340 drivers using the instructions found at [adrianmikalko's site](https://github.com/adrianmihalko/ch340g-ch34g-ch34x-mac-os-x-driver). The drivers here seem to work better than the ones at the chinese site or at sparks.gogo.nz. 2. Restart the computer. 3. Plug in the ESP8266. You can check whether the board is recognised (and drivers installed correctly) by opening a terminal window and typing `system_profiler SPUSBDataType` which is a Linux `lsusb` equivalent. (Using the Prferences &gt; System Resources does not show the device) ```bash $ system_profiler SPUSBDataType # show output here ``` 4. You can also see the port at `/dev/ttyWCHxxxx` if you do a `ls -l /dev/tty*` 5. Connect to the ESP8266 using `screen /dev/tty.WCHxxx 115200`. You can exit screen using 'CTRL-A CTRL-\'. **NOTE:** There is macosx lsusb equivalent here: [jihnona/lsusb](https://github.com/jlhonora/lsusb) # Problems Sometimes the WeMOS ESP8266 has been initialised to connect to a WLAN network connection, however the connection is *NOT* present. Then the WeMOS will continually try connecting (without sucess) and display its messages on the screen. In this case, we need to *STOP* the scanning and put the WeMOS into monitor mode. Ignore the messages that stream on the PuTTY screen and type the following (case sensitive) ``` import network sta = network.WLAN(network.STA_IF) sta.active(False) ``` This will put you in the monitor mode in which you can disable the network scanning. Alternatively, you could install [Coolterm](http://freeware.the-meiers.org/) which is a terminal monitor which sepaates the input line with the output. ### Starting Python Your ESP8266 can be programmed in different methods. The easiest is to use `Micropython` which is a subset of Python. With the large memory size available, Micropython makes it easy to access and develop complicated programs easily. * Python is a modern day high-level programming language which is English-like, powerful and implementable in microcontrollers. * Some pointers about Python * uppercase and lowercase are different * multiple whitespace is often ignored * tabls are used to indiate levels/hierarchy/nesting of code * the language is interactive * print "Hello world!" * Arithmetic and simple statements * Repetition (over a fixed number of times) ```python for i in range(1,5): print i, "hello" <press return again> ``` * From the above, what can you observe? * How many iterations are run? * Why do you need a `TAB` or indentation for the second line? * How can you run the code again? * type it in again (groans!) * use a function, and call it over and over again ```python def loop5(): for i in range(0,5): print i, "hello, there!" <press return twice> ``` execute the code (repeatedly) using `loop5()` * write the code in a text editor, send it over using `ampy` * `ampy` allows us to list, load or read programs from the ESP8266 unit. Hence, we are now able to write longer programs and then load it. You need to exit from PuTTY/terminal program before you can use `ampy`. * Before we start writing longer programs, let us examine what the ESP8266 has to offer. ### Modules The `Micropython` installed on the ESP8266 has a number of libraries that allow us to use the functions of the device. These libraries are called **modules**. In order to use a module, you need to `import` the module into the workspace. The functions within the module are now called using *module-name*.function-name. **Note** How do we know what functions are available in a module? Use the `dir()` function. ```python # what modules do I have >>> dir() ['bdev', 'os', '__name__', 'gc', 'uos', 'Pin', 'vfs', 'led'] # what functions does os have >>> dir(os) >>> import os ['__name__', 'uname', 'urandom', 'dupterm', 'dupterm_notify', 'VfsFat', 'listdir', 'mkdir', 'rmdir', 'chdir', 'getcwd', 'remove', 'rename', 'stat', 'statvfs', 'mount', 'umount'] ``` #### Ex1 Light Up LED In this example we will light up the LED on the WeMOS board. There are General Purpose Input Output (GPIO) pins available on the board. The onboard Blue LED is connected to GPIO 2. We should be able to light up the LED by bringing this pin to `LOW`. [Ref](http://micropython-on-wemos-d1-mini.readthedocs.io/en/latest/basics.html#blink) ```python # import the Pin function from the machine module from machine import Pin # initialise the gpio2 to output led = Pin(2, Pin.OUT) # write a LOW, to light up the LED led(0) ``` #### Ex2 Blink LED In this example we will make the LED blink 10 times. We use the `time` module to provide the necessary timing for 0.5 seconds. Note that the entire time module is imported, hence we address each individual function from `time` by using the `.` (dot) operator. ```python from machine import Pin import time # intialise gpio2 to output led = Pin(2, Pin.OUT) # blink it for i in range(10): led(1) time.sleep_ms(500) led(0) time.sleep_ms(500) ``` Our programs are getting a little larger, hence, it would be appropriate to write the source code using a text editor (e.g. Notepad++, SublimeText, Gedit) and then transfer the file to the ESP8266 for execution. The program that we use is called ampy (Adafruit Micropython Tool). Let us assume that the name of the program is `ex2.py`. ```python # install adafruit-ampy using pip sudo pip install adafruit-ampy # see the options available ampy --help # transfer the file to the esp8266 ampy --port /dev/ttyUSB0 run ex2.py ``` #### Ex3 Using functions What happens if you did not use `run`? ampy will load the program into the memory, but will not run it. The best way to do this is to re-write the code as a function. Let us now call this ex3.py ```python # ex3.py from machine import Pin import time # intialise gpio2 to output led = Pin(2, Pin.OUT) # function to blink led def blink(): for i in range(10): led(1) time.sleep_ms(500) led(0) time.sleep_ms(500) ``` Use ampy to load the program into the esp8266 ``` ampy --port /dev/ttyUSB0 put ex3.py ``` We now can import the module (ex3) and then call the function blink() ``` >>> import os >>> os.listdir() ['boot.py', 'iot.py', 'ex3.py'] >>> import ex3 >>> ex3.blink() ``` ### DHT11 DHT11 is a temperature and humidity sensor ([How DHT11 works](http://howtomechatronics.com/tutorials/arduino/dht11-dht22-sensors-temperature-and-humidity-tutorial-using-arduino/)). The process involves sending a signal to the sensor and then reading the results from the other pin. Micropython makes it easier for us - [Ref: Micropython DHT11](http://micropython-on-wemos-d1-mini.readthedocs.io/en/latest/shields.html#dht-and-dht-pro). The DHT11 requires the use of **gpio2** on the WeMOS D1-mini. We use error checking and trapping to ensure that we get correct values from our dht module. ```python # import libraries from machine import Pin import dht # assign the gpio2 port dh11 = dht.DHT11(Pin(2)) # for error checking error = False try: dh11.measure() except: # error, take old values error = True pass if error : print ("dht error") else: temperature = dh11.temperature() humidity = dh11.humidity() ``` You can test the above code interactively before you implement it in your main program. ### TM1637 The TM1637 is a 4-digit 7-segment LED tube which can be controlled using 2 pins - CLK and DIO. The TM1637 library has to be included into the flash by compiling and adding the library. Ref: Micropython libraries and modules - [Micropython-tm1637](https://github.com/mcauser/micropython-tm1637) is also available in the Python library. ```python # library import tm1637 from machine import Pin # initialise using gpio4 and gpio5 tm = tm1637.TM1637(clk=Pin(5), dio=Pin(4)) ``` The [TM1637 library](https://github.com/mcauser/micropython-tm1637#methods) has a number of functions, some of the more useful ones are * `brightness(val=None)` get or set the brightness of the display * `tm.write( [led1, led2, led3, led4] )` * where led1 is the binary code for the 7-segment led, where `1` lights up the segment, e.g. to display 0 = 0x3F, 0x06 = 1, 0x5B = 2, 0x4F = 0x4F. To add a ':' to the display, add 128 to led2. * Hence, to display 12:34, we would need to use `tm.write(0x3F, 0x06+128, 0x5B, 0x4F) * the conversion table can be found here: [Seven segment font](https://github.com/mcauser/micropython-tm1637#seven-segment-font). * `encode_digit(hexadecimal)` converts a hexadecimal (0-0xF) into the seven-segment code. #### Display temperature Displays `t :28` which stands for temperature 28 on the tm1637. ```python import tm1637 from machine import Pin # initialise the display tm = tm1637.TM1637(clk=Pin(5), dio=Pin(4)) tm.brightness(4) # display the temperature ledT = 0b1111000 # 7-seg code for t dig1 = tm.encode_digit(temperature // 10) # int div, extract 10s digit, convert dig0 = tm.encode_digit(temperature % 10) # modulus, extract 1s digit, convert tm.write( [ledT, 128, dig1, dig0] ) ``` #### Networking The ESP8266 has an inbuilt network stack. In order to connect to the network, we first initialise the drivers, scan for the appropriate network we want to connect to, specify the SSID, username and password and connect. ``` # library import network # configuration SSID = "FABLABXX" # name of network, change to your own KEY = "ppaasswwoorrdd" # network password, change to your own # reset network def reset_network(): global sta sta = network.WLAN(network.STA_IF) ap = network.WLAN(network.AP_IF) # sta.active(False) ap.active(False) return # initialise the network def do_connect(): import network, time global sta if not sta.isconnected() : sta.active(True) sta.connect(SSID, KEY) # try to connect while not sta.isconnected(): print('.', end='') time.sleep(1) sta.ifconfig() return # my main program def main(): reset_network() do_connect() # should connect to network # if there is a dhcp server, the ip address would be awarded ``` **IMPORTANT** If you examine the code, you will find that the Network name and password are software encoded into the program, which would mean that if someone had access to the ESP8266, they will have access to your network. This is a **security flaw** when using this version of Micropython. Should you want to protect your network, then you need to use either C++ or assembler to write your networking programs. #### Network Time Once we have connected to the network, we can use the Network Time Protocol (NTP) to keep our time synchronised with the networks. The ESP8266 has its own real time clock, but if we could synchronise it periodically, our clock would be very accurate. Let's setup the internal RTC (Real-time clock) ```python # library import network import time import utime import ntptime from machine import RTC # settings NTP_HOST = "164.78.28.5" # IP address of NTP server at SP NTP_REFRESH = 5 * 60 # every 5 minutes TIMEZONE = 8 * 60 * 60 # +8 GMT DHT_REFRESH = 1 * 60 # every 1 minute # start and initialise the real-time clock rtc = RTC() # function to get time & set it from ntptime def settime(): global rtc ntptime.host = NTP_HOST ns = 0 try: # try to get the time, change it to localtime ns = ntptime.time() + TIMEZONE except: # problem with ntp print("ntp error") pass if ns != 0: now = utime.localtime(ns) now = now[0:3] + (0,) + now[3:6] + (0,) # format it in time struct rtc.datetime(now) print ("ntp.ok") return ``` We call the function settime() to set the time and keep it synchronised with the network time. ### ThingSpeak [ThingSpeak](https://thingspeak.com) is an Open IOT platform which allows you to post data and perform analytical analysis. We will post our IOT temperature and humidity data to a ThingSpeak account periodically and use the site to provide a graphical analysis of our data. You will, first, need to create an account on the site. <section class="info"> <a href="iotclock-assets/thingspeak_output.png" target="_blank" <figure class="infoimg"> <img class="w640" src="iotclock-assets/thingspeak_output.png" alt="ThingSpeak Output" /> <figcaption> ThingSpeak Output of Data1 and Data2 </figcaption> </figure> </a> <div class="infotext"> <p>The IOT clock periodicaly (every 5 minutes) sends Data1 (Temperature) and Data2 (Humidity) values to ThingSpeak.</p> <p>ThingSpeak accepts the values as it matches the API WRITE Data id, and stores them in your account</p> <p>You can then format ThingSpeak to display the data as graphs over time.</p> </div> <div class="infoclr"></div> </section> <!--End of Section.info--> 1. Create an account with ThingSpeak 2. Goto Channels &gt; API Keys to obtain the WRITE API key. With this key you can instruct your IOT device to send data to the site. 3. You can monitor your data from field1 and field2 at ThingSpeak ```python # constants THINGSPEAK_REFRESH = 5*60 # every 5 minutes THINGSPEAK_HOST = "api.thingspeak.com" THINGSPEAK_API = "SE7KCFLCTISFZML6" # put your WRITE key here DATA1 = 'field1' DATA2 = 'field2' # send to the thingspeak server def send_thingspeak(): global temp global humidity data = b"api_key="+ THINGSPEAK_API + "&" +DATA1+"=" + str(temp) + "&"+DATA2+"=" + str(humidity) s = _socket.socket() ai = _socket.getaddrinfo(THINGSPEAK_HOST, 443) addr = ai[0][-1] s.connect(addr) s = ssl.wrap_socket(s) s.write("POST /update HTTP/1.0\r\n") s.write("Host: " + THINGSPEAK_HOST + "\r\n") s.write("Content-Length: " + str(len(data)) + "\r\n\r\n") s.write(data) print(s.read(128)) s.close() return ``` ## IOT Clock Lets put the entire project together ```python def iot(): display_init() # initialise the display do_connect() # connect to the network settime() # set the time from ntp display_room() # get the temp & humidity psd = psn = pst = time.time() # the current time while True: display_time() # display time ns = time.time() if ns - psd >= DHT_REFRESH: # if refresh is up display_room() # display temp & humidity psd = ns if ns - psn >= NTP_REFRESH: # refresh the rtc settime() psn = ns if ns - pst >= THINGSPEAK_REFRESH: # update on internet send_thingspeak() pst = ns ``` The final iotclock program can be found in ([iot.py](iotclock-assets/iot.py)). You can load the program into the WeMOS and try each of the routines to check how they can be used. If you want the iotclock to run independently, you will need to write the following code and save it as `main.py`. Transfer this file to the iot clock using `ampy`. When power/RESET is applied, the main() will be executed and it will call the iot program. ```python @ run iot clock automatically def main(): iot() ``` Code: [iot.py](iotclock-assets/iot.py) ### How to make your clock RUN You can only use your iot clock at home (using it in SP Office involves you violating several INDT regulations). You need to change the following in the [iot.py](a=iotclock-assets/iot.py) code before you start: 1. Download the [iot.py](a=iotclock-assets/iot.py) code and open it in a text editor. 2. Change the SSID to point to your home AP (Access Point) 3. Enter the password for your home AP. 4. Change the IP address of the network time server. If you do not have one, point to your AP, it usually handles this service. Alternatively use the [Singapore NNTP](http://www.pool.ntp.org/zone/sg) 5. Choose an account (call us for details) on ThingSpeak and obtain the API WRITE key. Alternatively, sign-up for an account on ThingSpeak. 6. Change the ThingSpeak API key to your own. 7. Save the file, upload to the ESP8266. ```python # settings SSID = "myHomeAP" # Edit: Your SSID name KEY = "myPassword" # Edit: Your password for the AP NTP_HOST = "164.78.28.5" # Edit: Your NNTP server IP ... # thingspeak settings THINGSPEAK_REFRESH = 2 * 60 # update every 2 minutes THINGSPEAK_HOST = "api.thingspeak.com" THINGSPEAK_API = "SE7KCFLCTISFZML6" # Edit: Place API WRITE key here DATA1 = 'field1' # Fields you use for your data DATA2 = 'field2' ``` Please [**EMAIL** me](mailto:rodney_dorville@sp.edu.sg) if you find any errors, or suggestions to the above, it would help make the information complete and accurate. <!-- End of markdown text -->