How to command ESPEASY GPIO thru MQTT Mosquitto

Moderators: rtenklooster, Voyager, BertB, Stuntteam

Post Reply
Message
Author
xmenne
Normal user
Posts: 10
Joined: 17 Jul 2019, 17:38
Location: Saint Ouen sur Loire France

How to command ESPEASY GPIO thru MQTT Mosquitto

#1 Post by xmenne » 05 Mar 2020, 12:08

I have a mosquitto broker and Domoticz installed on Pi.
I have a ESPEasy R120 installed on ESP8266 WemosD1 Mini.
All installed recently end of 2019.

I am successfull to have one switch working via Domoticz Http .
http://192.168.1.24/control?cmd=GPIO,15,1 is working fine.

What I want to do is the same thing but thru MQTT.

I have tried several flavor of this configuration without success
ESP03 subscribe Template is >> ESP03/#
Then I Publish on MQTT >> mosquitto_pub -t ESP03/cmd -m gpio,15,1
Therefore I see that on MQTT >> ESP03/cmd gpio,15,1
as expected

The issue is that with several flavor of this command and subscribe template i have no effect on mys ESP and switch.

I have two question for any one who may have a similar configuration :

Where can I see some detailed log in ESPEasy ?
Where am i wrong in the way i write my command ?

Thks
Signed XMenne from France

User avatar
grovkillen
Core team member
Posts: 3620
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: How to command ESPEASY GPIO thru MQTT Mosquitto

#2 Post by grovkillen » 05 Mar 2020, 16:18

You can use the web log or the serial log to see what's going on.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

TD-er
Core team member
Posts: 3518
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: How to command ESPEASY GPIO thru MQTT Mosquitto

#3 Post by TD-er » 05 Mar 2020, 16:51

Also the R120 build is quite old, so not all current features may be present.

xmenne
Normal user
Posts: 10
Joined: 17 Jul 2019, 17:38
Location: Saint Ouen sur Loire France

Re: How to command ESPEASY GPIO thru MQTT Mosquitto

#4 Post by xmenne » 06 Mar 2020, 12:57

Hello Thanks,
I uploaded latest version ESP EASY mega.
This is a big change and i will need time to discover the field of possible with this version.
May be i will find a way to avoid HTTP command to adress the GPIO with this Mega version
Need time as this is not my first activity :)
Thanks again
Signed XMenne from France

User avatar
dynamicdave
Normal user
Posts: 224
Joined: 30 Jan 2017, 20:25
Location: Hampshire, UK

Re: How to command ESPEASY GPIO thru MQTT Mosquitto

#5 Post by dynamicdave » 06 Mar 2020, 15:12

What I do in Node-RED is to use a MQTT-Out node (running Mosquitto) which is set-up with the IP address of your server
then set-up the topic in the MQTT-Out.

Something like... nodeXX/gpio/14
Where nodeXX is the 'Unit Name' as used in the ESP-Easy Config tab.

14 relates to the GPIO pin, which in this case is D5.

Pin mappings are...
D8 GPIO-15
D7 GPIO-13
D6 GPIO-12
D5 GPIO-14

I have about 40 Wemos D1 Mini devices and each one has a fixed IP address, like 192.168.1.41
So I name the Wemos D1 Mini with 'node41' and stick a label on the botton of the breadboard.
This means it's easy to workout the IP address when I pick-up a breadboard.

The Controller Subscribe setting in ESP-Easy looks like this... %sysname%/#
This means the Wemos named 'node41' will subscribe to... node41/#

To test it out (using Node-RED) you could connect an Inject node to the MQTT-Out node.
Set the Inject node to output a payload of a numeric value - either a 1 or 0 to operate the GPIO pin.

Hope this works for you.

xmenne
Normal user
Posts: 10
Joined: 17 Jul 2019, 17:38
Location: Saint Ouen sur Loire France

Re: How to command ESPEASY GPIO thru MQTT Mosquitto

#6 Post by xmenne » 10 Mar 2020, 19:19

Hello
Many thanks, you open my mind to new path to solution and it works now

What I did for the record

