Hello,
I am unable to connect to my local Mosquitto 1.4.10 broker from a JavaScript client over a websocket.
The same JavaScript client is successfully connecting to the public broker at test.mosquitto.org on port 8080 over a websocket.
The MQTT protocol connection on port 1883 is working fine, which I tested using mosquitto_pub and mosquitto_sub.
My broker is set up within a VirtualBox running Ubuntu 14.04.
I have libwebsockets installed on the same virtual machine.
My local broker was compiled with WITH_WEBSOCKETS:=yes in the _config.mk_ file
I confirmed by running _sudo netstat_ that the Websockets port is open.
I am loading the JavaScript client web page from a Firefox browser, from inside the same virtual machine on which Mosquitto is running. I get the following error message in the browser console (Apache web server is running on the same virtual machine as Mosquitto):
Firefox can't establish a connection to the server at ws://localhost:8080/mqtt
I did a trace through Wireshark and it seems that the client is getting no response from the server after sending the initial HTTP request to upgrade to the Websockets protocol (see trace below).
As far as I can tell, the issue lies in the Mosquitto installation. Whether it is a bug or something missing in my setup, I cannot tell.
It might help, for starters, if I could look at the .conf file set up for the test.mosquitto.org installation, so I may compare it to my settings.
Any other suggestions on fixing this will be greatly appreciated.
Thanks.
Here is my Mosquitto .conf file:
port 1883
listener 8080
protocol websockets
log_type all
websockets_log_level 1023
connection_messages true
Here is the Mosquitto server's log (with websockets logging level set to 1023, and verbose logging turned on - no messages appear when I load the JavaScript web page):
1481381105: mosquitto version 1.4.10 (build date 2016-12-10 18:47:37+0530) starting
1481381105: Config loaded from /etc/mosquitto/mosquitto.conf.
1481381105: Opening websockets listen socket on port 8080.
1481381105: Initial logging level 1023
1481381105: Libwebsockets version: 2.1.0 manavkumarm@manav-alljoyn-
1481381105: IPV6 not compiled in
1481381105: libev support not compiled in
1481381105: libuv support not compiled in
1481381105: Threads: 1 each 1024 fds
1481381105: mem: platform fd map: 4096 bytes
1481381105: Compiled with OpenSSL support
1481381105: Creating Vhost 'default' port 8080, 3 protocols, IPv6 off
1481381105: Using non-SSL mode
1481381105: Listening on port 8080
1481381105: mem: per-conn: 376 bytes + protocol rx buf
1481381105: canonical_hostname = mqtt
1481381105: Opening ipv4 listen socket on port 1883.
1481381105: Opening ipv6 listen socket on port 1883.
Here is the Wireshark trace:
GET /mqtt HTTP/1.1
Host: localhost:8080
User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:49.0) Gecko/20100101 Firefox/49.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Sec-WebSocket-Version: 13
origin: http://localhost
Sec-WebSocket-Protocol: mqtt
Sec-WebSocket-Extensions: permessage-deflate
Sec-WebSocket-Key: 2jGKB8w/B3al/XajJp3o6g==
Connection: keep-alive, Upgrade
Pragma: no-cache
Cache-Control: no-cache
Upgrade: websocket
With pretty much zero expertise, can I just take a shot in the dark?
Could this be related to cross-origin issues?
Broker:
1481381105: canonical_hostname = mqtt
Client:
origin: http://localhost
Wonder if mosquitto HTTP websockets listener is setup to support CORS...
I have used same config and served client html file from local apache server, although I installed mosquitto using home brew, but I do not think that will make any difference. Request headers are in my case are :-
Host: 127.0.0.1:8080
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:50.0) Gecko/20100101 Firefox/50.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Sec-WebSocket-Version: 13
origin: http://localhost
Sec-WebSocket-Protocol: mqttv3.1
Sec-WebSocket-Extensions: permessage-deflate
Sec-WebSocket-Key: vhDRatXBGVETP75wu0wr1A==
Connection: keep-alive, Upgrade
Pragma: no-cache
Cache-Control: no-cache
Upgrade: websocket
In my case I am able to connect to broker. Check my client file here. My suggestion is that you open your browser console and check what error you are getting. Hope it helps.
Thanks. I'm afraid I don't see anything here that is of help to me. Seems like I am performing exactly the same steps as you and not meeting with the same success. I have checked every other setting in my environment that I can think of.
Could you share your _.conf_ file, just to check if there are additional settings in there which might be of help to me?
Also, it would be helpful, if possible, to see the command-line options used to compile _libwebsockets_ on your machine (i.e. the optional components if any that were included in the compilation).
test.mosquitto.org uses libwebsockets 2.0.2 compiled with default options.
The relevant part of the config file is
listener 8080
protocol websockets
http_dir /var/lib/mosquitto/http_dir
Does the broker have permission to the http_dir directory and files?
I ran into the same issue as the OP and was able to resolve it by changing to libwebsockets 2.0.2 instead of using the latest 2.1.0.
So looks like mosquitto doesnt work well with the latest libwebsockets version...two questions:
Appreciate the efforts that is going in to maintain mosquitto. Have a great holiday season. Cheers.
Any news on this matter? It seems that I am troubled by the same problem on an OS X 10.11 El Capitan system.
Like @kumar003vinod, I installed mosquitto 1.4.10 via homebrew, too (actually upgraded from 1.4.9). libwebsockets was also updated via homebrew to 2.1.0.
@ralight You have added a "duplicate" -tag to this issue. Would you mind, referencing the original issue? Thanks!
Edit:
Just found out that on my Raspberry Pi (with a stone-old libwebsockets 1.2.2) mosquitto 1.4.10 is running fine with websockets support.
Ran into same on the latest Docker image. Websockets completely busted.
I'm not quite sure why the duplicate tag got added, I don't remember doing that.
I've been testing this and I think it is a regression in libwebsockets 2.1. Nothing I've been able to do will make things work on libwebsockets 2.1. Using the latest code from lws git is fine.
I think we need to wait until libwebsockets 2.1.1 is released.
@ralight is there an open issue on their side? Might be interesting to do a bisect and see where it got fixed.
Same issue here. Mosquitto installed via brew install mosquitto, enabled with following three lines:
listener 1884
protocol websockets
http_dir /Users/etc... (permissions are ok, contains a readable index.html)
On startup, mosquitto reports opening both 1884 and 1883, and "Libwebsockets version: 2.1.0".
The version reported is: mosquitto version 1.4.10 (build date 2016-12-25 03:38:45+0000).
FYI: I just tested downgrading my Docker image to eclipse-mosquitto:1.4.8 and websockets appears to be working there.
@jcw Same issue here with same environment
I'll get in touch with the libwebsockets project about it.
Hi all. OSX 10.11.5 El Capitan here.
Mosquitto 1.4.10 and libwebsockets 2.1.0 didn't work for me either. Mosquitto seemed to be listening on 127.0.0.1:9001, however no browsers were able to establish a ws://127.0.0.1:9001 connection and were ending with timeouts.
Thanks to @ashishbajaj99's note, I finally solved this by downgrading libwebsockets to 2.0.2 and reinstalling mosquitto 1.4.10.
Unfortunately I found no easy way to downgrade libwebsockets using brew, so I had to:
/etc/local/Cellar/libwebsockets/2.0.2brew doctor if everything is fine with symlinks etc.brew reinstall mosquittobrew switch libwebsockets 2.0.2 (it's ok to have two versions installed with brew)I've been struggling for the solution for over a week!
In case someone needs libwebsockets 2.0.2 as a zip, I can send him.
Hope this issue is solved soon.
hi @metelski,
I just start playing with mosquitto recently, and encounter this problem, too
so, may I ask where I can find this [email protected]?
trying to compile from its branch 2.0-stable, but so much pain
thanks
@monkeydj here you go - I uploaded zip files of working versions of mosquitto 1.4.10 and libwebsockets 2.0.2 via WeTransfer: https://we.tl/EoCgpc7zfA.
I am sending you both packages, because brew reinstalling mosquitto 1.4.10 can still cause some problems with compatibility of compiled libraries.
After you replace the folders (keep a backup somewhere), you may run brew doctor to see what should be done in order to make them run, e.g. brew link mosquitto or brew prune may be needed in your case.
@metelski thank you for those files, they ran perfectly together
if I used brew installed mosquitto, it would require lws.9.dylib, not 8
thanks again
FYI - v2.1.1 has been released. Time for an update of the Docker image?
Good news for macOS users: websockets in mosquitto are working fine again, after updating the mosquitto and libwebsocket packages via homebrew đ».
_Great!_
Yeahhh!
An updated docker image would be nice, I hat to downgrade to 1.4.4 in order to use websockets
This really needs 1.4.11 to be added to alpine linux first.
after system update my mosquitto also stopped working via WebSocket
(Ubuntu 14.04)
I just commented
protocol websockets
now working mqtt protocol only
otherwise mosquitto not start at all
same here.
after system update my mosquitto also stopped working via WebSocket (Ubuntu 14.04)
# mosquitto -v -c /etc/mosquitto/mosquitto.conf
Error: Websockets support not available.
Error found at /etc/mosquitto/conf.d/default.conf:12.
Error found at /etc/mosquitto/mosquitto.conf:13.
Error: Unable to open configuration file.
update. my issue is solved, websockets were reenabled.
https://launchpadlibrarian.net/309572687/mosquitto_1.4.11-0mosquitto2~trusty2_source.changes
thanks!
wget http://mosquitto.org/files/source/mosquitto-1.4.11.tar.gz
tar -zxvf mosquitto-1.4.11.tar.gz
cd mosquitto-1.4.11
// in file config.mk set: WITH_WEBSOCKETS:=yes
make
make install
and miracle .. working
Can't connect to mosquitto via wss.
Using: http://www.websocket.org/echo.html,
connecting to: wss://test.mosquitto.org:8081
Got: ERROR: undefined
By the way, deploy mosquitto 1.4.11 with Websockets, I got the same result.
libwebsocket 2.2.0 has been released 2017-03-08
Works for me after install the latest version!
mosquitto 1.4.11
libwebsockets 2.2.1
+1
OX 10.11 El Capitan
mosquitto v.1.4.12
libwebsockets 2.2.1
Installed via Homebrew (brew install... )
It appears that mosquitto does NOT have websockets enabled by default. Here's what worked for me:
Shut down mosquitto (if it was running)
Open mosquitto config file in your text editor (/usr/local/etc/mosquitto/mosquitto.conf)
Scroll to line #297 where it says...
# Choose the protocol to use when listening.
# This can be either mqtt or websockets.
# Certificate based TLS may be used with websockets, except that only the
# cafile, certfile, keyfile and ciphers options are supported.
#protocol mqtt
port 1883
listener 1884
protocol websockets
So now it should look like this....
# Choose the protocol to use when listening.
# This can be either mqtt or websockets.
# Certificate based TLS may be used with websockets, except that only the
# cafile, certfile, keyfile and ciphers options are supported.
#protocol mqtt
port 1883
listener 1884
protocol websocket
You are setting 1883 to default to mqtt protocol
You are adding a listener on (port) 1884 for websockets (you can make it any port# but I thought 1884 was easier to remember)
mosquitto -v -c /usr/local/etc/mosquitto/mosquitto.conf
That's it! You should now be able to send and receive messages between mqtt and ws.
Happy coding :)
I'm using mosquitto 1.4.12, Amazon Linux AMI. when trying to restart mosquitto after applying the following config:
listener 1883
listener 1884
protocol websockets
I got the following error aftr restarting:
[server ~]$ sudo service mosquitto restart
Shutting down Mosquitto MQTT broker [FAILED]
Starting Mosquitto MQTT brokerError: Websockets support not available.
Error found at /etc/mosquitto/conf.d/bridge.conf:29.
Error found at /etc/mosquitto/mosquitto.conf:10.
Error: Unable to open configuration file.
[FAILED]
Anything I'm missing?
I tried to figure out how to install libwebsockets, but couldn't find anything about installing it on ec2 instance.
@theunreal this is not the same issue. The package you installed was built without websockets support. You'll have to compile it for yourself, or find another package that was built with it.
I'm using Mosquitto 1.4.12
Thanks a lot @stormbytes ... your solution does help me.
I think this issue can be closed. The docker image for 1.4.12 seems to work now
hi
wget http://mosquitto.org/files/source/mosquitto-1.4.11.tar.gz
tar -zxvf mosquitto-1.4.11.tar.gz
cd mosquitto-1.4.11
// in file config.mk set: WITH_WEBSOCKETS:=yes
make
make install
1) In $ make command gives below error:-
set -e; for d in lib client src; do make -C ${d}; done
make[1]: Entering directory `/home/mqttserverwikey/mosquitto-1.4.11/lib'
cc -Wall -ggdb -O2 -I. -I.. -I../lib -fPIC -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -DWITH_SRV -c mosquitto.c -o mosquitto.o
In file included from mosquitto.c:33:
./mosquitto_internal.h:40:20: error: ares.h: No such file or directory
In file included from mosquitto.c:33:
./mosquitto_internal.h:265: error: expected specifier-qualifier-list before âares_channelâ
mosquitto.c: In function âmosquitto_loopâ:
mosquitto.c:884: error: âstruct mosquittoâ has no member named âachanâ
mosquitto.c:887: warning: implicit declaration of function âares_fdsâ
mosquitto.c:887: error: âstruct mosquittoâ has no member named âachanâ
mosquitto.c:992: error: âstruct mosquittoâ has no member named âachanâ
mosquitto.c:993: warning: implicit declaration of function âares_processâ
mosquitto.c:993: error: âstruct mosquittoâ has no member named âachanâ
make[1]: *** [mosquitto.o] Error 1
make[1]: Leaving directory `/home/mqttserverwikey/mosquitto-1.4.11/lib'
make: *** [mosquitto] Error 2
2) In $ make install command gives below error:-
set -e; for d in lib client src; do make -C ${d}; done
make[1]: Entering directory `/home/mqttserverwikey/mosquitto-1.4.11/lib'
cc -Wall -ggdb -O2 -I. -I.. -I../lib -fPIC -DWITH_TLS -DWITH_TLS_PSK -DWITH_THREADING -DWITH_SOCKS -DWITH_SRV -c mosquitto.c -o mosquitto.o
In file included from mosquitto.c:33:
./mosquitto_internal.h:40:20: error: ares.h: No such file or directory
In file included from mosquitto.c:33:
./mosquitto_internal.h:265: error: expected specifier-qualifier-list before âares_channelâ
mosquitto.c: In function âmosquitto_loopâ:
mosquitto.c:884: error: âstruct mosquittoâ has no member named âachanâ
mosquitto.c:887: warning: implicit declaration of function âares_fdsâ
mosquitto.c:887: error: âstruct mosquittoâ has no member named âachanâ
mosquitto.c:992: error: âstruct mosquittoâ has no member named âachanâ
mosquitto.c:993: warning: implicit declaration of function âares_processâ
mosquitto.c:993: error: âstruct mosquittoâ has no member named âachanâ
make[1]: *** [mosquitto.o] Error 1
make[1]: Leaving directory `/home/mqttserverwikey/mosquitto-1.4.11/lib'
make: *** [mosquitto] Error 2
apt-get install libc-ares-dev
hi i tried the command which you refer.
But i found error :- -bash: apt-get: command not found
So i tried this one sudo yum install libc-ares-dev
it's give following error
No package libc-ares-dev available.
Error: Nothing to do
Your system server ? ubuntu / debian it's ok
Linux
On Fri, Nov 24, 2017 at 3:24 PM, Tifaifai Maupiti notifications@github.com
wrote:
Your system server ? ubuntu / debian it's ok
â
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/eclipse/mosquitto/issues/336#issuecomment-346788341,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AMReN2yPHgOp8rr8vX1MjZnkOr2GwNqdks5s5pJWgaJpZM4LKCJt
.
--
SUNIL PARMAR SR WEB DEVELOPER NIMBLECHAPPS.COM http://nimblechapps.com/
<%2802%29%206962%201455>
twitter https://twitter.com/nimblechapps
|
google https://plus.google.com/+Nimblechapps
|
facebook https://www.facebook.com/nimblechapps
|
linkedin https://www.linkedin.com/company/nimblechapps-pvt-ltd-
Ubuntu or debian is Linux distribution ;)
uname -a
uname -a
Linux myi.myicuisine.com 2.6.32-042stab116.1 #1 SMP Wed May 4 16:21:02 MSK 2016 x86_64 x86_64 x86_64 GNU/Linux
Even i tried :- sudo yum install mosquitto
but its give me error :-
No package mosquitto available.
Contact Loic Mucha ;)
@sunilnimble2015 why are you spamming this thread with a completely unrelated issue?
go to your distribution documentation and learn how to look for packages and install them then, and only then, open a new one if compiling isn't working.
@sunilnimble2015 To clarify, aptitude (apt-get) is a package manager for
Debian-based systems. yum is a package manager for Redhat-based systems.
I cannot tell from the uname easily, but you appear to have neither of
those Linux distributions.
Mosquitto has a dependency on the c-ares library, which you must install
prior to compilation. You can build it from source from Github:
https://github.com/c-ares/c-ares
You will need to follow the build instructions to satisfy its dependencies
as well.
Regards,
Brandon
On Fri, Nov 24, 2017 at 5:33 AM, Andrea Pinazzi notifications@github.com
wrote:
@sunilnimble2015 https://github.com/sunilnimble2015 why are you
spamming this thread with a completely unrelated issue?
go to your distribution documentation and learn how to look for packages
and install them then, and only then, open a new one if compiling isn't
working.â
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/eclipse/mosquitto/issues/336#issuecomment-346796708,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABXHpd_VzzmwOYDlzyI2Qp-7eA3QyprIks5s5ptigaJpZM4LKCJt
.
Closing as the issue seem resolved: libwebsockets 2.1.0 does not works with Mosquitto. Older (2.0 or 1.7 for example) or newer (2.1.1 or more) version of libwebsockets should be used.
use the servers hostname not the ip
use 'hostname' not '127.0.0.1'or 'localhost' worked for me
Most helpful comment
Hi all. OSX 10.11.5 El Capitan here.
Mosquitto 1.4.10 and libwebsockets 2.1.0 didn't work for me either. Mosquitto seemed to be listening on 127.0.0.1:9001, however no browsers were able to establish a ws://127.0.0.1:9001 connection and were ending with timeouts.
Thanks to @ashishbajaj99's note, I finally solved this by downgrading
libwebsocketsto2.0.2and reinstalling mosquitto 1.4.10.Unfortunately I found no easy way to downgrade
libwebsocketsusing brew, so I had to:/etc/local/Cellar/libwebsockets/2.0.2brew doctorif everything is fine with symlinks etc.brew reinstall mosquittobrew switch libwebsockets 2.0.2(it's ok to have two versions installed with brew)I've been struggling for the solution for over a week!
In case someone needs libwebsockets 2.0.2 as a zip, I can send him.
Hope this issue is solved soon.