Page 1 of 1

mqtt cant receive gpio command

Posted: 02 Aug 2018, 17:07
by randytsuch
I've spend the last few days trying to get mqtt working on one of my esp's.

Running mega-20180723, using the "normal" version. Compiled and loaded with Platformio using the wiki instructions.
Loaded into a wemos mini d1 pro.

On the other side, I have a pi running home assistant. I have seen threads that the embedded mqtt in HA has problems, and that's what I'm using, but I don't think its HA and I will explain why.

I can get status from the ESP, so I know the mqtt interface works fine. I have a couple switches, and they change state when they should.

I can send data over mqtt to the the esp using MQTT import, and then setting up a rule to change the relay state. Works every time.

I also used both MQTTLens and MQTT.fx to both monitor and to try to send MQTT messages to my esp.
if name of esp was ESP00
then I'd use a topic of
/ESP00/gpio/12
payload of 0 or 1.

Controller subscribe is
%sysname%/#
also tried the default
/%sysname%/#

And tried many variations of that command. I'd never see any log messages to say the message was received, but I know it was sent because of the MQTT programs.
I also used both of the MQTT programs to send the command. Last night I was using MQTT.fx.

But like I said, MQTT import worked no problem, and I would see log messages when I sent with that. With MQTT import, I needed to change the topic to match how I set up the parameter, worked easily.
But I have a different problem there. It sets the MQTT parameter, and that fires my rule, which toggles a relay. But if I don't change the MQTT parameter, after a while (maybe a few hours), the rules gets fired again, and the relay toggles again. I didn't send a command, this happened in the middle of the night. I could reset the MQTT parameter from the HA side, and I may do this if I have to.

But I would really like to figure how why I can't send a MQTT message to my ESP Easy?
What does the format of the topic need to be, from the sender side?

Thanks for any advice
Randy

Re: mqtt cant receive gpio command

Posted: 02 Aug 2018, 20:00
by grovkillen
Have you studied the wiki? You're not sending correct topics and payload.

Re: mqtt cant receive gpio command

Posted: 02 Aug 2018, 22:07
by randytsuch
Based on the wiki, last night I was trying

topic: /ESP00/cmd
payload: gpio/12/1

And based on my experience with mqtt port, if I get the payload part incorrect, espeasy will at complain about the payload in a logger message
So if payload should really be gpio,12,1 then I would expect an error message.

I've also done a lot of web searching, and almost all of the posts I find where people say this works they use a format like what I said in my previous post
although I just found this example, which is inside a rule
Publish /sonoff1/cmd,GPIO,12,0

Any hint?

Randy

Re: mqtt cant receive gpio command

Posted: 02 Aug 2018, 22:33
by grovkillen
Show me screen shots and I'll give you the correct payload etc.

But you should be able to get it to work using this:

topic: <MQTT subscribe template>/cmd
example: /ESP_EASY/cmd

payload: <command syntax>
example: GPIO,12,1

More commands:
https://www.letscontrolit.com/wiki/index.php/GPIO
https://www.letscontrolit.com/wiki/inde ... _Reference

Re: mqtt cant receive gpio command

Posted: 02 Aug 2018, 22:41
by randytsuch
Thanks for that, I'll give it a try when I get home tonight, and post some screenshots.

The other thing I should mention is my ESP time was off, and I just fixed that, don't know if MQTT cares about time.

Randy

Re: mqtt cant receive gpio command

Posted: 02 Aug 2018, 22:56
by grovkillen
No that shouldn't be a problem.

Re: mqtt cant receive gpio command

Posted: 03 Aug 2018, 03:39
by kenkoknz
Hi,
if it is any help, i just tried the following with node red in Pi(with mqtt node) and also android app mqtt dashboard. Both syntax below works:

nodemcu
mega 21080801
subscribe to: /%sysname%/#

case 1:
topic: /ESP00/gpio/12
payload of 0 or 1. (I tried string, number and bool, all ok)

case 2 (as suggested by Grivkillen):
topic: /ESP_EASY/cmd
payload: GPIO,12,1

Re: mqtt cant receive gpio command

Posted: 03 Aug 2018, 05:12
by randytsuch
Ken
Thanks for taking the time to do those tests.

So success!!

But only with grovkillen's (wiki) method.

That works every time.

I still can't get the topic = /ESP00/gpio/12 way to work

But I'm able to get it working, so I'm happy.

One thing I would like to mention.
MQTT commands don't get sent to the logger, which did not help in debugging this.
Seems like if a MQTT command is received, it should show up in the log, like it does when you send to MQTT port.

Randy

Re: mqtt cant receive gpio command

Posted: 03 Aug 2018, 07:32
by kenkoknz
what level have you got the log settings? maybe try debug.

Re: mqtt cant receive gpio command

Posted: 03 Aug 2018, 16:56
by randytsuch
I have it set to debug level for web output.

I'm starting to think that maybe my build is a little wonky. I built it on platformio on a macbook, and maybe something went slightly wrong.

I have a spare wemos mini d1 (4 meg version), which I can load with the precompiled espeasy. I'll try that this weekend, and see if it works better.

I also had a relay trigger in the middle of last night, and I'm not sure why. I looked at my mosquitto monitor, and it didn't show any traffic that would have triggered the relay, so I'm hoping the change to a d1 with precompiled sw will fix that too.