I updated ESP with ESPEasy Mega version
I discovered the new function MQTT Import
I create a new Device Generic MQTT import
Name = Task Name >> RelaisChevret
MQTT Topic1 >> domoticz/out/ESP11_Relai1
andValue Name >> Relai1

When you publish on your Broker
mosquitto_pub -t domoticz/out/ESP11_Relai1 m 1

Then your Device Value Relai1 is 1

After that I created Rules (also new for me)
On RelaisChevret#Relai1=1 do
GPIO,12,1
end on

and it works and this close this post I suppose.
I now have to work on Domoticz but it is another story.

Many thanks to you all , this forum is very helpful.
Hope i can help some one one day in return .
Signed XMenne from France

xmenne
Normal user
Posts: 10
Joined: 17 Jul 2019, 17:38
Location: Saint Ouen sur Loire France

Re: How to command ESPEASY GPIO thru MQTT Mosquitto

#7 Post by xmenne » 11 Nov 2020, 18:29

The purpose of this MONIT configuration is to have Domoticz restart fully after an electrica shut down of my RASP.
Here we have the config for Web Server monit , config for alerting email and config for Restart Domoticz service


set mailserver smtp.gmail.com port 587 # primary mailserver
username "xx.mennesson@gmail.com" password "M__7"
using tlsv1
with timeout 30 seconds
set alert xx.mennesson@gmail.com
#
#
# backup.bar.baz port 10025, # backup mailserver on port 10025
# localhost # fallback relay
#
#
## By default Monit will drop alert events if no mail servers are available.
## If you want to keep the alerts for later delivery retry, you can use the
## EVENTQUEUE statement. The base directory where undelivered alerts will be
## stored is specified by the BASEDIR option. You can limit the queue size
## by using the SLOTS option (if omitted, the queue is limited by space
## available in the back end filesystem).
#
set eventqueue
basedir /var/lib/monit/events # set the base directory where events will be stored
slots 100 # optionally limit the queue size
#
#

#
set httpd port 2812
use address 192.168.1.107 # only accept connection from localhost (drop if you use M/Monit)
allow 0.0.0.0/0.0.0.0 # allow localhost to connect to the server and
allow admin:monit # require user 'admin' with password 'monit'
#
#
# #with ssl { # enable SSL/TLS and set path to server certificate
# # pemfile: /etc/ssl/certs/monit.pem
# #}
#
###############################################################################
## Services
###############################################################################


###### Monitoring Domoticz selon PROJETSDIY.FRN

check process domoticz with pidfile /var/run/domoticz.pid
start program = "/etc/init.d/domoticz.sh start"
stop program = "/etc/init.d/domoticz.sh stop"
if failed
url http://127.0.0.1:8080/json.htm?type=com ... getversion
and content = '"status" : "OK"'
for 2 cycles
then restart
if 5 restarts within 5 cycles then exec "/sbin/reboot"
#
## Check that a process is running, in this case Apache, and that it respond
##
Signed XMenne from France

xmenne
Normal user
Posts: 10
Joined: 17 Jul 2019, 17:38
Location: Saint Ouen sur Loire France

Re: How to command ESPEASY GPIO thru MQTT Mosquitto

#8 Post by xmenne » 11 Nov 2020, 18:35

The purpose of this Script LUA is to activate e relay from Domoticz thru MQTT:

-[[
Intention of this script is to publish defined message using MQTT broker running on a localhost.
The script will trigger only when the status of the defined device is changed.
--]]

--------------------------------
------ Variables to edit ------
--------------------------------
devicename = "RelaisChevret" --Name of the device
deviceIDX = 10
debug = false
--------------------------------
-- End of variables to edit --
--------------------------------

commandArray = {}

if (devicechanged[devicename]) then
print(devicename.." MQTT script running...")

if (devicechanged[devicename] == "On") then
print(devicename.." turned on!")
os.execute('mosquitto_pub -h mqtt.leamicz.net -t domoticz/out/esp11_relai1 -m "1")
elseif (devicechanged[devicename] == "Off") then
print(devicename.." turned off!")
os.execute('mosquitto_pub -h mqtt.leamicz.net -t domoticz/out/esp11_relai1 -m "0")
end
end

return commandArray
Signed XMenne from France

Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests