cannot connect to MQTT broker.

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
espfrm883
Normal user
Posts: 30
Joined: 28 Sep 2015, 00:07

cannot connect to MQTT broker.

#1 Post by espfrm883 » 28 Sep 2015, 00:36

Hello all,

I need some fresh eyes to help troubleshoot my Problem. The ESP indicates that it cannot connect to the broker. I've tested Mosquitto with the following commands as well as a simple andriod app (MyMQTT).

Terminal 1
mosquitto_sub -v -t 'test/topic'

Terminal 2
mosquitto_pub -t 'test/topic' -m 'helloWorld'

This was a successful test. However don't know how to make sure that OpenHAB is receiving or pushing the commands. What topic in the MyMQTT should I put in to the phone to test openHAB?

I'm open to any other suggestions as well.

thank you to the esp8266nu team for a great project. :D

################################# Generic ESP8266 ######################################
System Info
Uptime: 20 minutes
IP: 192.168.2.189
GW: 192.168.2.1
Build: 20
Unit: 16
STA MAC: 18:fe:34:fe:60:5d
AP MAC: 1a:fe:34:fe:60:5d
ESP Chip ID: 16670813
ESP Flash Size: 524288
Free Mem: 25448

Main Settings
Name: demo
Admin Password: pass
SSID: MYSSID
WPA Key: MYPASSWD
WPA AP Mode Key: configesp
Unit nr: 16
Protocol: OpenHAB MQTT
Controller IP: 192.168.2.125
Controller Port: 1883
Sensor Delay: 60
Message Delay (ms): 1000
Sleep Mode: 0
Optional Settings 0.0.0.0
Fixed IP Octet: 0.0.0.0
ESP IP: 0.0.0.0
ESP GW: 0.0.0.0
ESP Subnet: 0.0.0.0
Syslog IP: 0.0.0.0
Syslog Level: 0
UDP port: 0
Serial log Level: 3
Web log Level: 3
Baud Rate: 115200

################################# OpenHAB MQTT Transport ######################################
#
# Define your MQTT broker connections here for use in the MQTT Binding or MQTT
# Persistence bundles. Replace <broker> with a id you choose.
#

# URL to the MQTT broker, e.g. tcp://localhost:1883 or ssl://localhost:8883
mqtt:mymosquitto.url=tcp://localhost:1883

# Optional. Client id (max 23 chars) to use when connecting to the broker.
# If not provided a default one is generated.
mqtt:mymosquitto.clientId=openHAB


################################# OpenHAB Items ######################################
Switch MQTTLED (test) {mqtt=">[mymosquitto:/demo/gpio/2:command:ON:1],>[mymosquitto:/demo/gpio/2:command:OFF:0]"}

espfrm883
Normal user
Posts: 30
Joined: 28 Sep 2015, 00:07

Re: cannot connect to MQTT broker.

#2 Post by espfrm883 » 29 Sep 2015, 04:19

I have confirmed the issue is with ESPEasy after plugging in my old Mosquitto gateway and RFM69HW.

- How can I turn on debug while watching the serial monitor?
- I'll build out my ESP826612 this weekend to see if the problem is limited to the generic ESP.

side note: I've found out that my OpenHab on Raspberry Pi loads and runs better by limiting addons to the one actually used.

espfrm883
Normal user
Posts: 30
Joined: 28 Sep 2015, 00:07

Re: cannot connect to MQTT broker.

#3 Post by espfrm883 » 30 Sep 2015, 03:49

Ok. Here's the log. I've attempted this with an ESP826612 as well as a generic.

HTTP : Tools request :
HTTP : Webrequest : reboot
: Rebooting...

ets Jan 8 2013,rst cause:4, boot mode:(3,3)

