Help a noob , basic MQTT & switch setup (SOLVED)

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
kiwijunglist
New user
Posts: 6
Joined: 14 Jun 2018, 01:26

Help a noob , basic MQTT & switch setup (SOLVED)

#1 Post by kiwijunglist » 14 Jun 2018, 01:36

Hi

I have a nodemcu esp12n flashed with build 120 of espeasy.
It is connected to my wifi and is connecting to my mqtt broker (i use hassio).
I'm not sure if the device is functioning correctly...
I have been unable to figure out the default mqtt topics, as every guide I read has different mqtt topics for commands etc and I have tried them all and I don't know where my problem lies.
I've been using mqtt dash to test by subscribing and publishing to topics but I can't see any activity and the commands don't work.

I have the following relevant settings:
Config -> Main Settings -> Name: esp01
Config -> Main Settings -> Protocol: OpenHAB MQTT
Advanced Settings -> Subscribe template: /%sysname%/#
Advanced Settings -> Publish template: /%sysname%/%tskname%/%valname%
Hardware Settings -> Pin mode 16: Default

And under devices:
Device -> Task 1
Device: switch input
Name: led
IDX / Var: 250
1st GPIO: GPIO-16
Pull up: Yes
Inversed: No
Switch type: Switch
Switch button type: Normal Switch
Send boot state: No
Send data: Yes
Optional Settings -> Value Name 1: switch

Should the above config publish a value to my broker if i short GND - D0 (GPIO-16)?
What topic should it publish to?

Also: I don't know of any android mqtt clients that can subscribe to */*/* that would be more useful for testing.

Thanks
Kiwi
Last edited by kiwijunglist on 14 Jun 2018, 04:13, edited 2 times in total.

kiwijunglist
New user
Posts: 6
Joined: 14 Jun 2018, 01:26

Re: Help a noob , basic MQTT & switch setup

#2 Post by kiwijunglist » 14 Jun 2018, 01:45

I found an answer to my question: MQTT-Spy (Java App) can subscribe and spy on all topics.

When I short GPIO 16 to GND I get
- Topic: esp01/led/switch
- Content: 1

and when it's unshorted I get
- Topic: esp01/led/switch
- Content: 0

kiwijunglist
New user
Posts: 6
Joined: 14 Jun 2018, 01:26

Re: Help a noob , basic MQTT & switch setup

#3 Post by kiwijunglist » 14 Jun 2018, 01:56

If I want to connect an LED to the nodemcu do I wire it up like follows:

GPIO16 -> Resister -> LED -> GND

What are the correct settings?:

Config -> Main Settings -> Name: esp01
Advanced Settings -> Subscribe template: /%sysname%/#
Advanced Settings -> Publish template: /%sysname%/%tskname%/%valname%
Hardware Settings -> Pin mode 16: ?? Output Low ??

And under devices:
Device -> Task 1
Device: switch input
Name: led
IDX / Var: 250
1st GPIO: GPIO-16
Pull up: No
Inversed: No
Switch type: Switch
Switch button type: Normal Switch
Send boot state: No
Send data: Yes
Optional Settings -> Value Name 1: switch

If so what is the mqtt topic and content for controlling the LED?
I tried topic: "esp01/cmd" & content: "gpio,16,1" but it didn't work.

kiwijunglist
New user
Posts: 6
Joined: 14 Jun 2018, 01:26

Re: Help a noob , basic MQTT & switch setup

#4 Post by kiwijunglist » 14 Jun 2018, 02:29

http://192.168.178.100/control?cmd=GPIO,16,1
http://192.168.178.100/control?cmd=GPIO,16,0

{
"log": "GPIO 16 Set to 1",
"plugin": 1,
"pin": 16,
"mode": "output",
"state": 1
}

Is working to control the LED, but I can't get the MQTT to control it.

Protocol: OpenHAB MQTT
Device: esp01
Subscribe template: /%sysname%/#
Publish template: /%sysname%/%tskname%/%valname%
Device: switch input
Name: led
IDX/Var: 250
Value name: switch

Have tried [topic -> command]
esp01/cmd -> gpio,16,1
esp01/cmd -> 1
esp01 -> gpio,16,1
esp01/cmd/led/switch -> 1
esp01/led/switch -> 1
esp01/cmd/led/switch -> gpio,16,1
esp01/led/switch -> gpio,16,1

Unfortunately there is no documentation that I can find that correctly states mqtt commands for openhab mqtt protocol.

kiwijunglist
New user
Posts: 6
Joined: 14 Jun 2018, 01:26

Re: Help a noob , basic MQTT & switch setup

#5 Post by kiwijunglist » 14 Jun 2018, 03:53

Solved:

Topic is "/esp01/gpio/16"
Not "esp01/gpio/16"

Notice the extra / at the start.

Post Reply

Who is online

Users browsing this forum: No registered users and 21 guests