MQTT subscribed - how to execute cmds on esp8266?

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
tozett
Normal user
Posts: 734
Joined: 22 Dec 2015, 15:46
Location: Germany

MQTT subscribed - how to execute cmds on esp8266?

#1 Post by tozett » 22 Dec 2015, 15:51

Hi,
i am faszinated by EasyESP, it has all i ever thought of.
i recently have flashed a ESP01, it running fine, it sends to my mosquitto broker and on the serial-console i saw, it subscribed itself to all /<name> messages, like mine: /Esp01/#

i did not find a lot doku, so my question: What messages can i send, to let the EasyESP on my ESP01 execute (switch-)cmds on the GPIOs ?
i found some pieces in the domoticz-mqtt code, but im not that experienced in programming. can anybody enlighten me?

great thanks,
ozett

Martinus

Re: MQTT subscribed - how to execute cmds on esp8266?

#2 Post by Martinus » 22 Dec 2015, 16:03

The commands to control output directly were mainly build for a generic http interface. And have mainly been tested through http only.
So using MQTT could bring limitations for output control or could just not work yet. There's some guidance in this tutorial:

http://www.esp8266.nu/index.php/Tutorial_OpenHAB_Switch

I think in your case you could send a message to /Esp01/gpio/2 with value '1' to turn on GPIO-2

tozett
Normal user
Posts: 734
Joined: 22 Dec 2015, 15:46
Location: Germany

Re: MQTT subscribed - how to execute cmds on esp8266?

#3 Post by tozett » 22 Dec 2015, 16:30

Thanks for the quick reply.
i tested it without devices connected to gpio, i must do this later with a led, for example.
but i would have been helpful (at leat to me), if the output of "mosquitto_sub -t /Esp01/#" would show up on the serial console...
there is only some other debug-info running, i may look in the source, if mqtt-messages 'should' show up on the console...

Code: Select all

NIT : Booting Build nr:48
WIFI : Connecting...
INIT : I2C
MQTT : Failed to connected to broker
MQTT : Connected to broker
Subscribed to: /Esp01/#
INIT : Boot OK
INIT : Normal boot
WD   : Uptime 0 ConnectFailures 0 FreeMem 27600
WD   : Uptime 1 ConnectFailures 0 FreeMem 27568
WD   : Uptime 1 ConnectFailures 0 FreeMem 27360
WD   : Uptime 2 ConnectFailures 0 FreeMem 27344
but again, thanks for the quick reply...
(i will investigate, if other cmds beside "on/off" could be send via mqtt...)

Martinus

Re: MQTT subscribed - how to execute cmds on esp8266?

#4 Post by Martinus » 22 Dec 2015, 16:35

You should see logged MQTT topics if you increase serial log level to 3 or 4.

tozett
Normal user
Posts: 734
Joined: 22 Dec 2015, 15:46
Location: Germany

Re: MQTT subscribed - how to execute cmds on esp8266?

#5 Post by tozett » 22 Dec 2015, 16:47

thanks, i found it in the EaspEasy Webinterface unter Tools/Advanced and set Log-level for serial to 4.
if i send

Code: Select all

mosquitto_pub -t /Esp01/gpio/2 -m on
i can see the manual-entered topic on the serial-console: (how do i validate, if the topic resembles a valid template on ESpEasy?)

Code: Select all

FLASH: Settings saved
WD   : Uptime 23 ConnectFailures 0 FreeMem 25824
MQTT : Topic /Esp01/gpio/2
WD   : Uptime 24 ConnectFailures 0 FreeMem 25824
FLASH: Settings saved
MQTT : Topic /Esp01/gpio/2
WD   : Uptime 24 ConnectFailures 0 FreeMem 25808
The message/cmd (=on/off, 1/0) will not show up there. would be helpful for debugging..

and i found some lines in the source (https://github.com/ESP8266nu/ESPEasy/bl ... /_C005.ino) for

"#define CPLUGIN_NAME_005 "OpenHAB MQTT"

where the receiving-part ends with calling another plugin like:

Code: Select all

 String cmd = topicSplit[1];
        struct EventStruct TempEvent;
        TempEvent.Par1 = topicSplit[2].toInt();
        TempEvent.Par2 = event->String2.toFloat();
        PluginCall(PLUGIN_WRITE, &TempEvent, cmd);
        break;
Does this mean, that i can send everything meaningful (pwm-value 512, on/off) to every GPIO ?

-------
somebody came also to this point: http://www.esp8266.nu/forum/viewtopic.p ... =202#p1424,
but not further...

ipua
Normal user
Posts: 11
Joined: 06 Apr 2016, 20:20

Re: MQTT subscribed - how to execute cmds on esp8266?

#6 Post by ipua » 16 Jan 2017, 20:01

I am using Openhab and v.147 of ESP Easy.
How I can switch the LCD on or off using MQTT?
I tested

Code: Select all

mosquitto_pub -m 'off' -t /ESP1/cmd/LCDCMD
mosquitto_pub -m 'off' -t /ESP1/LCDCMD
mosquitto_pub -m 'off' -t /ESP1/LCD/lcdcmd
mosquitto_pub -m 'off' -t /ESP1/lcdcmd
without any result.
Same comands (lcdcmd)thru http works fine.
Thanks for help.

tozett
Normal user
Posts: 734
Joined: 22 Dec 2015, 15:46
Location: Germany

Re: MQTT subscribed - how to execute cmds on esp8266?

#7 Post by tozett » 17 Jan 2017, 09:11

i am not sure, if mqtt works generally as input to espeasy.
maybe only in a plugin, where it is coded in.

somebody said try this:
papperone wrote:Did you try to send MQTT command to the topic "/<%sysname%>/cmd"; it shoudl work...
somebody else said, you need the mqtt import plugin.
paulymorph wrote:Next, MQTT... I also compiled and loaded the MQTT Import plugin (and Extra Utilities) which appear to have successfully installed. Now, i'm trying to figure out how to publish (externally) to an MQTT topic such as /node2/candle/Brightness and have WiFi Candle brightness be adjusted accordingly without having to go through the UI of the ESP.
but everything discussed for the wifi-candle plugin:
viewtopic.php?f=2&t=2147&hilit=mqtt+cmd&start=40#p12219

in this plugin it goes like this:

Code: Select all

        // MQTT   : mosquitto_pub -d -t sensors/espeasy/ESP_Candle/cmd  -m "CANDLE_OFF"

may the hints could help you..?

ipua
Normal user
Posts: 11
Joined: 06 Apr 2016, 20:20

Re: MQTT subscribed - how to execute cmds on esp8266?

#8 Post by ipua » 21 Jan 2017, 19:00

Thanks tozett!
Finally I found how to conrtol LCD:

Code: Select all

mosquitto_pub -t /ESP1/cmd -m 'lcdcmd,on'
mosquitto_pub -t /ESP1/cmd -m 'lcdcmd,off'

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 41 guests