Difference between revisions of "ESP Board Setup"

From ElectroDragon
Jump to navigation Jump to search
 
(38 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
 +
* Programming firmware please see on this page [[ESP8266 Program]]
 +
* MQTT Debugging please see [[MQTT]]
  
 
== Quick Start Quide - AP Point ==
 
== Quick Start Quide - AP Point ==
Line 6: Line 9:
 
{| class="wikitable sortable"
 
{| class="wikitable sortable"
 
|-
 
|-
! User Action !! Description !!-
+
! Steps !! User Action !! Description !!-
 
|-
 
|-
| Power up your board ||  
+
| Config Network || Power up your board ||  
 
* Board will provide a wifi AP "ESP-Relay-Board" or similar
 
* Board will provide a wifi AP "ESP-Relay-Board" or similar
 
* (Also all leds blink for testing purpose)  
 
* (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 || -
+
| Config Network || 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 Network || Configure wifi with scan, click show up wifi list and click your Wifi SSID || - || -
 
|-
 
|-
| Config following information 1. connect to local wifi setup
+
| Config Network || Connect to SSID
 
||
 
||
* Your wifi SSID
+
* Enter Your wifi router password
* Your wifi Password
 
 
||  
 
||  
 
|-
 
|-
| Config following information 2. MQTT part setup (keep default)
+
| Config MQTT || Check MQTT Address
 
||  
 
||  
* Remote MQTT server address (default using ours)
+
* Keep default remote MQTT server address (default iot.electrodragon.com)
* Remote MQTT server port (actually not able to be changed)
+
* Optional - Remote MQTT server port (no need change, default 1883)
* Remote MQTT server user ID (not used, anonymously allowed)
+
* Optional - Remote MQTT server user ID (not used, keep empty)
* Remote MQTT server user password (not used, anonymously allowed)
+
* Optional - Remote MQTT server user password (not used, keep empty)
 
||  
 
||  
 
|-
 
|-
| Config following information 3. Setup your module topic ID ||  
+
| Config MQTT || Setup your own module topic ID ||  
* this will be used as MQTT module ID, and MQTT topic ID
+
* MQTT Topic ID, for example we use a complex ID: 74dyt6, but final ID is ESP_74dyt6 (not ESP-74dyt6)
* please use a unique complex name, otherwise if conflict with other module ID, it can not connect
+
* '''please use a unique complex name''', otherwise if conflict with other users' topic 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 ||  
+
| Config MQTT || Connected Successfully || Board led blink slowly
 +
|-
 +
| Control via MQTT || Send commands to control ||
 +
* 1_ON or 1_OFF to MQTT example topic ID ESP_74dyt6 will turn on or off relay 1
 +
* same for relay 2
 +
||  
 +
 
 
|}
 
|}
  
== APP Control and Commands ==
+
== MQTT APP Control ==
* Use any MQTT app (for exampe MyMqtt) to control, configure MQTT app server
+
* Use any MQTT app (for exampe MyMQTT) to control here for example
* Only need to provide server address '''139.59.102.70''' in APP confiugration, '''default port 1883'''
+
Setup for MyMQTT or similar
 +
* Set only - Server address '''iot.electrodragon.com (IP address 167.88.114.101)
 +
* Keep default port 1883'''
  
* Subscribe to your own command topic, for example, if you make your board name "ED", then the full topic name will be '''"ESP-ED"''' for example (please make sure the ID name is unique and complex)
+
Subscribe to your own command topic
 +
* For example, if you use board MQTT topic "74dyt6 ", then the full topic name will be '''ESP_74dyt6'''  
 +
* Please make sure the ID name is unique and complex, better use numbers instead of words
 +
 
 +
== Board Setup ==
 +
=== General Commands ===
 
* The following is for ESP Relay control board.
 
* The following is for ESP Relay control board.
 
{| class="wikitable sortable"
 
{| class="wikitable sortable"
Line 58: Line 72:
 
| ESP Relay Board || 2_OFF || Turn off onboard relay 2
 
| ESP Relay Board || 2_OFF || Turn off onboard relay 2
 
|}
 
|}
 +
 
* The following is for ESP LED strip board.
 
* The following is for ESP LED strip board.
 
* To use local WLAN command control, you must first know the led board IP address
 
* To use local WLAN command control, you must first know the led board IP address
Line 64: Line 79:
 
! Board Type !! Command  !! Description
 
! Board Type !! Command  !! Description
 
|-
 
|-
| ESP LED strip board || #00ff00 || turn light to green.
+
| ESP LED strip board || #00ff00 || turn light to green. ff for green value 255
 
|-
 
|-
 
| ESP LED strip board || 192.168.0.111\rgb\00ff00 || turn light to green. 192.168.0.111 is board IP address
 
| ESP LED strip board || 192.168.0.111\rgb\00ff00 || turn light to green. 192.168.0.111 is board IP address
 
|}
 
|}
  
