Zonnestroompanelen in Nederland

duurzaamheid achter de meter

(47) Sniffer box 2: updated portable weather station with ESP8266-wifi

by Floris Wouterlood – february 7, 2021

Summary
An improved version is described of the Sniffer box, created in a previous project*: a small portable Internet Of Things (IOT) device consisting of a sensor-equipped Wemos D1 mini ESP8266 microcontroller that sends data to an account at Thingspeak.com. The server at Thingspeak logs the data and displays them in an attractive way via a browser window on a smart phone, tablet or computer. The improved device contains Arduino-compatible components and has a Nokia 5510 LCD with switchable background illumination. Programming is done via the Arduino IDE. Sniffer box 2 can be deployed at any spot where usb power and wifi are available.

Introduction
In a previous project* I constructed with several Arduino components a compact portable IOT weather station: a Sniffer box. Its engine, a Wemos D1 mini ESP8266 microcontroller, manages several sensors that collect useful data. At intervals the microprocessor transmits the data via wifi and a router to a Thingspeak server. Data display is via a built-in OLED or can be remotely accessed, for instance with a smart phone or similar device. This Sniffer box had been in 24/7 continuous operation for a year and a half to monitor and log temperature and relative humidity in a holiday chalet. It needed maintenance because the two humidity sensors that I applied (DHT11) started to malfunction. Further, the on board OLED began to show burned-in pixels after the long period of permanent action. The microcontroller did not show any sign of fatigue. A successor was designed for the Sniffer box, say Sniffer box 2, re-using the casing and the microcontroller, and equipped with new, better and replaceable sensors and a new, hopefully better display.

Design of Sniffer box 2

figure 1. Position of the Wemos D1 mini microcontroller board and various other components in Sniffer Box 2. The inset shows the Si7021 mini breakout board.

Design
Like its predecessor, Sniffer box 2 is built around a Wemos D1 mini (figure 1) which has an ESP8266 chip that is mounted on a board with an incredibly small footprint : 35x28mm. The D1 mini is functionally fully compatible with the NodeMCU ESP8266 1.0 (ESP-12E model) and so is its pin layout, however because of the D1 mini’s small footprint the number of pins is limited. The D1 mini is programmable with the Arduino IDE as a member of the ESP8266 class of devices (Arduino IDE: Tools, Boards, Boards Manager).

figure 2. Wiring diagram of the electronic components in Sniffer Box 2.

I used for Sniffer Box 2 the 80 x 120 mm plastic electric junction box with breakaway ports that I salvaged from the first Sniffer Box. The three sensors in the original Sniffer Box (a Dallas DS18B20 temperature sensor and two DHT11 relative humidity sensors) were replaced by a single Si7021 combined temperature-relative humidity sensor mini breakout board. This freed space to position a male 8-pin pin header to support a ribbon cable connection to the new display mounted in the lid of the box. Among candidate displays the Nokia 5510 LCD was selected because this is a modest, robust, graphical display with a proven long life expectancy and with sufficient pixels to display the recorded data.

The wiring diagram in its final version is shown in figure 2. While in operating mode a display is not necessary when prolonged logging is done in a place like a remote holiday chalet, it is a very handy assistant during software programming and apart from that it is useful to have visual control over the operation of the device. One of the conditions in the design is that all major components: Wemos D1 mini and Si7021 should be ‘pluggable’, that is, placed on pin headers soldered onto the base soldering board (figure 3). This makes it very easy at maintenance time to remove the microcontroller and the sensor for testing or replacement.

figure 3. Schematic layout of the print with indication and meaning of all pins. The final platform soldering board is made up of two 30×70 mm boards in ‘L’ configuration. The first board supports the Wemos D1 mini via two pin headers and the second board accommodates the sensor and the connectors to the display. Both boards are firmly attached to each other

Electronics and supplies
1x Wemos-type D1 mini ESP87266 microcontroller board, 1x Si7021 temperature/relative humidity sensor breakout board, 1x Nokia 5510 84*48 pixel monochrome LCD, 2x 30×70 mm soldering boards, 1x led, 2x 8-pin female pin header, 1x 4-pin female pin header, 2x 5-pin male pin header, 2x 2-pin male pin header, 2x 4.7 kΩ resistor, 1x 220 Ω resistor, wire, 1x 10-lead female connector ribbon cable 1x M3 nylon place holder with nut, thread length 6mm, 1x PVC container 80 x 120 mm (electric junction box with breakaway ports and a snap-on lid). Power supply is via a USB cord and an external 5V DC USB power supply.

Construction
Inside the container box are two soldering boards: one that supports the D1 microcontroller board and the other that accommodates the sensors. These boards are placed in a L-configuration, with slight overlap (figures 3 and 4). Main consideration was that the sensor must face (open) breakout ports for unhindered functionality. The best place to position the sensor is at the long end of the container box and in front of a breakaway port. Because heat might build up inside the box, however modest, threatening to influence the sensors, it was made sure to place the microcontroller board as far away from the sensor as possible. The two boards were firmly attached to each other by ‘stitching’ with wire and soldering (narrowly visible in figure 4). Once the soldering board platform configuration was established, two rows of pin headers were soldered onto this platform and the board with the D1 mini could be put in place (figure 4).

