Skip to content
computourist edited this page Jun 26, 2016 · 10 revisions

ESP8266 client

The ESP8266-MQTT-client will connect with an MQTT broker over Wifi and controls a digital output (LED, relay):

- toggle output and send status message on local button press
- receive messages from the MQTT broker to control output, change settings and query state
- periodically send status messages

Several nodes can operate within the same network; each node has a unique node ID. On startup the node operates with default values, as set during compilation. Hardware used is a ESP8266 WiFi module that connects directly to the MQTT broker.

Message structure is equal to the RFM69-based gateway/node sytem by the same author. This means both type of gateway/nodes can be used in a single Openhab system. For a decription of the message format look for the explanation pdf in the RFM69 gateway section.

Sonoff

Itead sells a small ESP8266 based control unit that is capable of switching mains current at 10 A. It has a header for programming, so it is easy to change the code and replace it with the MQTT-client code. To program the flash memory, an FTDI-USB board has to be connected like shown below:

ftdi

Make sure power is supplied at 3.3 Volts by the USB-board.

--> DO NOT APPLY MAINS WHEN PROGRAMMING THE UNIT. <--

The programming connector has a square pad indicating the 3.3 Volts connection:

sonoff_socket

(Note that TX on the Sonoff is connected to RX on the FTDI board and vice versa.)

To program, push the button, connect 3.3 Volts, and release the button. You can then flash using Arduino IDE or any other method.

On power-up, the green LED will show the following sequence:

  • it wil light up for a second when the WiFi connection is established.
  • it will go out for one second
  • it wil light up and stay lit indicating an active MQTT link.

The unit I ordered does not have a 433 Mhz function on board, so transistor Q3 is not installed and the red LED is not used. By installing a short wire between R3 and the collector of Q1 the red LED will light up when the relay is activated. The wire connections are shown below:

red LED connection

red LED connection

Clone this wiki locally