== Optional Setup by ESPeasy + Domoticz ==
+
=== LED status ===
=== domoticz setup by HTTP ===
+
{| class="wikitable sortable"
* Install https://domoticz.com/downloads/ normally in windows
+
|-
* after installtion, open webpage to setup
+
! LED !! Status
Create "hardware"
+
|-
* add "hardware" - > "dummy" - virtual switch
+
| 0.2 seconds very fast blink || board is getting IP address from router, no IP address yet
Create "device" switch
+
|-
* after created hardware, creat "devices" -> you can click "Create Virtual Sensors"
+
| 5.0 seconds very slow blink || connected to wifi, connect to mqtt server, wait for commands
* Setup -> type switch, name any
+
|-
* back to menu switches, edit this switch, ON action set to http command -> http://192.168.1.109/control?cmd=gpio,13,1
+
| 0.5 seconds blink || wait for smartconfig
* OFF action same to http://192.168.1.109/control?cmd=gpio,13,0
+
|}
* Both relay can be setup, in switches manu, click the bulb to checkout if can work or not, or use domoticz app
+
 
Create "device" DHT22 sensor
+
== Update Log ==
* click "Create Virtual Sensors" again -> create temp+hum type sensor device
+
* [https://github.com/Edragon/esp_firmware/tree/master/ESP%20Relay%20Board/arduino For latest firmware, and update log please see this page.]
* 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 ===
+
=== Demo code and update Log ===
* Espeasy can easily read the sensor value, support mutiple protocols like domoticz, openhab
+
 
* [[File:ESPEasy_R120.zip|Use eapeasy R120 version file "ESPEasy_R120_1024"]] , upload
+
R3 version
* 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 [https://www.letscontrolit.com/wiki/index.php/EasySetup here].
+
* Download R3 firmware here [[File:Relay_board_20161118.zip]]
Setup DHT22 sensor
+
* mqtt sever info saved in mqtt_config.txt file
* Place DHT22 sensor into board, "as how it looks like", just fit the place
+
* After smartconfig, ssid and password saved in config.txt, when power up will always use this setup for wifi
* In device config page, device -> see attached image
+
* support to switch to unique ID (chipID) mode control by sending commands "chipID+ON" (162243ON) to ID topics
* In device config page, hardware -> set GPIO14 to input
+
* [[File:Esp_relay_board_firmware_r3.1.zip|Firmware 3.1 download here.]], new firmware implemented on board from 4th Feburary 2017.
* Domoticz hardware setup of IDX/VAR for DHT22 normally is 237, switch relay is 100, this must be input, otherwise won't work
+
R4 version
<gallery>
+
* [[File:Relay_board_firmware_r4.zip|Download R4 firwmare here]]
File:Espeasy_dht22_setup.png | setup
+
# 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
File:Espeasy_dht22_value.png | and then value show up
+
# server 1 "mc" is mqttcloud free server, server 2 "sg" is Singarpore server, optimized for Asia area too.
</gallery>
+
 
Device control via HTTP
+
== Documents ==
* Simple command http://192.168.1.109/control?cmd=gpio,13,1
+
Other Software and Firmware
* Complex setup
+
* [[ESPeasy]]
 +
* [[Domoticz]]
 +
Firmware
 +
* [https://github.com/Edragon/esp_firmware Old demo code, firmware please download here]  
 +
Demo video
 +
* [https://www.youtube.com/watch?v=cDZNVRK-ivc Demo video avaialble here.]
 +
* [https://www.youtube.com/watch?v=Tznk1umc20M  Please see the demo video here]
 +
Demo code
 +
* https://github.com/Edragon/esp_firmware
 +
 
 +
 
 +
== Obsolette ==
 +
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
 +
 
 +
 
  
== Quick Start Quide (Smart-Config, old) ==
+
=== Quick Start Quide (Smart-Config, old) ===
  
 
* Config Steps
 
* Config Steps
Line 186: Line 218:
 
|}
 
|}
  
==== Other Configuration ====
 
LED status:
 
{| class="wikitable sortable"
 
|-
 
! 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_20161118.zip]]
 
* 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_r3.1.zip|Firmware 3.1 download here.]], new firmware implemented on board from 4th Feburary 2017.
 
