ESP Easy

rwblinn
Site Admin
Posts: 195
Joined: 07 Oct 2017, 12:16

ESP Easy

Postby rwblinn » 09 Oct 2017, 11:58

Node-RED ESP Easy - About
ESP Easy ( http://www.letscontrolit.com/wiki/index.php/ESPEasy ) is a solution which turns the ESP Module into an easy multifunction sensor device.
The configuration of ESP Easy is browser based.
Recommend to get started by reading the ESP Easy Wiki ( http://www.letscontrolit.com/wiki/index.php/ESPEasy ) and the Command Reference ( http://www.letscontrolit.com/wiki/index ... _Reference ).
Regular lookup the ESP Easy Community Forum ( http://www.letscontrolit.com/forum/ ).

For most of the experiments, a NodeMCU 0.9 is used with IP address http://192.168.0.50 .

#Setup
As a first test, setup a NodeMCU 0.9 using the Arduino IDE by following the Instructions ( http://www.letscontrolit.com/wiki/index ... are_Upload ).
Additional hints while setting up ESP Easy (status 20161219)
* Ensure to load the latest version of the Additional Boards Manager ( http://arduino.esp8266.com/stable/packa ... index.json ).
* Ensure to use the latest version of the ESP8266 Library (check via Library Manager).
* Changes in espeasy.ino (located in the espeasy source folder):
* -Set the network SSID and password. As default server:port used the Raspberry Pi address as the mosquitto broker runs on it.</li>
* -Keep the DEFAULT_AP_KEY to "configesp".
* -If want to have static IP address, then set DEFAULT_USE_STATIC_IP to true (for the experiments using 192.168.0.50).
* -Set the DEFAULT_PROTOCOL 5
* -Note: All settings can be changed after successfull installation, via the settings menu, e.g. 192.168.0.50/config
* Compile and upload to the ESP - this might take depending device and upload speed.
* Open a browser and enter 192.168.0.50. The ESPEasy configuration page should be shown.
* For the experiments, connected the ESP to the Raspberry Pi (for power supply only).

#References
Project Page: http://www.letscontrolit.com/wiki/index.php/ESPEasy
Command Reference: http://www.letscontrolit.com/wiki/index ... _Reference
System Variables: http://www.letscontrolit.com/wiki/index ... _Variables
Forum: http://www.esp8266.nu/forum
GitHub Download Stable Releases: https://sourceforge.net/projects/espeasy/
Source Code Development: https://github.com/ESP8266nu

-Node-RED ESP Easy - Flow BMP180
Read the Temperature & Pressure from a BMP180 sensor connected to an ESP8266 NodeMCU v0.9.

Reference: http://www.letscontrolit.com/wiki/index ... tricSensor

-Parts Needed
* 1x ESP8266 [NodeMCU v0.9]
* 1x BMP180

-Wiring
#ESP8266 = BMP180
VCC=VCC
GND=GND
D2 (GPIO4) = SDA
D3 (GPIO0) = SCL

#ESP8266 = LED
D6 (GPIO12) = + Anode
GND = GND

-Circuit
img://http://www.rwblinn.de/nodered/nod ... 180-bb.png

-Prototype
img://http://www.rwblinn.de/nodered/nod ... p180-p.png

-Prepare
#ESP Easy Create Device LED
Open browser and connect to ESP Easy e.g. ip-address 192.168.0.50
Select Devices > Edit
Device: Temperature & Pressure - BMP085
Name: BMP1
Delay: 5
IDX/Var: 5 (just a placeholder, but must be greater 0)
Send Data: checked
Value Name 1: Temperature
Value Name 2: Pressure
Notes:
The device name is used for the MQTT subscribe & publish template, which is defined as global variable %sysname%.
The BMP085 is compatible with the BMP180 used.

#ESP Easy Define MQTT
ESP Easy Protocol: openHAB MQTT
ESP Easy Tools > Advanced > Subscribe & Publish Templates:
Subscribe: /%sysname%/#
Publish: /%sysname%/%tskname%/%valname%

ESP Easy publishes as response for the BMP180 Sensor Values:
Subscribed to topic: /espeasy/#
Topic: /espeasy/BMP1/Temperature
Payload: 19.60

Topic: /espeasy/BMP1/Pressure
Payload: 1023.97

-Flow
img://http://www.rwblinn.de/nodered/nod ... p180-f.png

-Dashboard
img://http://www.rwblinn.de/nodered/nod ... p180-d.png

-Flow Explanation
MQTT IN
#MQTT In Node
The MQTT in node uses server "localhost" with default port 1883 and topic /espeasy/#.
The output goes to the "Delay Node".

#Delay Node
Limits the messages to 1msg/10s.
The output goes to a "Function Node".

#Function Node
Build two messages:
* Temperature with output "Chart Node Temperature"
* Pressure with output "Chart Node Pressure"

#Chart Node Temperature
Dashboard node to show the BMP180 measured temperature deg C in a chart.
Used the chart defaults, open for further configuration.

#Chart Node Pressure
Dashboard node to show the BMP180 measured pressure mbar in a chart.
Used the chart defaults, open for further configuration.

-Flow JSON
[
{"id":"cbd3434a.00b46","type":"mqtt in","z":"4bd9bd7e.db3f4c","name":"","topic":"/espeasy/#","qos":"2","broker":"fb495dad.b6839","x":90.19999694824219,"y":88,"wires":[["6847c49b.529ea4"]]},
{"id":"1d3e2ef2.c637b9","type":"ui_chart","z":"4bd9bd7e.db3f4c","name":"Temperature","group":"408c2bef.2fa7ac","order":0,"width":0,"height":0,"label":"","chartType":"line","legend":"false","xformat":"HH:mm","interpolate":"linear","nodata":"","ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"x":677.5,"y":81.39999389648438,"wires":[[],[]]},
{"id":"e45475e0.022eb","type":"ui_chart","z":"4bd9bd7e.db3f4c","name":"Pressure","group":"f65aa0b1.8a2078","order":0,"width":0,"height":0,"label":"","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"x":667.5,"y":128.40000915527344,"wires":[[],[]]},
{"id":"66790e4f.78ddf","type":"function","z":"4bd9bd7e.db3f4c","name":"Build Messages","func":"var msgT = {};\nvar msgP = {};\nif (msg.topic == \"/espeasy/BMP1/Temperature\"){\n msgT.payload = msg.payload;\n}\nif (msg.topic == \"/espeasy/BMP1/Pressure\"){\n msgP.payload = msg.payload;\n}\nreturn [msgT, msgP];","outputs":"2","noerr":0,"x":457.5,"y":87.59999084472656,"wires":[["1d3e2ef2.c637b9"],["e45475e0.022eb"]]},
{"id":"6847c49b.529ea4","type":"delay","z":"4bd9bd7e.db3f4c","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"10","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":267.5,"y":88.80000305175781,"wires":[["66790e4f.78ddf"]]},
{"id":"fb495dad.b6839","type":"mqtt-broker","z":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"willTopic":"","willQos":"0","willPayload":"","birthTopic":"","birthQos":"0","birthPayload":""},
{"id":"408c2bef.2fa7ac","type":"ui_group","z":"","name":"Temperature","tab":"6f462fdd.90ac1","disp":true,"width":"6"},
{"id":"f65aa0b1.8a2078","type":"ui_group","z":"","name":"Pressure","tab":"6f462fdd.90ac1","disp":true,"width":"6"},
{"id":"6f462fdd.90ac1","type":"ui_tab","z":"","name":"BMP180","icon":"dashboard"}
]

-ToDo
* Flow completed.

-Version
20161221


-Node-RED ESP Easy - Flow LED Switch
Switch an LED connected to Pin D6 (GPIO12) of an ESP8266 NodeMCU v0.9.

-Parts Needed
* 1x ESP8266 [NodeMCU v0.9]
* 1x LED

-Wiring
#ESP8266 = LED
D6 (GPIO12) = + Anode
GND = GND

-Prepare
#ESP Easy Create Device LED
Open browser and connect to ESP Easy e.g. ip-address 192.168.0.50
Select Devices > Edit
Device: Switch input
Name: LED1
GPIO: GPIO-12
Pull-up: checked
Note: The device name is used for the MQTT subscribe & publish template, which is defined as global variable %sysname%.

#ESP Easy Define MQTT
ESP Easy Protocol: openHAB MQTT
ESP Easy Tools > Advanced > Subscribe & Publish Templates:
Subscribe: /%sysname%/#
Publish: /%sysname%/%tskname%/%valname%

Example syntax MQTT to set the state of a GPIO port to high:
Topic: /espeasy/cmd
Payload: GPIO,Port,State e.g. gpio,12,1
Note: %sysname% is replaced by espeasy.

ESP Easy publishes as response:
Topic: /espeasy/LED1/Switch
Payload: 0 | 1

#Test MQTT
Test if the LED can be turned on/off via MQTT by using mosquitto invoked from a Raspberry Pi terminal.
Logon to the Raspberry Pi as user Pi and open a Terminal session
Turn LED ON: $ mosquitto_pub -t /espeasy/cmd/gpio/12 -m 1
Turn LED OFF: $ mosquitto_pub -t /espeasy/cmd/gpio/12 -m 0

ESP Easy publishes as response:
Topic: /espeasy/LED1/Switch
Payload: 0 | 1

#Test HTTP
Test if the LED can be turned on/off via HTTP.
Switch ON: http://192.168.0.50/control?cmd=gpio,12,1
Response:{"log": "GPIO 12 Set to 1","plugin": 1,"pin": 12,"mode": "output","state": 1}
Switch OFF: http://192.168.0.50/control?cmd=gpio,12,1
Response:{"log": "GPIO 12 Set to 0","plugin": 1,"pin": 12,"mode": "output","state": 0}

-Flow
img://http://www.rwblinn.de/nodered/nod ... switch.png

-Flow Explanation
MQTT OUT
#Inject Node
The Inject Node to turn the LED ON using topic /espeasy/cmd and payload gpio,12,1
The output goes to the "MQTT Out Node".

#Inject Node
The Inject Node to turn the LED OFF using topic /espeasy/cmd and payload gpio,12,0
The output goes to the "MQTT Out Node".

Note: it is not required to define the topic in the Injext Nodes because it is also defined in the "MQTT Out Node".

#MQTT Out Node
The MQTT out node uses server "localhost" with default port 1883 and topic /espeasy/cmd.
Note: The name espeasy is defined in the ESP Easy settings Config > Name

The publish payload returns
topic: /espeasy/status
payload: {"log": "GPIO 12 Set to 1","plugin": 1,"pin": 12,"mode": "output","state":1}
and
topic:/espeasy/LED1/Switch
payload:1 or 0

MQTT IN
#MQTT In Node
The MQTT in node uses server "localhost" with default port 1883 and topic /espeasy/#.
The output goes to the "Debug Node".

#Debug Node
Logs the payload for the topics published for /espeasy/#.
Examples:
20.12.2016, 14:12:06/espeasy/#/espeasy/status : msg.payload : string [84]{ "log": "GPIO 12 Set to 1", "plugin": 1, "pin": 12, "mode": "output", "state": 1 }
20.12.2016, 14:12:06/espeasy/#/espeasy/LED1/Switch : msg.payload : string [1]1

-Flow JSON
[
{"id":"abf0a0e3.7e8298","type":"mqtt out","z":"c1600a40.10903","name":"","topic":"/espeasy/cmd","qos":"","retain":"","broker":"fb495dad.b6839","x":480,"y":280,"wires":[]},
{"id":"b83b16ff.063938","type":"inject","z":"c1600a40.10903","name":"","topic":"","payload":"gpio,12,1","payloadType":"str","repeat":"","crontab":"","once":false,"x":100,"y":280,"wires":[["abf0a0e3.7e8298"]]},
{"id":"2a4bb543.6facaa","type":"inject","z":"c1600a40.10903","name":"","topic":"","payload":"gpio,12,0","payloadType":"str","repeat":"","crontab":"","once":false,"x":100,"y":340,"wires":[["abf0a0e3.7e8298"]]},
{"id":"a29da5e0.d4bce","type":"debug","z":"c1600a40.10903","name":"/espeasy/#","active":true,"console":"false","complete":"payload","x":470,"y":420,"wires":[]},
{"id":"1f529f6.11b4f61","type":"mqtt in","z":"c1600a40.10903","name":"","topic":"/espeasy/#","qos":"2","broker":"fb495dad.b6839","x":100,"y":420,"wires":[["a29da5e0.d4bce"]]},
{"id":"6b312157.a1c918","type":"comment","z":"c1600a40.10903","name":"Protocol openHAB MQTT","info":"Switch an LED connected to Pin D6 = GPIO12 of a NodeMCU.\nMQTT is used to trigger switching.\n\nESPEasy protocol set for this experiment is openHAB MQTT:\nConfigered in ESPEasy Tools > Advanced:\nSubscribe Template: /%sysname%/#\nPublish Template: /%sysname%/%tskname%/%valname%\n\nSyntax MQTT: \nTopic: /espeasy/cmd\nPayload: command like GPIO,Port,State\ne.g. gpio,12,1\nConfigure in f.e. Inject Node which output goes to a MQTT out node:\nThe MQTT out node uses server localhost with default port 1883 and topic /espeasy/cmd.\nThe Inject Node to turn the LED ON uses as topic /espeasy/cmd and payload gpio,12,1\nThe Inject Node to turn the LED OFF uses as topic /espeasy/cmd and payload gpio,12,0\n\nNote\nThe name espeasy is defined in the ESPEasy settings Config > Name\n\nThe publish payload returns \ntopic:\n/espeasy/status\npayload:\n{\n\"log\": \"GPIO 12 Set to 1\",\n\"plugin\": 1,\n\"pin\": 12,\n\"mode\": \"output\",\n\"state\": 1\n}\nand\ntopic:\n/espeasy/LED1/Switch\npayload:\n1 or 0\n\n\n","x":130,"y":240,"wires":[]},
{"id":"fb495dad.b6839","type":"mqtt-broker","z":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"willTopic":"","willQos":"0","willPayload":"","birthTopic":"","birthQos":"0","birthPayload":""}
]

-ToDo
* Flow completed.

-Version
20161220


-Node-RED ESP Easy - Flow OLED
Display on an OLED display, the uptime (line 1), system time (line 2), IP address (line 3).
In addition, see flows LED Switch, BMP180, show
* the status of an LED, LED: 0 | 1 trigged by switching on / off (line 4)
* the temperature (line 5) & pressure (line 6) from a BMP180 sensor

Supported (state 20161221) are OLED text messages, 8 lines of 16 characters.

Reference: www.letscontrolit.com/wiki/index.php/OLEDDisplay

To trigger the LED, the flow as described under Node-RED ESP > Easy LED Switch is used.

-Parts Needed
* 1x ESP8266 [NodeMCU 1.0]
* 1x OLED [0,96 Inch I2C IIC SPI serial 128 x 64 OLED LCD LED Display-Modul for Arduino]
* 1x LED

-Wiring
#NodeMCU = OLED=NodeMCU
VCC=VCC
GND=GND
D2 (GPIO4) = SDA
D3 (GPIO0) = SCL

#LED
Wiring and ESP Easy setup of the LED, see Node-RED ESP > Flow LED Switch.

#BMP180
Wiring and ESP Easy setup of the BMP180, see Node-RED ESP > Flow BMP180.

-Prepare
#ESP Easy Hardware
Set the GPIO ports
Wifi Status Led: GPIO-0
SDA: GPIO-2
SCL: GPIO-14

#ESP Easy Create Device OLED
Open browser and connect to ESP Easy e.g. ip-address 192.168.0.50
Select Devices > Edit:
Device: Display - OLED SSD1306
Name: OLED1
Delay: 5 (5 seconds, if update faster then set to 2 seconds).
IDX: 1 (just a placeholder)
I2C Address: 3C
Rotation: Normal
Line 1: Uptime %uptime%
Line 2: Systemtime %systime%
Line 3: IP %ip%
Line 4: LED: [LED1#Switch]
Other lines left empty.
Display Button: GPIO-0
Disply timeout: 10

Click submit and close.

Note:
ESP Easy > Tools > I2C Scan, shows the I2C Addresses in use:
I2C Addresses in use Known devices
0x3c OLED SSD1306 Display

The LED is named LED1. The corresponding taskname is LED1.
As the device is a switch, the value is "Switch".
Lookup the source code to get the value names for the sensors. Example:
File ..\source\espeasy\_P001_Switch.ino defines like:
#define PLUGIN_VALUENAME1_001 "Switch"

#Test HTTP
Turn the OLED display ON or off via HTTP
192.168.0.50/control?cmd=oledcmd,on
192.168.0.50/control?cmd=oledcmd,off

Clear the OLED display via HTTP
192.168.0.50/control?cmd=oledcmd,clear

Send text to line 1 starting column 1
192.168.0.50/control?cmd=oled,1,1,Hello World

#Test LED
Using the flow as outlined in Node-RED ESP > Easy LED Switch, results in updated display.

-Prototype
img://http://www.rwblinn.de/nodered/nod ... oled-p.png


-Node-RED ESP Easy - Hints
Various Hints

#Serial Monitor
Checking the output of the ESP Module, can be done by using the Arduino IDE Serial Monitor (Menu Tools > Serial Monitor).
Baud rate: 115200
Output Example (with a BMP085 Device):
INIT : Booting Build nr:120
IP : Static IP :192.168.0.50
WIFI : Connecting... 1
WIFI : Connected!
INIT : I2C
MQTT : Connected to broker
Subscribed to: /espeasy/#
INIT : Boot OK
INIT : Normal boot
WD : Uptime 0 ConnectFailures 0 FreeMem 28664
BMP : Temperature: 19.84
BMP : Barometric Pressure: 1024.02

#ESP Easy Define MQTT
Open browser and connect to ESP Easy e.g. ip-address 192.168.0.50
ESP Easy Config:
Name: espeasy (this is the sysname variable used for tasks/events)
Protocol: openHAB MQTT with local controller.
Controller IP: 192.168.0.16 (Raspberry Pi address running mosquitto)
ESP Easy Tools > Advanced:
Subscribe & Publish Templates:
Subscribe: /%sysname%/#
Publish: /%sysname%/%tskname%/%valname%

Example syntax MQTT to set the state of a GPIO port to high:
Topic: /espeasy/cmd
Payload: GPIO,Port,State e.g. gpio,12,1
Note: %sysname% is replaced by espeasy.

#Event Value Names
If a device, LED in this case, is named LED1, then the corresponding taskname is LED1.
As the device is a Switch, the value is "Switch".
Lookup the source code to get the value names for the sensors.

Examples:
Device Switch
Example Name: LED1
File:
..\source\espeasy\_P001_Switch.ino
Values:
#define PLUGIN_VALUENAME1_001 "Switch"
Get Value:
LED1#Switch

Device BMP085
Example Name: BMP1
File:
..\source\espeasy\_P006_BMP085.ino
Values:
#define PLUGIN_VALUENAME1_006 "Temperature"
#define PLUGIN_VALUENAME2_006 "Pressure"
Get Value:
BMP1#Temperature
BMP1#Pressure

Return to “Various Topics”

Who is online

Users browsing this forum: No registered users and 1 guest