WiFi Sensors, Relays, etc ...

Introduction

This page describes my experiments with WiFi Sensors based on ESP8266 modules and some other home automation projects.

ESP8266 and sensors

I use ESP-07 and ESP-12E modules and simple universal board. For measuring I use following sensor types:

ESP8266 has pins Reset and GPIO16 connected and deep sleep functionality is used. Sensors measure values every 5 minutes and sleeps between measuring.

Powering

Current that draws ESP8266 depends on mode (STA vs. AP) and from state. Critical is boot, firmware flash and WiFi operations. See more infoexternal link about it. With insuficient power supply you may have problems: unexpected reboots, error messages to serial line after failed boot, etc. Also account reserve for powering your sensors.

I tried following powering methods:

Source code

Here is source code, developed using Arduino IDE. It's common for my four sensors and concrete one must be enabled by uncomenting some lines at top of code.

ESP8266 programming

For programming, I use CP2104 USB UART and Level shifter for 5 V -> 3.3V conversion.

IOT database

I store measured data to Oracle database. Yes, this is overkill, but I have this database installed for work development and I am too lazy to install something else. Database model is very simple and self explained, I hope:

Database model

Scripts for initial populate of DB tables are located in project IotDbScripts. Here is crucial parts: create_tasbles.sql | populate.sql

IotDatabase

IotDatabase is ORM layer between Oracle tables and Java. It's use EclipseLinkexternal link as ORM engine. For each database table, there is mapping class - Person, SensorType, Sensor, etc. Also service layer for obvious tasks is created.

IotDatabase

IotService

IotService is Java EE application based on:

Yes, it's maybe another overkill, but I want to learn some Java EE technologies.

IOT Service

IotService is deployed on Apache Tomcat server, and this service has following purposes:

InsertSensorValueService

This JAX-RS Service is responsible for storing data from sensors, and for sending alerts. Everytime sensor measure value, WiFi connection is established and following HTTP GET request with sensor code and measured value is sent to IotService:

http://server:8080/IotService/rest/insert-value/LV_TEMP_02/20.07

Request contains sensor code and measured value.

IOT Insert value Service

When measured value is under/over defined alert, email message is sent, like this:

Alert email

GetChartDataController

This MVC Controller generates web page with chart. It loads values and create desired averages. Controller stores JSON data for chart to MVC Model. In next phase, processing is redirect to JSP page (MVC View). Google chartsexternal link API is used for chart rendering.

Chart

Other Services

I have developed some other JAX-RS Services for getting data in JSON and other things.

Base station

For displaying measured values without PC or tablet I made simple station with Arduino LEONARDO ETH and 20*4 LCD display. It's housed in old box with power supply. There are five front panel buttons, that I use for choosing values to be displayed. Here is source code, developed using Arduino IDE.

Relays

Base station contains two power relays to control 230V outlets. Required state of relays is stored to database tables and base station check this using JAX-RS service and set desired state. For driving relays there is expand board with PCF8574, the I²C 8-bit expander and ULN2803A.

Control relay states

Basen pump controller

One of two relays I use for switching basen pump ON/OFF to give maximum efficiency of solar panels. The system consists of the following parts:

Basen with solar panels and IOT controlled pump

When pump control works correctly, temperature of solar panel has typical sawtooth shape, water in basen temperature rises gently.

Basen with solar panels temperatures

Measuring indoor Air quality

The CCS811external link Air Quality Breakout is a digital gas sensor with I2C bus. I tried it with ESP8266 but it not works for me. So I connected it to Fishino UNOexternal link and made simple measuring station. There is also 20*4 LCD display and Si7021 for measuring temperature.

Station displays sensors values on LCD and sends them to IOT service. Here is source code, developed using Arduino IDE.

Conclusion

At this time, I have five ESP modules with various sensors in gardenhouse, greenhouse and outdoor. Server side service is under daily development, but if somebody is interested about source code, let me mail, it's nothing secret.

Hokaido
Valid XHTML 1.0!     Creative Commons License - non commercial