figure 4. Container and platform soldering board with the sensor and microcontroller in their final position. The two male pin headers (connectors 1 and 2) are still unoccupied, ready to be connected with connectors 1 and 2 coming from the display .

Next the sensor pin header was positioned and soldered onto the platform. The sensor itself (a Si7021) had arrived from the manufacturer mounted on a mini breakout board. This breakout communicates via the I2C protocol with the microcontroller. Hence the pin header has four pins: SDA, SCL, VCC and GND. The Si7021 has been tested before in Arduino** and ESP8266*** settings

Assembly

figure 5. Sniffer box 2 in action. A control led with its accompanying 220 Ω resistor was added later in the design to have a led signaling a major event (e.g. wifi transmission). The four pins of the OLED display stick into a pin header soldered onto board B of the platform. The display pin header makes it possible to temporarily remove the display when the Sniffer box is going to be used for a long period unattended.

In the final assembly the platform was fastened to the bottom of the container with the nylon place holder and a small nylon nut (figure 4). The display was fastened onto the lid of the container (figures 4, 5). Note that a display is only necessary when the Sniffer box is being programmed. In field operation all communication is via wifi anyway. The display was provided with a suitable 10-wire flat cable found in a box with leftover computer parts. The male and female connectors for the display were matched and the lid was snapped onto the container. USB power was supplied to the Wemos D1 mini and Sniffer box 2 was operational (figure 5).

Sketch
The purpose of Sniffer box 2, as its predecessor, is to collect temperature and relative humidity data and to transfer these to a server on the Internet. The Internet site then presents the data in an attractive way and stores them for future download. The sketch created for the original Sniffer Box* had to be changed to control the Si7021 sensor and the Nokia display. In addition an averager module was introduced as a filter that calculates a rolling average of temperature instead of raw instantaneous data. Thus: averaged temperature and momentous relative humidity were transmitted at intervals of 10 minutes to the server at Thingspeak, a free MATLAB service available at https://thingspeak.com that does the logging and data presentation. The main components of the sketch are discussed in the paper on the original Sniffer box*.

Short run through the sketch
The upgraded sketch: Snifferbox-IOT_2.ino starts with a series of comment lines explaining the purpose of the sketch, documenting pins used for specific sensors, etcetera. Next follow the #includes, libraries, object constructors, variables and connection/login variables.
To dampen temperature shocks the temperature readings are run through a function called average_readings (). This filter consists of a stack of a defined (currently 8) temperature readings. Each iteration of the loop () a fresh temperature reading is added to the averager stack while the oldest reading is removed. The average of the stack is sent to the internet through the function send_the_stuff (). In order to prepare the average_readings () function some extra variables need to be introduced at the beginning of the sketch:

// temperature is stored in a float variable named ‘temperature’

#define windowSize 8        // number of indexed readings to average – say stack height
int index_01 = 0;
float value = 0;
float sum = 0;
float readings[windowSize];
float averaged_temperature;

The instructions in the function average_readings () are the following

void average_readings (){

sum = sum – readings[index_01];                         // remove the oldest entry from the sum
value = (temperature);                                          // read the next sensor value
readings[index_01] = value;                                  // add the newest reading to the window
sum = sum + value;                                              // add the newest reading to the sum
index_01 = (index_01+1) % windowSize;             // increment the index, and wrap to 0

                                                                              // if it exceeds the
                                                                              // averaged_temperature = sum / windowSize;
}

Because average_readings () needs to run continuously in between two wifi transmission periods the transmission timer is executed as a timer without delay based on counting millis().

Results
With the above sketch and with the proper channel settings in the Thingspeak account I got nice temperature and humidity logging with Sniffer box 2. Figure 8 shows how data can be displayed in my Sniffer box channel.
Because of the introduction of the averaging filter Sniffer box 2 needs after a cold start some time (that is: a number of iterations equal to the size of the averager stack) before the correct (average) temperature is shown on Serial Monitor. For the Nokia display I opted for displaying the fresh temperature measurement at each iteration of void loop ().

figure 6. Presentation of data at https://thingspeak.com. Thingspeak offers a range of presentation widgets to the user such as graphs and ‘gauge’ widgets presenting the most recent values of series of readings.

As its predecessor, Sniffer box 2 needs 5V DC power from an external source, e.g. a smartphone charge adapter or a 5V power bank. If WiFi is not available there is no transmission to the server and Sniffer box 2 then acts as a local temperature-humidity sensor. Of course one has to check beforehand in the location to be monitored whether the two conditions, 5V DC and WiFi, are fulfilled.

Download
The sketch, snifferbox2-IOT.ino, can be downloaded here (zip file). After opening the sketch in your Arduino IDE, be sure to fill in the SSID and pass key for the local WiFi router, and to fill in the correct Thingspeak API key (available in the channel configuration you created at www.thingspeak.com)

References

*Sniffer box: portable weather station with ESP8266-wifi
Thesolaruniverse, July 13, 2019

**Bare Si7021 temperature/relative humidity sensor
Thesolaruniverse, January 24, 2021

***Breadboard prototype for a tiny weather station – Si7021 sensor, ESP8266 Wemos D1 mini microcontroller board, Nokia 5510 84*48 LCD. Thesolaruniverse, January 24, 2021