This is my English translation of the article originally published in Geek Times.
A couple of years ago I purchased esp8266, a cheap Wi-Fi chip with full TCP/IP stack and micro controller capability manufactured by Espressif. My idea was to build something useful for my home using this controller. Such features as Wi-Fi connectivity, small size, enough inputs / outputs and ease of programming make esp8266 a perfect controller for enabling home automation. I eventually decided to build a home weather station.
Basic system requirements:
- Remote view of data being analyzed
- Remote control
- Display for real-time data view
- Ease of connectivity and USB charging
- Data transmission to home server for collection of insights, data visualization and more
- Scalability of connected sensors
- Simultaneous use of many weather sensors
My first step was to find existing systems I could use for a prototype. As I explored available systems I understood none of them would meet my requirements either because of the closed code or because they charge extra fees for letting you get advantage of all features you need. Therefore, I chose to invent my own bicycle. To take my project from the ground up, I had to deploy software and hardware first. I bought the following components on eBay:
- NodeMCU board
- LCD TFT Display 320х240 based on ILI9340C
- DHT22 sensor
- BMP180 sensor
- Prototyping boards (5х7 см)
- Micro USB chip
For software development I chose a simple PHP + MySQL stack based on Raspberry PI and deployed to home server. Its advantage over Cloud services is system stability in case of black-out or disconnection. Although I had to program back-end for data storage and processing, I was excited to do so! Arduino IDE fitted with an esp8266 module was chosen as a programming environment, check out details here.
My plan A was to program everything in Lua (nodemcu), but I had to refuse from it because I'd run out of memory each time I uploaded sketches. For data exchange between Raspberry and my weather station I chose JSON.
I used standard methods of sensor connection to module and found relevant libraries here:
- DHT22 — learn.adafruit.com/dht
- BMP180 — github.com/iot-playground/Arduino/tree/master/external_libraries/SFE_BMP180
- TFT LCD — github.com/gnulabis/UTFT-ESP8266
This library was helpful, too.
Here're additional sensors you can connect and configure for data collection and analysis:
- Lighting monitoring module — BH1750 — github.com/kmaximv/BH1750
- Real-time module — RTC DS1307 — learn.adafruit.com/ds1307-real-time-clock-breakout-board-kit/overview
- Temperature and humidity modules — SHT21 — github.com/enjoyneering/HTU21D
Right now I'm waiting to receive MHT-Z19 CO2 sensor to monitor CO2 level in the air (indoor and outdoor). Once I've got it, I'm going to extend weather parameters I'm tracking at home.
After several iterations of code bug fixing and prototyping I was ready to assemble my home weather station.
At first, I made a display opening in a plastic box:
Then I embedded the display inside along with a hardware board, module and sensors. Reset button was deployed, too.
I made holes in the front plates of the box for sensors ventilation and power connectors.
I deployed a remote control in the module firmware using a web server. It allowed me to set up and configure the device with regards to:
- Wi-Fi network to connect to
- Sensors to be used
- Real-time module setup
- Data view from connected servers
- Sensors to be reloaded, etc
I used responsive design to control my weather station remotely from a smartphone. Built-in pages don't have any external dependencies, all styles and scrips are being stored in modules memory.
I also created a basic website to view a list of connected modules, generated data and graphs and deployed it to Raspberry.
What is yet to be deployed?
- NTP time sync
- In-module data aggregation in case of disconnection
- Authentication on data viewer server
- Sensors connection to certain users
- Data visualization
- Outdoor sensor
- Relay control
- Ability to generate data from door / window open sensors
- Making changes to generated data for analysis of in-box sensors.
Feel free to view the project code on GitHub.
And have you experimented with DIY home automation? Please share your experience as a comment below or send us a tweet to @Intersog!