R4 version
 
* [[File:Relay_board_firmware_r4.zip|Download R4 firwmare here]]
 
# 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
 
# server 1 "mc" is mqttcloud free server, server 2 "sg" is Singarpore server, optimized for Asia area too.
 
====  Demo code of version R1 ====
 
{| class="wikitable sortable"
 
|-
 
! Module: LEDBlink !! init.lua || mqtt2.lua ||
 
|-
 
|
 
<syntaxhighlight lang="lua">
 
local M = {}
 
   
 
function M.fast()
 
    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.write(gpio_16,gpio.HIGH)
 
        else
 
            gpio_blink = 0
 
            gpio.write(gpio_16,gpio.LOW)
 
        end
 
    end)
 
     
 
end
 
 
return M
 
</syntaxhighlight>
 
||
 
<syntaxhighlight lang="lua">
 
LED = require "LEDblink"
 
 
print("set up wifi mode")
 
wifi.setmode(wifi.STATION)
 
wifi.sta.autoconnect(0)
 
-- if you want to test smartconfig, disconnect the board first
 
 
wifi.sta.disconnect()
 
 
 
tmr.alarm(1, 6000, 1, function()
 
    if wifi.sta.getip()== nil then
 
   
 
        print("Waiting for smartconfig, IP unavailable..")
 
       
 
        wifi.startsmart(0,
 
            function(ssid, password)
 
            print(string.format("Success. SSID: %s ; PASSWORD: %s", ssid, password))
 
        end)
 
       
 
        LED.fast()
 
 
 
    else
 
        tmr.stop(1)
 
        tmr.stop(2)
 
        print("Config done, IP is "..wifi.sta.getip())
 
       
 
        wifi.stopsmart()
 
       
 
        dofile("mqtt2.lua")
 
    end
 
   
 
end)
 
 
</syntaxhighlight>
 
||
 
<syntaxhighlight lang="lua">
 
print("Running file mqtt")
 
tmr.delay(100000)
 
 
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)
 
  
    else
+
[[category: ESP8266 Hardware]]
        print("receive OFF liked data on light1")
 
        gpio.write(gpio12,gpio.LOW)
 
    end
 
   
 
  else
 
    if topic == "Light2" then
 
        if data == "ON" then
 
            print("received message: ON@light2")
 
            gpio.write(gpio13, gpio.HIGH)
 
  
        else
+
[[Category:ESP Relay Board]]
            print("receive OFF liked data on light2")
 
            gpio.write(gpio13,gpio.LOW)
 
        end
 
    end
 
   
 
  end
 
 
 
end)
 
 
 
 
 
m:connect("m11.cloudmqtt.com", 19311, 0, function(conn)
 
    print("connected")
 
 
 
    m:subscribe({["Light1"]=0, ["Light2"]=0}, function(conn)
 
        print("subscribe Light 1 and 2 success")
 
    end)
 
 
 
end)
 
 
 
</syntaxhighlight>
 
|}
 
 
 
=== Debugging ===
 
Websocket debugging: [[File:CloudMQTT Websocket Console.png|thumbnail]]
 
 
 
