WiFi Sensors

Introduction

This page describes my experiments with WiFi Sensors based on ESP8266 modules.

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 sleep between measuring. This allows live with two AA bateries more than one month. In my experience, that modules works with voltage about 2.8 V correctly.

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

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 Fishino UNOexternal link 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.

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

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