This repository was archived by the owner on Dec 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Program flow
Sridhar edited this page Mar 1, 2016
·
4 revisions

As shown in the above image the code has been burnt to a NodeMCU V0.9 ESP8266 board. For better code organization I’ve split the code into 4 source files.
- Constants.h: Within constants file I’ve various sections.
- Network related: In this section I define host to which I’ll be sending the data, the SSID for the network to which we’ll connect and its password.
- Section inputs defines the pins we’ll use for reading analog and digital inputs. Analog input is no brainer: ESP8266, at the time this document was prepared, has only one analog input A0. I’ve selected GPIO 4 as the digital input.
- Post request: When we send a post request to REST server we need a header that identifies the request and the type of content we’ll be sending. These constants will be used to build the header.
- Loop Control: In this section I’m defining the frequency at which we’ll read the values from the sensor and how often we’ll be sending the data to Thingspeak server.
- We have two more constants, disconnect check & led cycle timer. ESP8266 is connected to rest of the world using home WiFi. In the event WiFi connection breaks we have a heart beat monitor to check if we need to reconnect to home network. Let Cycle timer is to set the frequency of the led fade-in, fade-out. I’ve a LED that keeps fading-in/out to let me know that my program that monitors my basement is alive and doing its job.
- Before we are done with our constants we have to define one more output: the pin to which we are connecting our blinking LED.
2 . Variables.h
Now let’s go over the global variables that is used for this application.
- Under section “Timers” we have variables that is used to store the next timer tick when we’ll read values from sensor, send data to server, when to check on internet connection and manage the fading of LED.
- Section “Dynamic values” is the place where the data read from sensor is registered.
- Next section is used to register if Wi-Fi is disconnected. Each time after successful transmission of data to the server we set this value to zero. In the event if there is a transmission error we increment disconnect count. The Wi-Fi connection routine uses this count to reestablish Wi-Fi connection if necessary.
- JSON object section is to store JSON values to be transmitted. It is a scratch pad buffer to convert sensor values to JSON objects that will be transmitted.