Quantcast
Channel: OpenEnergyMonitor aggregator
Viewing all articles
Browse latest Browse all 328

mharizanov: WiFi IoT 3 channel relay board with MQTT and HTTP API using ESP8266

$
0
0

The ESP8266 DHT22/LED blinker project grew into a M2M relay board project with the following features in mind:

  • Relatively small (10x5cm) PCB
  • Powered via on-board power supply or externally via a micro-USB plug
  • Has three 2A Sharp Solid State Relays (later version has 8A SSR)
  • DHT22 humidity/temperature and/or DS18b20 temperature sensor support
  • WiFi (of course) in Static/Dynamic IP mode
  • Native MQTT support (both publish and subscribe, controlling the relays and reading sensors over MQTT)
  • HTTP/JSON API for setting/getting relay board properties
  • Fancy jQuery UI for remote control via smartphone/tablet/laptop from anywhere in the world
  • Web-configurable WiFi/MQTT/Sensor settings
  • NTP support
  • In the pipeline
    • Basic HTTP authentication to protect the web interface
    • Dynamic DNS support so that the module’s IP is always known
    • I2C status display support
    • Custom made plastic box/cover
    • Scheduling functionality

I’ve created a prototype PCB to test the concept, used a quick turnaround PCB service that was neither quick nor of good quality. The initial idea was something like this:

v1 Schematicv1 Board Layoutv1 Board With one SSR populated and a light bulb attached to test

The v1 board had some design flaws, but overall works well. Here is a video, the software was at early stage then:

I’ve since then added native MQTT support based on Martin Hubáček’s mbed MQTT for LwIP. That implementation is quite basic and lacks some features so I plan to replace it with Tuan PM’s fresh MQTT for ESP8266 code in the future.  The board currently publishes the readings of the DS18B20 temperature sensor to “ESP8266/in/ds18b20/temperature” topic and subscribes itself to “ESP8266/out/gpio/#” to watch for on and off commands for the three SSRs on GPIOs 12-14. The publish and subscribe topics are hardcoded now, but I am working on a configuration web interface where all these settings would be exposed.

MQTT makes it quite easy to implement external business logic, I use Node-Red for the purpose and have implemented complex rules that trigger my boiler heater element and a heat exchanger contour TRV.

Visualising MQTT with Android's MyMQTTThe jQuery control web UIThe Wi-Fi configuration page; Fixed or dynamic IP address can be assigned

I also added a jQuery powered control UI with background refresh using the board’s HTTP/JSON API; it updates automatically if the state changes from another session or MQTT control packet.

The configuration UI is intentionally in the old-style plain HTML so that it can be rendered even when the board is in AP configuration mode and the connected device can’t pull the jQuery libraries online.

NTP support is also there and I plan to use that for some basic scheduling functionality; Given the HTTP API and MQTT support, that seems less and less practical, but I still do plan to add it at some point in time.

Alternatively, one could use the nodeMCU  ESP8266 Lua firmware instead and make all sorts of fancy use of the relay board with custom scripting some thermostat functions for example.

I’ve used the v1 board to control a contactor that switches on and off the heater element in my boiler and controls a Non-Mechanical Thermo Electric Actuator that opens heat exchanger contour in case my fireplace with water jacket produces hot water that exceeds the boiler’s current temperature and thus aids or completely replaces the electric heater element:

Enclosed in a plastic box next to the boiler's breaker boxCovers removed; Box has a status led and a on/off switch to kill the power. The Contactor in the breaker box has a manual switch as per wifey's requestThe SSR board, DS18b20 temperature sensor wired to a probe hole in the boiler.Fuse and the Contactor that is controlled by the relay boardCALEFFI non mechanical TRVthe TRV at another angle, this opens/closes heat exchanger contour

The HTTP API exposes the status of the relays and sensors as JSON string

http://IP/ds18b20.cgi returns { “temperature”: ” 55.0″}

http://IP/dht22.cgi returns { “temperature”: ” 24.4″, “humidity”: “44.5” }

http://IP/gpio.cgi returns the state of the relays { “gpio12″: “0”,”gpio13″: “0”,”gpio14″: “0”}

Relays are switched on/off using a query string: http://IP/gpio.cgi?gpio12=1&gpio13=0&gpio14=0

Since the module can provide JSON status string, we can use freeboard.io to query and visualise the data directly with no proxying, I have only set a router rule to port forward the http traffic of an externally visible port to port 80 of the Relay board:

Freeboard.IO Data Source set upBoiler Temperature filterDashboard to show boiler's temperature over time and the heater element state

So the relay now talks to freeboard.io, a 3 minute effort to illustrate the power of the Internet of Things.

I’ve decided to swap the 2A relays I used in v1 of the board with 8A ones and also made some fixes to the board design, here are the plans for v2:

v2 Schematicv2 Board Layout

I will be ordering few test boards of the v2 and blogging my progress once they are with me.

Switching larger loads is quite easy by adding a AC-AC SSR on top, I suggest Fotek’s line like this one. Connecting SSRs in parallel to increase the load current is *NOT* an option, just a note to those curious to try (myself included).

Once I get all this working as I imagine it, I will make the board design files and source code available on Github, and will offer a limited number of pre-built boards in my shop. You want one, trust me.. ;-) Follow me on Twitter to get the news first when these are available.

(478)


Viewing all articles
Browse latest Browse all 328

Trending Articles