Randy

Re: mqtt cant receive gpio command

Posted: 06 Aug 2018, 16:56
by randytsuch
Update in case someone finds this in a search looking for help.

I changed out the wemos d1 pro with a wemos d1, and loaded it via my macbook with a mid july verion of esp easy.

This worked, when sending via mqtt:
topic: /ESP00/gpio/12
payload of 0 or 1

But if I tried something like pulse or pcfgpio instead of gpio, it did not work

But if you use
topic: /ESP_EASY/cmd
payload: gpio,12,1

Then you can change out gpio with pulse, pcfgpio and it works fine.

So using cmd is safer as it seems to support any valid command you would want to use.

Randy

Re: mqtt cant receive gpio command

Posted: 22 Aug 2019, 18:09
by Quart
Got it working now !!!

The missing part for me was just this
Topic:
ESP_Easy/gpio/15

Message:
1


So now my Homey can post when a motion sensor is active and switch the diods on and when the zone is not active its turn the led off.

Here is how i looks in Homey and also a test it, when doorbell is pressed turn led on
mqtt.JPG
mqtt.JPG (20.26 KiB) Viewed 17077 times

Re: mqtt cant receive gpio command

Posted: 23 Aug 2019, 12:54
by TD-er
If crucial information is missing in the documentation, please let me know, or create a pull request with the suggested improvements :)

See https://espeasy.readthedocs.io/en/lates ... #c014-page

Re: mqtt cant receive gpio command

Posted: 17 Sep 2019, 15:23
by HarpieC
The docs page referes to the homie convention controller. The mqtt topic for gpio here is defined as:

Code: Select all

homie/%unitName%/SYSTEM/gpio#/set
The GPIO port must be set to default low or default high in the hardware tab to be included during auto-discover.

Changes on the gpio port are sent from ESPEasy to

Code: Select all

homie/%unitName%/SYSTEM/gpio#
Please use true/false instead of 1/0 as defined in the convention!

Re: mqtt cant receive gpio command

Posted: 17 Sep 2019, 15:36
by TD-er
Is that something that has to be changed in the software or in the documentation? (I'm not the author of the Homie controller)

Re: mqtt cant receive gpio command

Posted: 17 Sep 2019, 17:06
by HarpieC
I am ;)

Nothing to be changed. If somebody uses the homie controller they have to stick with the homie convention. As described. It can do the Job and I use it in several devices - even without a homie compatible controller. You just have to stay with the naming convention like starting with home/ and the prefix /set for altering parameters.

I was wondering why you mentioned C014 because above the Mqtt-import plugin was mentioned. I just wanted to make sure to point out the difference. Sorry for the misunderstanding.
Chris.

BTW the ? Button on the configuration page is not referring to the correct documentation page ... have to find out why.

Re: mqtt cant receive gpio command

Posted: 17 Sep 2019, 17:11
by HarpieC
And he couldn’t use C014 because it is in the develop build and not in the normal one (I think)

Re: mqtt cant receive gpio command

Posted: 13 May 2020, 08:22
by gregoinc
Feels like I am forever asking questions on old threads... apology if this has been answered elsewhere.

My situation... I have several NodeMCU units running Mega and communicating with Mosquito MQTT, with Node Red capturing information and forwarding to Blynk app. A one way information transfer.

I want to make it a two way, but for the life of me I cannot work out how to have Node Red send a MQTT message to tell one of my NodeMCU units to start the air conditioner. Here's my rules code...

On StartHP Do
If [counter#status]=0
heatpumpir,daikin,1,3,0,24,4,2
TaskValueSet 4,1,1
EndIf
EndOn

As you can see I have an event that transmits the IR commands to my air conditioner. What I would like to do is have Node Red send a message via MQTT to the NodeMCU to execute the StartHP event i.e. turn on the AC.

I read this thread and others, but am still in the dark about where to put the topic info and which string to use... Here's what I have been trying to use:

I create an inject in Node Red with the topic as the payload... ESP_EASY/event/StartHP
espeasyevent.jpg
espeasyevent.jpg (17.69 KiB) Viewed 12739 times
Node Red gave me back the error "Invalid topic specified" which tells me I am not entering the data in the right format? Any advice greatly appreciated, I have no doubt it will be my lack of knowledge getting in the way.

Thanks, Grego

Re: mqtt cant receive gpio command

Posted: 15 May 2020, 05:26
by gregoinc
In an effort to tie this off, I managed to find a solution... which once found appeared embarrassingly simple. In an effort to share information for those of you that are stuck like me here is what I found.

Here is the NodeRed inject node I created to simulate a command to start the air conditioner...
NodeRedStartHPInject.jpg
NodeRedStartHPInject.jpg (31.66 KiB) Viewed 12679 times
You will see the Payload contains the word "event" and the command to "StartHP" which starts the air conditioner. The Topic line contains the ESPEasy hostname (GregoInc1) followed by a forward slash and "cmd" which signifies the use of a command.

And here is the NodeRed MQTT out node, which as you will see is really simple.
NodeRedMQTTOutNode.jpg
NodeRedMQTTOutNode.jpg (37.81 KiB) Viewed 12679 times
Hope this helps.