ESP Board Setup

From ElectroDragon
Revision as of 00:27, 29 November 2017 by Chao (talk | contribs) (APP Control and Commands)
Jump to navigation Jump to search

Quick Start Quide - AP Point

  • Serial port will output verbose debug information, step by step
  • If you want to reset back to factory mode, press BTN2 but be caurful of the high voltage. Board will reset, restart and show up AP mode again.
User Action Description -
Power up your board
  • Board will provide a wifi AP "ESP-Relay-Board" or similar
  • (Also all leds blink for testing purpose)
Connect to "ESP-Relay-Board" (or similar) it with no password your phone will then ask you to sign in by pop-up message -
Configure wifi with scan, click show up wifi list and click your Wifi SSID - -
Config following information 1. connect to local wifi setup
  • Your wifi SSID
  • Your wifi Password
Config following information 2. MQTT part setup (keep default)
  • Remote MQTT server address (default using ours)
  • Remote MQTT server port (actually not able to be changed)
  • Remote MQTT server user ID (not used, anonymously allowed)
  • Remote MQTT server user password (not used, anonymously allowed)
Config following information 3. Setup your module topic ID
  • this will be used as MQTT module ID, and MQTT topic ID
  • please use a unique complex name, otherwise if conflict with other module ID, it can not connect
  • For example, if you choose module ID "1122", the full module ID for MQTT ID and MQTT topic is "ESP-1122"
Finish configuration Board led blink means MQTT server connected and ready to be used successfully

APP Control and Commands

  • Use any MQTT app (for exampe MyMqtt) to control, configure MQTT app server
  • Only need to provide server address in APP confiugration, default port 1883
  • Subscribe to your own command topic, for example, if you make your board name "1234", then the full topic name will be "ESP-1234" for example
  • Please make sure the ID name is unique and complex, better use numbers instead of words
  • The following is for ESP Relay control board.
Board Type Command Description
ESP Relay Board 1_ON Turn on onboard relay 1
ESP Relay Board 1_OFF Turn off onboard relay 1
ESP Relay Board 2_ON Turn on onboard relay 2
ESP Relay Board 2_OFF Turn off onboard relay 2
  • The following is for ESP LED strip board.
  • To use local WLAN command control, you must first know the led board IP address
Board Type Command Description
ESP LED strip board #00ff00 turn light to green.
ESP LED strip board\rgb\00ff00 turn light to green. is board IP address

Update Log

Optional Setup by ESPeasy + Domoticz

domoticz setup by HTTP

Create "hardware"

  • add "hardware" - > "dummy" - virtual switch

Create "device" switch

Create "device" DHT22 sensor

  • click "Create Virtual Sensors" again -> create temp+hum type sensor device
  • very important to remember to IDX number, this should be later set in espeasy - device - your DHT22 sensor setup
  • Data should appear soon on server page too.


  • Espeasy can easily read the sensor value, support mutiple protocols like domoticz, openhab
  • File:ESPEasy , upload
  • Restart board and connect to AP point esp_0, config to your wifi router, notice the new IP address of board will popup after config, read more about setup espeasy here.

Setup DHT22 sensor

  • Place DHT22 sensor into board, "as how it looks like", just fit the place
  • In device config page, device -> see attached image
  • In device config page, hardware -> set GPIO14 to input
  • Domoticz hardware setup of IDX/VAR for DHT22 normally is 237, switch relay is 100, this must be input, otherwise won't work

Device control via HTTP

Quick Start Quide (Smart-Config, old)

  • Config Steps
Steps Descriptions Screenshot
0. Power up
  • Power up by AC power directly (or USB-TTL CP2102 for debugging)
  • Relay and relay LED will switch on/off twice for debugging purpose.
1. Smartconfig
  • Download IOT espressif apk from google play
  • in app, choose add devices, and enter password of your wifi setup
  • connect esp relay board on power
  • If you only want debug, can just CP2102 USB-TTL board, which provide sufficient power
  • Optionally press BTN2 button to clean in board config
2. finish smartconfig
  • click enter in iot app, wait until device found
3. Config your mqtt server
  • download mymqtt app or mqtt dashboad from google play
  • Use mymqtt for example, Config your mqtt server as follow
User: jtpfneeq
Password	: 4Og5kJ5WYQYT
Port: 14967
4. General commands test
  • Send commands "ON" or "OFF" to Topic "Light1" or "Light2"
  • You will here the relay coil click, and appliance connected with be switched on or off, LED on or off
5. Check mac address for unique control

There are three ways:

  • check the wifi spot, "AI-THINKER-D92069", D92069 is the MAC ID
  • In above IOT espress config, when config done, also can see D92069
  • Subscribe to topic "Light1", mac address will be published to this topic, all the time when power up
6. Switch to Mac IC control mode
  • Send commands, for example mac id is D92069, send "D92069ON" to mqtt topic Light1
  • Board will restart and switch to mac control mode
  • In new mode, use mac ID D92069 as topic
  • commands "1ON" "1OFF" "2ON" "2OFF" to control each relay
7. use station mode control
  • Connect to wifi spot, for example, "AI-THINKER_D92069"
  • download and use widget "socket control widget" from google play
  • create a new widget, and see the screenshot on right
  • a1, b1 are switch relay on, a0, b0 are switch relay off
  • board station server IP is, listen on port 80

Other Configuration

LED status:

