MQTT gpio switching info

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
ambassadoro
Normal user
Posts: 40
Joined: 17 Nov 2015, 15:58

MQTT gpio switching info

#1 Post by ambassadoro » 12 Feb 2016, 09:53

Hello,

there was the question how to drive a GPIO via MQTT:

Code: Select all

mosquitto_pub -d -t /esp3/GPIO/14 -m 0
The esp3 is the subscription-topic from the advanced section of the esp-configuration webpage: /%sysname%/#
Then the GPIO keyword and the number of the gpio that you want to switch. -m 0 is the payload. So this sets the gpio14 to 0. -m 1 makes it high.

This example works when you are on a local mosquitto server. Otherwise it needs username and password.

Here an example for a simple blinker with a 2 relais card (relais connected via transistors to 12 & 14):

Code: Select all

while true; do 
mosquitto_pub -q 1 -d -t /esp3/GPIO/14 -m "0";
mosquitto_pub -q 1 -d -t /esp3/GPIO/12 -m "1";
sleep 1;
mosquitto_pub -q 1 -d -t /esp3/GPIO/14 -m "1";
mosquitto_pub -q 1 -d -t /esp3/GPIO/12 -m "0";
sleep 1; done
When you have a real good power supply, this should run forever.

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

Re: MQTT gpio switching info

#2 Post by tozett » 12 Feb 2016, 11:29

cool.
thanks a lot for the hint. i will try this..

maybe youve done similar with MQTT on linux and start a shell command through payload?
:roll:

edit: i found this... look good to me (even python instead of bash, but on linux no prob ...)
https://github.com/jpmens/mqtt-launcher

ambassadoro
Normal user
Posts: 40
Joined: 17 Nov 2015, 15:58

Re: MQTT gpio switching info

#3 Post by ambassadoro » 12 Feb 2016, 12:24

With the shell-command this is useful for test purpose. For more automation I am playing around with Home Assistant. It supports mqtt very well and looks much more promising to me than fhem.
Have fun :-)

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

Re: MQTT gpio switching info

#4 Post by tozett » 12 Feb 2016, 12:36

i will try this:
https://home-assistant.io/components/shell_command/
:D
and must define shell-commands to send from MQTT/Homeassistant.io with groupswrite(eibd) to KNX..
:mrgreen:
coool, thanx

edit: set up a debian8 vmware, now running homeassistant..looks promising..
:mrgreen:

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

Re: MQTT gpio switching info

#5 Post by tozett » 14 Feb 2016, 21:13

ambassadoro wrote:... subscription-topic from the advanced section of the esp-configuration webpage: /%sysname%/#
... -m 0 is the payload. So this sets the gpio14 to 0. -m 1 makes it high.
hi,
i dont see realy clear if i can also send PWM level to GPIOs as a payload?
what payload-commands are possible?
same as http requests?
did not find the right place in the code,
but that must be me 8-) :oops:
a hint may help`....

edit: found something from the devs about PWM here:
http://www.esp8266.nu/forum/viewtopic.p ... 3601#p3601

wutu
Normal user
Posts: 35
Joined: 05 Feb 2016, 07:33

Re: MQTT gpio switching info

#6 Post by wutu » 26 Feb 2016, 00:49

Yes, it is possible.
I use:
esp GPIO:
<systopic>/pwm/<pin> with payload: 0-254
pca9685 GPIO
<systopic>/pcapwm/<pin> with payload: 0-4094
Last edited by wutu on 02 May 2016, 12:48, edited 1 time in total.

HarpieC
Normal user
Posts: 19
Joined: 20 Mar 2016, 20:33

Re: MQTT gpio switching info

#7 Post by HarpieC » 20 Apr 2016, 12:02

another question:

is there a way to send a pulse of some milliseconds to the gpio pin via MQTT too. I try to avoid http and have all communication via MQTT because it is easier to debug via MQTT spy or MQTT.fx

It's working via http:

http://<ESP IP address>/control?cmd=Pulse,<pin>,<state>,<duration>

Thank you for your support.
Chris

adibacco
Normal user
Posts: 2
Joined: 18 Dec 2016, 09:50

Re: MQTT gpio switching info

#8 Post by adibacco » 18 Dec 2016, 09:52

Looking into the code or at this page http://www.letscontrolit.com/wiki/index ... _Reference you will find that you can publish a message like pulse,12,1,250 to topic cmd

Post Reply

Who is online

Users browsing this forum: No registered users and 15 guests