* 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: [[File:Esp relay board demo.JPG|300px|thumbnail]]
 
* Debugging info can be read when you use it.
 
<syntaxhighlight lang="lua">
 
NodeMCU custom build by frightanic.com
 
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 192.168.43.134
 
Running file mqtt
 
connected
 
Light2:
 
receive OFF liked data on light2
 
Light1:
 
receive OFF liked data on light1
 
Light1:
 
received message: ON@light1
 
Light1:
 
receive OFF liked data on light1
 
Light2:
 
received message: ON@light2
 
Light2:
 
offline
 
</syntaxhighlight>
 
 
 
== Flash Firmware or Debugging==
 
Setup
 
* 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 info@electrodragon.com
 
* Firmware can be found on [https://github.com/Edragon/esp_firmware/tree/master/ESP%20Relay%20Board 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 [[Category:ESP8266_Code_Guide#Flash_Firmware|here]], flash .bin firmware file to board 0x00000, more instruction please see the page.
 
<br />
 
For nodemcu to upload sketch (old)
 
* Use script interpreter LUA as embedded system programming
 
* open Nodemcu flasher/esp download tool/esptool.py to upload this firmware, more details see here, [http://www.electrodragon.com/esp8266-flash-firmware/ see some guidelines here]<br />
 
* Restart module and upload lua scripts: LEDBlink.lua, init.lua, mqtt2.lua
 
 
 
== Documents ==
 
Demo video
 
* [https://www.youtube.com/watch?v=cDZNVRK-ivc Demo video avaialble here.]
 
* [https://www.youtube.com/watch?v=Tznk1umc20M  Please see the demo video here]
 
Demo code
 
* https://github.com/Edragon/esp_firmware
 
[[category: ESP8266 Boards]]
 

Latest revision as of 00:13, 17 November 2019

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.
Steps User Action Description -
Config Network Power up your board
  • Board will provide a wifi AP "ESP-Relay-Board" or similar
  • (Also all leds blink for testing purpose)
-
Config Network Connect to "ESP-Relay-Board" (or similar) it with no password your phone will then ask you to sign in by pop-up message -
Config Network Configure wifi with scan, click show up wifi list and click your Wifi SSID - -
Config Network Connect to SSID
  • Enter Your wifi router password
Config MQTT Check MQTT Address
  • Keep default remote MQTT server address (default iot.electrodragon.com)
  • Optional - Remote MQTT server port (no need change, default 1883)
  • Optional - Remote MQTT server user ID (not used, keep empty)
  • Optional - Remote MQTT server user password (not used, keep empty)
Config MQTT Setup your own module topic ID
  • MQTT Topic ID, for example we use a complex ID: 74dyt6, but final ID is ESP_74dyt6 (not ESP-74dyt6)
  • please use a unique complex name, otherwise if conflict with other users' topic ID, it can not connect
Config MQTT Connected Successfully Board led blink slowly
Control via MQTT Send commands to control
  • 1_ON or 1_OFF to MQTT example topic ID ESP_74dyt6 will turn on or off relay 1
  • same for relay 2

MQTT APP Control

  • Use any MQTT app (for exampe MyMQTT) to control here for example

Setup for MyMQTT or similar

  • Set only - Server address iot.electrodragon.com (IP address 167.88.114.101)
  • Keep default port 1883

Subscribe to your own command topic

  • For example, if you use board MQTT topic "74dyt6 ", then the full topic name will be ESP_74dyt6
  • Please make sure the ID name is unique and complex, better use numbers instead of words

Board Setup

General Commands

  • 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. ff for green value 255
ESP LED strip board 192.168.0.111\rgb\00ff00 turn light to green. 192.168.0.111 is board IP address

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

Update Log


Demo code and update Log

R3 version

  • Download R3 firmware here File:Relay board 20161118.zip
  • 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 r3.1.zip, 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.

Documents

Other Software and Firmware

Firmware

Demo video

Demo code


Obsolette

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


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
Server: m13.cloudmqtt.com
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 192.168.4.1, listen on port 80