2

I use paho mqttws31.js (http://www.eclipse.org/paho/clients/js/) for receiving mqtt messages via websockets in a web-app. On pcs with different browsers(chromeium, firefox ...) everything works totally smooth without any errors. But when I use exactly the same source-code on mobile devices, like tablets or smartphones I don't receive retained messages. I subscribe for some retained topic inside of the onSuccess callback when I connect to the broker. But I don't receive the retained message most of the time. As mentioned this only happens on mobile devices.

Thanks in advance.

dan kutz
  • 107
  • 1
  • 12
  • Similar question here: http://stackoverflow.com/questions/25176643/android-paho-mqtt-client-does-not-receive-messages-once-network-connectivity-c – Dom Sep 11 '14 at 19:12
  • no this refers to java and not javascript(big difference) + as mentioned twice it works in non-mobile browsers. – dan kutz Sep 11 '14 at 19:37
  • I've had a look on mosquitto and noticed, that as soon as the webclient subscribes the retained topic the retained message is sent: 1410481320: Sending PUBLISH to clientId-NCrfWsdfTwn (d0, q0, r0, m0, 'current_topics', ... (3144 bytes)) But this message never manages to get to the mobile device. – dan kutz Sep 12 '14 at 00:27
  • What broker / websockets and versions are you using? – Matt. Sep 12 '14 at 04:29
  • Mosquitto 1.3.1 in conjunction with lighttpd for websocketsupport. – dan kutz Sep 12 '14 at 13:01
  • I just cannot understand why it works totally fine on non-mobile devices, so I guess it must be an issue of mobile browsers? – dan kutz Sep 12 '14 at 14:24
  • I have seen something similar before, are you able to download the broker/websockets from hivemq.com and see if that works fine with your setup? – Matt. Sep 12 '14 at 20:42
  • With the hive broker it seems to work. – dan kutz Sep 13 '14 at 20:58
  • I had a similar problem with mosquitto and lighttp. Never got around to solving it, just used hivemq. Mosquitto 1.4 (yet to be released), you can compile it and it has built in websockets. – Matt. Sep 13 '14 at 22:47
  • Thanks i already came upon this solution, but somehow i cannot start the broker with websockets:1410648873: mosquitto version 1.4 (build date 2014-09-12 15:45:30+0200) starting 1410648873: Config loaded from websocket.conf. 1410648873: Opening ipv4 listen socket on port 1883. 1410648873: Opening ipv6 listen socket on port 1883. 1410648873: Error: Unable to create websockets listener on port 8010. – dan kutz Sep 13 '14 at 22:54
  • Have you got anything else running on that port 8010? ```netstat -anltp|grep :8010``` – Matt. Sep 14 '14 at 05:32
  • No I don't have anything else running. If I execute the command with sudo I receive: Error: Invalid user 'mosquitto' – dan kutz Sep 14 '14 at 11:13
  • This has to be a bug with lighttpd+websockets in my opinion. What version of both of those are you using? – ralight Sep 18 '14 at 08:13
  • Oh, and try the latest 1.4 branch - you may have fallen foul of https://bugs.launchpad.net/mosquitto/+bug/1370111 – ralight Sep 18 '14 at 09:16
  • I defined the http_dir within the config, but nevertheless receive the same error. – dan kutz Sep 21 '14 at 17:20
  • I'm still getting this issue now in 2023 - all fine on pc but not working correctly on mobile browsers. Was this fixed? – Jammo Apr 03 '23 at 17:07

1 Answers1

1

So for the ones who don't want to read all of the comments. This is seems to be a bug of mosquitto in conjunction with lighttpd, as websocket-provider.

What you can do:

either use: (simple way) HiveMQ(http://www.hivemq.com/mqtt-over-websockets-with-hivemq/) it supports websockets inherently, so the installation is a breeze, but it's not opensource and as it is written in Java I'm not sure if it is as fast as mosquitto, but I definitely don't know.

or: invest some time in compiling the newest version(1.4) of mosquitto, which also supports websockets natively: http://jpmens.net/2014/07/03/the-mosquitto-mqtt-broker-gets-websockets-support/ (but is not released so far) this version also seems to fix this problem. Installing newest mosquitto: http://goochgooch.wordpress.com/2014/08/01/building-mosquitto-1-4/

Edit0: I checked the speed and must say HiveMQ with websockets is way faster than mosquitto with websockets. I already noticed it when I connected via websockets, because there was a small latency. Then I sent 1000 values to the browser where they were returned to the subscribing client again. Hive seems to be 3-times faster than mosquitto (I have to commit that this may not be a reliable experiment). So for me my decision is obvious, as long as mosquitto doesn't work properly along with lighttpd-websocket support I will stay with hive. Would be nice to hear some opinions.

Edit1: I'm in a dilemma: Websocketsupport through lighttpd is very fast, way faster than the new mosquitto websocket support and faster than hivemq. As I am running the mqtt-broker on a raspberry, I'm dependent on good performance so neither of the discussed solutions of Edit0 is appropriate for me. But if I use lighttpd I face the originally described problem.

Does somebody have a more convenient solution?

Thx for your help.

dan kutz
  • 107
  • 1
  • 12
  • As I said above, I'm sure this is a bug in lighttpd+mod_websockets. What version of both of them are you using? – ralight Sep 24 '14 at 14:24
  • Also, could you give more details on how you measured the speed? – ralight Sep 24 '14 at 14:26
  • I am using lighttpd 1.4 with mod_websocket 3.5 is this a wrong combination? If so could you tell me which versions fit together? I measure the speed by the round trip time measured through a python script. It sends arbitrary 256 bytes to a subscribing web-client via a mosquitto broker on the raspberry pi. The web-client sends the packets immediately back to the other client. – dan kutz Sep 25 '14 at 09:51
  • Can anyone suggest another solution? – dan kutz Nov 07 '14 at 10:54
  • regarding the mosquitto websocket performance, it's an known issue in the polling loop of mosquitto. see issue 147 https://github.com/eclipse/mosquitto/issues/147. you can wait till Roger release 1.6 with a new event loop. or add the libwebsocket fd to the `WSAPoll()`'s fdlist or modify its timeout default value of 100ms to something like 30ms or 10ms. if your test showed 3x difference between mosquitto and hive, it's quite possible they are close today or soon. – minghua May 26 '16 at 05:47