LED Status
0.2 seconds very fast blink board is getting IP address from router, no IP address yet
5.0 seconds very slow blink connected to wifi, connect to mqtt server, wait for commands
0.5 seconds blink wait for smartconfig

In board config files for mqtt:

  • mqtt_server_1.lua, mqtt_server_2.lua - including server configuration details
  • wifi_config.txt - your wifi name and password
  • check_mode.txt - check if your board use mac control or not

Demo code and update Log

R3 version

  • Download R3 firmware here File:Relay board
  • mqtt sever info saved in mqtt_config.txt file
  • After smartconfig, ssid and password saved in config.txt, when power up will always use this setup for wifi
  • support to switch to unique ID (chipID) mode control by sending commands "chipID+ON" (162243ON) to ID topics
  • File:Esp relay board firmware, new firmware implemented on board from 4th Feburary 2017.

R4 version

  1. Including two servers config, in ID control mode, send commands "server1" or "server2" to swtich, or edit file "check_server.txt" change 1 for server1, or 2 for server2
  2. server 1 "mc" is mqttcloud free server, server 2 "sg" is Singarpore server, optimized for Asia area too.

Demo code of version R1

Module: LEDBlink init.lua mqtt2.lua
local M = {}
    gpio_16 = 0
    gpio.mode(gpio_16, gpio.OUTPUT)
    gpio_blink = 0
    tmr.alarm(2, 500, 1, function()
        if gpio_blink == 0 then
            gpio_blink = 1
            gpio_blink = 0

return M
LED = require "LEDblink"

print("set up wifi mode")
-- if you want to test smartconfig, disconnect the board first


tmr.alarm(1, 6000, 1, function() 
    if wifi.sta.getip()== nil then
        print("Waiting for smartconfig, IP unavailable..")
            function(ssid, password)
            print(string.format("Success. SSID: %s ; PASSWORD: %s", ssid, password))
        print("Config done, IP is "..wifi.sta.getip())
print("Running file mqtt")

gpio12 = 6
gpio.mode(gpio12, gpio.OUTPUT)
gpio.write(gpio12, gpio.LOW)

gpio13 = 7
gpio.mode(gpio13, gpio.OUTPUT)
gpio.write(gpio13, gpio.LOW)

-- init mqtt client with keepalive timer 120sec
m = mqtt.Client("nodemcu", 120, "swqzxzhr", "9JMcxVeUNz3t")

-- setup Last Will and Testament (optional)
-- Broker will publish a message with qos = 0, retain = 0, data = "offline" 
-- to topic "/lwt" if client don't send keepalive packet
m:lwt("/lwt", "offline", 0, 0)

m:on("connect", function(client) print ("connected") end)
m:on("offline", function(client) print ("offline") end)

-- on publish message receive event
m:on("message", function(conn, topic, data)
  print(topic .. ":" )
  if topic == "Light1" then
    if data == "ON" then
        print("received message: ON@light1")
        gpio.write(gpio12, gpio.HIGH)

        print("receive OFF liked data on light1")
    if topic == "Light2" then
        if data == "ON" then
            print("received message: ON@light2")
            gpio.write(gpio13, gpio.HIGH)

            print("receive OFF liked data on light2")

m:connect("", 19311, 0, function(conn)

    m:subscribe({["Light1"]=0, ["Light2"]=0}, function(conn) 
        print("subscribe Light 1 and 2 success")



Websocket debugging:

CloudMQTT Websocket Console.png
  • Websocket debugging, login to cloudmqtt, please use your own server config (lua file mqtt-config.lua), see the screenshot on right
  • Commands can also send directly via websocket interface

Serial USB interface debugging:

Esp relay board demo.JPG
  • Debugging info can be read when you use it.
NodeMCU custom build by
	branch: master
	commit: c8037568571edb5c568c2f8231e4f8ce0683b883
	SSL: false
	modules: dht,enduser_setup,file,gpio,mqtt,net,node,tmr,uart,wifi
 build 	built on: 2016-03-29 10:06
 powered by Lua 5.1.4 on SDK 1.4.0
set up wifi mode
> Waiting for smartconfig, IP unavailable..
Waiting for smartconfig, IP unavailable..
Waiting for smartconfig, IP unavailable..
Waiting for smartconfig, IP unavailable..
Success. SSID: hcwork ; PASSWORD: electrodragon
Waiting for smartconfig, IP unavailable..
Waiting for smartconfig, IP unavailable..
Config done, IP is
Running file mqtt
receive OFF liked data on light2
receive OFF liked data on light1
received message: ON@light1
receive OFF liked data on light1
received message: ON@light2

Flash Firmware or Debugging


  • No need to connect AC mains power, only use power from USB-TTL
  • You will need USB-TTL tool e.g. CP2102, FT232RL, CH340 to upload firmware
  • If you want to customize it, please contact via
  • Firmware can be found on this page, including arduino or nodemcu firmware.

Enter into flashing mode

  • Hold down BTN2 button
  • Connect TX RX VCC 5V and GND wires of USB-TTL to board pins
  • board powered up by USB-TTL(esp8266 module blue led blink, on board red led constantly on), now can release BTN2
  • Get esp download tool from, flash .bin firmware file to board 0x00000, more instruction please see the page.

For nodemcu to upload sketch (old)

  • Use script interpreter LUA as embedded system programming
  • open Nodemcu flasher/esp download tool/ to upload this firmware, more details see here, see some guidelines here
  • Restart module and upload lua scripts: LEDBlink.lua, init.lua, mqtt2.lua


Demo video

Demo code