wdt reset
load 0x4010f000, len 1264, room 16
tail 0
chksum 0x42
csum 0x42
~ld
ªU
INIT : Booting Build nr:20
scandone
del if0
usl
sul 0 0
mode : softAP(1a:fe:34:a6:76:90)
add if1
dhcp server start:(ip:192.168.4.1,mask:255.255.255.0,gw:192.168.4.1)
bcn 100
bcn 0
del if1
usl
sul 0 0
mode : sta(18:fe:34:a6:76:90)
add if0
WIFI : Connecting...
f 0, .
.
.
.
scandone
state: 0 -> 2 (b0)
.
state: 2 -> 3 (0)
state: 3 -> 5 (10)
add 0
aid 8
pm open phy_2,type:2 0 0
cnt

connected with MYNET, channel 2
dhcp client start...
.
.
.
ip:192.168.2.198,mask:255.255.255.0,gw:192.168.2.1
.
INIT : I2C
MQTT : Failed to connected to broker
MQTT : Failed to connected to broker
INIT : Boot OK
Boot
0
normal boot

Martinus

Re: cannot connect to MQTT broker.

#4 Post by Martinus » 30 Sep 2015, 15:08

When the ESP got it's IP, can you ping the device on that IP?
Do you have some generic webserver running so you could try if the ESP connects through HTTP to something?
Use debug level 3 and it should show something like this:

Code: Select all

HTTP : connecting to 192.168.0.40
HTTP : closing connection
(I have a plain webserver running on 192.168.0.40 and at least it will connect to it even though this is not Domoticz or some other HA solution)

Then we know at least that communication is working and the issue must be something within MQTT connection.

espfrm883
Normal user
Posts: 30
Joined: 28 Sep 2015, 00:07

Re: cannot connect to MQTT broker.

#5 Post by espfrm883 » 30 Sep 2015, 22:54

Thank you for the reply.. I still am having the same problem.

What do you think of the issue being a clentname problem?

My broker is configured to all the defaults which allow anonymous and I don't think that I have a client name configured on any of the other clients (Andriod and Arduino).

The ESP has an IP address. Here's the System Info.
System Info
Uptime: 0 minutes
IP: 192.168.2.198
GW: 192.168.2.1
Build: 18
Unit: 16
STA MAC: 18:fe:34:a6:76:90
AP MAC: 1a:fe:34:a6:76:90
ESP Chip ID: 10909328
ESP Flash Size: 4194304
Free Mem: 26232
I can ping the ESP from the MQTT server
PING 192.168.2.198 (192.168.2.198) 56(84) bytes of data.
64 bytes from 192.168.2.198: icmp_req=1 ttl=255 time=26.2 ms
64 bytes from 192.168.2.198: icmp_req=2 ttl=255 time=49.2 ms
64 bytes from 192.168.2.198: icmp_req=3 ttl=255 time=2.01 ms
I still have a problem connecting to the broker. Even though other devices can including my phone and an Arduino Gateway.
I've updated the logging to level 3 and this is all I get.
INIT : Booting Build nr:18
INIT : I2C
WIFI : Connecting...
.
.
.
.
.
.
.
.
.
MQTT : Failed to connected to broker
MQTT : Failed to connected to broker
INIT : Boot OK
Boot
WD : Uptime 0 ConnectFailures 0 FreeMem 26232

espfrm883
Normal user
Posts: 30
Joined: 28 Sep 2015, 00:07

Re: cannot connect to MQTT broker.

#6 Post by espfrm883 » 01 Oct 2015, 05:08

Solved BABY! :D

The issue is with the default Mosquitto repository incompatible with ESP. Credit goes to this post
http://mosquitto.org/2013/01/mosquitto- ... epository/

I uninstalled the existing broker.

Code: Select all

sudo /etc/init.d/mosquitto stop 
sudo apt-get --purge remove mosquitto mosquitto-clients python-mosquitto
To use the new repository you should first import the repository package signing key:

Code: Select all

wget http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key
sudo apt-key add mosquitto-repo.gpg.key
Then make the repository available to apt:

Code: Select all

cd /etc/apt/sources.list.d/
Then one of the following, depending on which version of debian you are using: (I used wheezy)

Code: Select all

sudo wget http://repo.mosquitto.org/debian/mosquitto-wheezy.list
sudo wget http://repo.mosquitto.org/debian/mosquitto-jessie.list

Then update apt information:

Code: Select all

apt-get update
And discover what mosquitto packages are available:

Code: Select all

apt-cache search mosquitto
Or just install:

Code: Select all

apt-get install mosquitto
And the sweet result:
INIT : Booting Build nr:18
INIT : I2C
WIFI : Connecting...
.
.
.
.
.
.
.
MQTT : Connected to broker
INIT : Boot OK
Boot
gpio,2,0
gpio,2,1
gpio,2,0

MarkIngle
Normal user
Posts: 47
Joined: 10 Feb 2016, 05:06

Re: cannot connect to MQTT broker.

#7 Post by MarkIngle » 13 Feb 2016, 06:21

Thanks for posting this! Now if I can just figure it out for Windows 7!

Gorgo
Normal user
Posts: 20
Joined: 14 Feb 2016, 11:40

Re: cannot connect to MQTT broker.

#8 Post by Gorgo » 09 Mar 2016, 16:22

That's a bit weird for me. I've reinstalled mosquitto following the sample (I've picked Jessie), and after listed the packages available I chose just install.

After it's been done checked its status:

Code: Select all

pi@arcpi:~ $ sudo /etc/init.d/mosquitto status
● mosquitto.service - LSB: mosquitto MQTT v3.1 message broker
   Loaded: loaded (/etc/init.d/mosquitto)
   Active: active (running) since Wed 2016-03-09 16:10:45 CET; 2min 59s ago
  Process: 392 ExecStart=/etc/init.d/mosquitto start (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/mosquitto.service
           └─402 /usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf

Mar 09 16:10:45 arcpi mosquitto[392]: Starting network daemon:: mosquitto.
Mar 09 16:10:45 arcpi systemd[1]: Started LSB: mosquitto MQTT v3.1 message broker.
It says 1.4.8 v3.1

Should I give a try to Wheezy version?

Gorgo
Normal user
Posts: 20
Joined: 14 Feb 2016, 11:40

Re: cannot connect to MQTT broker.

#9 Post by Gorgo » 09 Mar 2016, 16:49

Tried, but I see no difference. ESP is still unable to connect broker.
I find this interesting:

Code: Select all

● mosquitto.service - LSB: mosquitto MQTT v3.1 message broker
   Loaded: loaded (/etc/init.d/mosquitto)
   Active: active (running) since Wed 2016-03-09 16:40:37 CET; 1min 57s ago
  Process: 395 ExecStart=/etc/init.d/mosquitto start (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/mosquitto.service
           └─413 /usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf

Mar 09 16:40:37 arcpi mosquitto[395]: Starting network daemon:: mosquitto.
Mar 09 16:40:37 arcpi systemd[1]: Started LSB: mosquitto MQTT v3.1 message broker.
pi@arcpi:~ $ mosquitto
1457538339: mosquitto version 1.4.8 (build date Sun, 14 Feb 2016 15:06:55 +0000) starting
1457538339: Using default config.
1457538339: Opening ipv4 listen socket on port 1883.
1457538339: Error: Address already in use
Still 3.1 and that error message in the last line where this should be: "Opening ipv6 listen socket on port 1883."
Possibly that is wrong here but got no idea how to figure it out.
Any help appreciated.

espfrm883
Normal user
Posts: 30
Joined: 28 Sep 2015, 00:07

Re: cannot connect to MQTT broker.

#10 Post by espfrm883 » 09 Mar 2016, 16:57

Looks like your other mosquitto broker may be running.

Gorgo
Normal user
Posts: 20
Joined: 14 Feb 2016, 11:40

Re: cannot connect to MQTT broker.

#11 Post by Gorgo » 09 Mar 2016, 17:13

As far as I know there is no other broker.

Gorgo
Normal user
Posts: 20
Joined: 14 Feb 2016, 11:40

Re: cannot connect to MQTT broker.

#12 Post by Gorgo » 09 Mar 2016, 18:01

OK, after Mosquitto already running typing "mosquitto" to the terminal window tries to start it again, maybe that's the reason.
But still unable to connect to broker.

I read somewhere that there is a syntax issue with "/%sysname%..." -that maybe the "/" is not needed at the beginning... I just can't find it anymore.

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

Re: cannot connect to MQTT broker.

#13 Post by tozett » 10 Mar 2016, 07:34

check running tasks with "ps" or "ps -xa" to see how many mosquittos are running...
than check connection with mosquitto_sub client...

show what the findings are..

Gorgo
Normal user
Posts: 20
Joined: 14 Feb 2016, 11:40

Re: cannot connect to MQTT broker.

#14 Post by Gorgo » 10 Mar 2016, 13:06

Thank you.

Erased then reinstalled EspEasy, after reboot I get this on serial:
INIT : Booting Build nr:78
WIFI : Connecting... 1
WIFI : Connected!
INIT : I2C
MQTT : Failed to connected to broker
MQTT : Connected to broker
Subscribed to: unit1/#
INIT : Boot OK
INIT : Cold Boot
WD : Uptime 0 ConnectFailures 0 FreeMem 26176
WD : Uptime 1 ConnectFailures 0 FreeMem 26144
WD : Uptime 1 ConnectFailures 0 FreeMem 25952
WD : Uptime 2 ConnectFailures 0 FreeMem 25824
WD : Uptime 2 ConnectFailures 0 FreeMem 25240
WD : Uptime 3 ConnectFailures 0 FreeMem 25760
WD : Uptime 3 ConnectFailures 0 FreeMem 25760
WD : Uptime 4 ConnectFailures 0 FreeMem 25712
WD : Uptime 4 ConnectFailures 0 FreeMem 25712
WD : Uptime 5 ConnectFailures 0 FreeMem 25648
WD : Uptime 5 ConnectFailures 0 FreeMem 25632
WD : Uptime 6 ConnectFailures 0 FreeMem 25632
Pi through terminal:
pi@arcpi:~ $ ps -xa
PID TTY STAT TIME COMMAND
1 ? Ss 0:08 /sbin/init
2 ? S 0:00 [kthreadd]
3 ? S 0:04 [ksoftirqd/0]
5 ? S< 0:00 [kworker/0:0H]
7 ? S 0:20 [rcu_sched]
8 ? S 0:00 [rcu_bh]
9 ? S 0:00 [migration/0]
10 ? S 0:00 [migration/1]
11 ? S 0:00 [ksoftirqd/1]
13 ? S< 0:00 [kworker/1:0H]
14 ? S 0:00 [migration/2]
15 ? S 0:00 [ksoftirqd/2]
17 ? S< 0:00 [kworker/2:0H]
18 ? S 0:00 [migration/3]
19 ? S 0:00 [ksoftirqd/3]
21 ? S< 0:00 [kworker/3:0H]
22 ? S< 0:00 [khelper]
23 ? S 0:00 [kdevtmpfs]
24 ? S< 0:00 [netns]
25 ? S< 0:00 [perf]
26 ? S 0:00 [khungtaskd]
27 ? S< 0:00 [writeback]
28 ? S< 0:00 [crypto]
29 ? S< 0:00 [bioset]
30 ? S< 0:00 [kblockd]
32 ? S< 0:00 [rpciod]
34 ? S 0:00 [kswapd0]
35 ? S 0:00 [fsnotify_mark]
36 ? S< 0:00 [nfsiod]
42 ? S< 0:00 [kthrotld]
44 ? S< 0:00 [VCHIQ-0]
45 ? S< 0:00 [VCHIQr-0]
46 ? S< 0:00 [VCHIQs-0]
47 ? S< 0:00 [iscsi_eh]
48 ? S< 0:00 [dwc_otg]
49 ? S< 0:00 [DWC Notificatio]
51 ? S 0:28 [mmcqd/0]
52 ? S 0:00 [VCHIQka-0]
53 ? S< 0:00 [SMIO]
54 ? S< 0:00 [deferwq]
55 ? S 0:10 [jbd2/mmcblk0p2-]
56 ? S< 0:00 [ext4-rsv-conver]
59 ? S< 0:00 [ipv6_addrconf]
107 ? Ss 0:02 /lib/systemd/systemd-journald
108 ? Ss 0:00 /lib/systemd/systemd-udevd
187 ? S 0:00 [spi0]
366 ? S 0:52 [RTW_CMD_THREAD]
381 ? Ss 0:00 /usr/sbin/cron -f
384 ? Ss 0:00 /lib/systemd/systemd-logind
395 ? Ss 0:00 avahi-daemon: running [arcpi.local]
397 ? Ss 0:00 /usr/bin/dbus-daemon --system --address=systemd: --nofork --nopidfile
413 ? S 0:42 /usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf
418 ? Ss 0:00 /usr/sbin/thd --daemon --triggers /etc/triggerhappy/triggers.d/ --soc
422 ? S< 0:00 [cfg80211]
426 ? Ss 0:00 /sbin/dhcpcd -q -b
433 ? S 0:00 avahi-daemon: chroot helper
437 ? Ss 0:05 /sbin/wpa_supplicant -s -B -P /run/wpa_supplicant.wlan0.pid -i wlan0
477 ? Ssl 0:00 /usr/sbin/rsyslogd -n
483 ? S< 0:00 [kworker/3:1H]
509 ? Sl 20:58 /usr/bin/java -Djna.boot.library.path=/usr/lib/jni -Dgnu.io.rxtx.Seri
514 ? Ss 0:00 /usr/sbin/sshd -D
527 ? Ssl 0:00 /usr/sbin/lightdm
566 ? Ss 0:10 /usr/sbin/ntpd -p /var/run/ntpd.pid -g -u 106:111
614 tty1 Ss 0:00 /bin/login -f
615 ? Ss+ 0:00 /sbin/agetty --keep-baud 115200 38400 9600 ttyAMA0 vt102
635 tty7 Ssl+ 0:34 /usr/bin/X :0 -seat seat0 -auth /var/run/lightdm/root/:0 -nolisten tc
689 ? Sl 0:00 lightdm --session-child 13 16
700 ? Ss 0:00 /lib/systemd/systemd --user
705 ? S 0:00 (sd-pam)
709 ? Ssl 0:00 /usr/bin/lxsession -s LXDE-pi -e LXDE
727 ? S< 0:00 [kworker/1:1H]
728 ? Ss 0:15 /usr/sbin/nmbd -D
746 ? Ss 0:00 /usr/bin/ssh-agent /usr/bin/dbus-launch --exit-with-session x-session
749 ? S 0:00 /usr/bin/dbus-launch --exit-with-session x-session-manager
750 ? Ss 0:00 /usr/bin/dbus-daemon --fork --print-pid 5 --print-address 7 --session
760 ? Sl 0:00 /usr/lib/gvfs/gvfsd
766 ? S< 0:00 [kworker/2:1H]
767 ? S< 0:00 [kworker/0:1H]
775 tty1 S+ 0:00 -bash
777 ? Sl 0:00 /usr/lib/gvfs/gvfsd-fuse /run/user/1000/gvfs -f -o big_writes
787 ? Ss 0:05 /usr/sbin/smbd -D
832 ? S 0:00 /usr/sbin/smbd -D
843 ? S 0:01 openbox --config-file /home/pi/.config/openbox/lxde-pi-rc.xml
846 ? Sl 0:00 lxpolkit
848 ? Sl 2:44 lxpanel --profile LXDE-pi
849 ? Sl 0:00 pcmanfm --desktop --profile LXDE-pi
858 ? Ss 0:00 /usr/bin/ssh-agent -s
860 ? Ssl 0:00 /usr/lib/policykit-1/polkitd --no-debug
869 ? Sl 0:00 /usr/lib/gvfs/gvfs-udisks2-volume-monitor
871 ? Ssl 0:00 /usr/lib/udisks2/udisksd --no-debug
883 ? Sl 0:00 /usr/lib/gvfs/gvfs-goa-volume-monitor
887 ? Sl 0:00 /usr/lib/gvfs/gvfs-afc-volume-monitor
892 ? Sl 0:00 /usr/lib/gvfs/gvfs-gphoto2-volume-monitor
896 ? Sl 0:00 /usr/lib/gvfs/gvfs-mtp-volume-monitor
911 ? Sl 0:00 /usr/lib/gvfs/gvfsd-trash --spawner :1.1 /org/gtk/gvfs/exec_spaw/0
912 ? Ssl 0:00 /usr/lib/menu-cache/menu-cached /tmp/.menu-cached-:0-pi
10798 ? S 0:00 [kworker/u8:1]
16470 ? S 0:01 [kworker/u8:0]
17887 ? S 0:01 [kworker/1:2]
18225 ? S 0:00 [kworker/2:0]
18882 ? S 0:00 [kworker/3:2]
18908 ? S 0:00 [kworker/2:1]
18926 ? S 0:00 [kworker/1:1]
18938 ? S 0:00 [kworker/0:2]
18967 ? S 0:00 [kworker/3:1]
19014 ? S 0:00 [kworker/0:1]
19078 ? S 0:00 [kworker/2:2]
19094 ? Ss 0:00 sshd: pi [priv]
19096 ? S 0:00 [kworker/0:0]
19103 ? Ss 0:00 sshd: pi [priv]
19106 ? S 0:00 sshd: pi@pts/0
19118 ? S 0:00 sshd: pi@notty
19121 ? Ss 0:00 /usr/lib/openssh/sftp-server
19122 pts/0 Ss 0:00 -bash
19162 pts/0 R+ 0:00 ps -xa
pi@arcpi:~ $ mosquitto_sub -d -t unit1/#
Client mosqsub/19358-arcpi sending CONNECT
Client mosqsub/19358-arcpi received CONNACK
Client mosqsub/19358-arcpi sending SUBSCRIBE (Mid: 1, Topic: unit1/#, QoS: 0)
Client mosqsub/19358-arcpi received SUBACK
Subscribed (mid: 1): 0
Client mosqsub/19358-arcpi sending PINGREQ
Client mosqsub/19358-arcpi received PINGRESP
Client mosqsub/19358-arcpi sending PINGREQ
Client mosqsub/19358-arcpi received PINGRESP
Client mosqsub/19358-arcpi sending PINGREQ
Client mosqsub/19358-arcpi received PINGRESP
Client mosqsub/19358-arcpi sending PINGREQ
Client mosqsub/19358-arcpi received PINGRESP
It seems almost OK now, isn't it?
Actually I can't define the lines like "WD : Uptime 0 ConnectFailures 0 FreeMem 26176".

Gorgo
Normal user
Posts: 20
Joined: 14 Feb 2016, 11:40

Re: cannot connect to MQTT broker.

#15 Post by Gorgo » 10 Mar 2016, 14:20

Perfect.
Now I can turn GPIOs on and off through the broker.
How should the responses (state change confirmation) appear from the ESP on the broker? Later I want to drive my nodes via OpenHab, so I'll need to have status reports to keep it sane...

Subscribed to the topic unit1/# -and when I manually publish on it I see this:

Code: Select all

Client mosqsub/19358-arcpi received PUBLISH (d0, q0, r0, m0, 'unit1/gpio/2', ... (1 bytes))
0
Client mosqsub/19358-arcpi received PUBLISH (d0, q0, r0, m0, 'unit1/gpio/2', ... (1 bytes))
0
Client mosqsub/19358-arcpi received PUBLISH (d0, q0, r0, m0, 'unit1/gpio/2', ... (1 bytes))
1
Client mosqsub/19358-arcpi sending PINGREQ
Client mosqsub/19358-arcpi received PINGRESP
but nothing from the ESP.

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

Re: cannot connect to MQTT broker.

#16 Post by tozett » 10 Mar 2016, 14:37

do you enabled sending for the GPIO?
may check here some more hints for this:
http://www.esp8266.nu/forum/viewtopic.p ... e%25#p4886

Gorgo
Normal user
Posts: 20
Joined: 14 Feb 2016, 11:40

Re: cannot connect to MQTT broker.

#17 Post by Gorgo » 10 Mar 2016, 14:59

Thank you, already read that.

SUB template:%sysname%/#
PUB template: %sysname%/%tskname%/%valname%

Removed the first "/"
Don’t use a leading forward slash

It is allowed to use a leading forward slash in MQTT, for example /myhome/groundfloor/livingroom. But that introduces a unnecessary topic level with a zero character at the front. That should be avoided, because it doesn’t provide any benefit and often leads to confusion.
http://www.hivemq.com/blog/mqtt-essenti ... -practices

My question is to be exact: I should see the ESP's response on the mosquitto_sub terminal under "unit1/#" topic, right?

Thank you for your time and effort.

jackwan1
Normal user
Posts: 21
Joined: 11 Apr 2017, 05:42

Re: cannot connect to MQTT broker.

#18 Post by jackwan1 » 12 Apr 2017, 00:11

Hi all,

I am new here and needs all the help.

I am using Ubuntu 16.10 default mosquitto installation on a local host, the MQTT clients can log on to it without any problem.
Flashed sonoff device with R147 ESPeasy
This thread is of great help, so I set in the "advanced" tool section of the ESP easy (removed the first / in each)

subscribe template: %sysname%/
publish template: %sysname%/%tskname%/%valname%

and the subscription topic of : sonoff1/# is working, I am getting system info from subscription.
However the publish part become a problem
I have tried : sonoff1/gpio/12 or sonoff1/gpio/0 or sonoff1/lightswitch/Switch with no success the lightswitch and Switch are the task name and value in the Device configuration.

Before the above, I have the "/" in front of the template and "/" in front of subscribe or publish that does not work either.

jackwan1
Normal user
Posts: 21
Joined: 11 Apr 2017, 05:42

Re: cannot connect to MQTT broker.

#19 Post by jackwan1 » 12 Apr 2017, 00:24

Ok Ok its all good

it turned out that while subscribe you cannot have a / , publish you need a /
it is weird

So the templates

subscribe : %sysname%/
publish : %sysname%/%tskname%/%valname%

But the clients need

subscribe: sonoff1/#
publish: /sonoff1/gpio/0 or 12

minor difference, but major headache.

In the commercial broker such as cloudmqtt and mqtt-dashboard

the subscribe template must be /%sysname%/
the publish template must be /%sysname%/%tskname%/%valname%

and the clients call must have / in front

jackwan1
Normal user
Posts: 21
Joined: 11 Apr 2017, 05:42

Re: cannot connect to MQTT broker.

#20 Post by jackwan1 » 12 Apr 2017, 06:35

Ok, now after reboot the conventions seem corrected themselves

So the templates

subscribe : %sysname%/
publish : %sysname%/%tskname%/%valname%

Then the clients need

subscribe: sonoff1/#
publish: sonoff1/gpio/0 or 12

no more / in the publish phase

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

Re: cannot connect to MQTT broker.

#21 Post by grovkillen » 12 Apr 2017, 06:55

I think many cloud based brokers use a unique identifier for the clients, thus the need to have a leading slash (which isn't leading really). I.e.

123e4567-e89b-12d3-a456-42665544000/sonoff1/gpio/0
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:

Post Reply

Who is online

Users browsing this forum: No registered users and 38 guests