Enabling mosquitto over websocket in windows - mqtt

I have built mosquitto on Visual Studio with websockets enabled, using Cmake to generate the project files. I used libwebsockets-1.4 .
I ran this broker with a websocket listener, and as following image it started listening on port 8000 through websockets.
Now I used the PAHO websocket client and tried to connect to the broker
client = new Paho.MQTT.Client("localhost", 8000, "abc123");
client.connect({onSuccess:onConnect});
function onConnect() {
console.log("onConnect");
}
Even with verbose logging i see nothing in the broker logs. And in the browser console I get
WebSocket connection to 'ws://localhost:8000/mqtt' failed: Error during WebSocket handshake: net::ERR_CONNECTION_RESET
After that I tried it with the test.mosquitto.org:8080 , and it got connected with no issue.
PS : I then tried mosquitto 1.4.7 and libwebsocket 1.6 combination which resulted in following build errors, please suggest me a fix.
Next attempt was with mosquitto 1.4.2 and libwebsockets 1.4 , had no issue building mosquitto with it. When i used a regular tcp client it worked fine, when a connect message from a websocket client was sent mosquitto.exe crashes.
What may have gone wrong and how can I overcome this issue? Anyone who had successfully deployed mosquitto with websocket support on windows please help out.

I managed to get mosquitto built with websocket support by using mosquitto 1.4.7 and libwebsockets 1.5 without a problem.

Related

Paho C++ MQTT Client unable to connect to Mosquitto on Ubuntu Docker Image (Python Client Works)

I am facing this issue for a couple of days and I am unable to reproduce it outside the Ubuntu Docker container.
Please refer to this simplified diagram of my architecture:
As you can see, I have everything running inside the Docker container.
This is not the typical issue of not being able to connect to inside the container, the whole application runs on the local network of the Docker container.
The Ubuntu Image is the official one with just some packages installed so that everything works (nothing too fancy, just python3 and some c++ tools).
It is running Mosquitto 2.0.15 with the following configuration:
listener 1883
protocol mqtt
allow_anonymous true
log_dest file /home/user/mosquitto.log
So, in summary, I am running an unsecured MQTT broker in the default port 1883. I also added a log file in an attempt to debug what is going on.
On my Python Client, the connection is made in the simplest way possible:
...
self.mqtt_client = mqtt.Client(client_id="Client Id")
self.mqtt_client.connect("localhost", 1883, 6000)
...
self.mqtt_client.loop_start()
...
This Client is able to connect to the broker with no issue at all.
Subscribe and Publish works perfectly too!
On my C++ Client, I try to keep it simple as well:
...
mqtt::async_client MQTTClient("tcp://localhost:1883", "Another Client Id");
MQTTClient.connect()->wait();
...
Yet, this Client fails every attempt to connect to the broker:
terminate called after throwing an instance of 'mqtt::exception'
what(): MQTT error [-1]: TCP/TLS connect failure
Aborted (core dumped)
Although it looks like a SSL/TLS error, this is actually the generic error for when the MQTT broker is not found (If I stop the broker on my local machine I get the same error).
Checking the MQTT broker logs (verbose ON), it does not record anything regarding the attempt to connect from C++ Client:
1672874968: mosquitto version 2.0.15 starting
1672874968: Config loaded from /etc/mosquitto/conf.d/default.conf.
1672874968: Opening ipv4 listen socket on port 1883.
1672874968: mosquitto version 2.0.15 running
(I do get log messages when connecting with Python Client)
On my own Linux machine I am unable to reproduce this issue. Both clients work fine.
I am using the same configuration for the Mosquitto broker and the Clients are exactly the same.
Already tried to play with the IP used to connect to the broker (localhost/127.0.0.1/0.0.0.0) and using different ports, the result is the same.
It is weird that the Python Client can connect with no issue at all.
At this point, I am fairly confident that the issue must be something Docker-specific and how it handles TCP sockets. But I am unable to find anything helpful online.
I can easily check that the port is open:
lsof -i -P -n | grep :1883
mosquitto 56 user 5u IPv4 1633274841 0t0 TCP 127.0.0.1:1883 (LISTEN)
Any ideas what is going on? Or debug tools ideas?
Thanks in advance!
I have tried:
Playing with IP and port of the broker;
Stating the preferable MQTT version (tried with every version);
Run Client with strace and try to find something unusual;
Verify if I am running the exact same Client as my Linux machine;
I finally found out what my issue was.
I had a HTTP proxy configured and Paho C will automatically use this proxy.
It is detecting by checking if "http_proxy" environment variable is set.
My solution was simply unset this variable:
unset http_proxy
Interestingly, the Python MQTT client does not have this behavior.
And for that reason, it worked perfectly!

Mosquitto server hosted on Digital ocean not making remote connections with android and Eclipse Paho Javascript Clients

I hosted Mosquitto MQTT broker on Ubuntu in Digital Ocean Cloud droplet. It's domain name is instrux.live and IP of the domain is 192.34.63.138. I publish and subscribe messages from two terminal windows and it worked fine.
When I tried to connect it with the android using Paho MQTT android client it could not connect. I also checked its connection with the MyMQTT android application and it did not connect. After making sure the android code has not any error, I again checked its connection with the Eclipse Paho Javascript client on eclipse.org website and it did not connect. Now, I have realized there might be something missing or wrong in my broker configuration which is not allowing it to get connected with other clients remotely. I have also opened firewall for ports 1883 for Android client and 8083 for the Javascript client and still it is not connecting.Here is mosquitto configuration file:
allow_anonymous true
password_file /etc/mosquitto/passwd
listener 1883
protocol mqtt
listener 8083
protocol websockets
Since the error is "Connection Refused" rather than a timeout I suspect that you have not configured the firewall to allow inbound traffic on port 8083.
You may need to do this both on the machine it's self and in Digital Ocean's console.

Thingsboard CoAP Port opening

I am trying to send data from my NodeMCU to my local thingsboard installation on my computer. However, I don't know how to do it. I am really new at these stuff, I saw some fine examples with HTTP and MQTT, but there isn't any info about CoAP on thingsboard website.
There is a documentation about CoAP API Reference that says I need to send a post request to coap://localhost:5683/api/v1/........../telemetry but when i try to do it with Postman it says cant reach the following adress. I tried doing it with http://localhost:5683/api/v1/........../telemetry and it works. I saw my messages in Latest Telemetry Section in my Device on Thingsboard.
To connect to my Thingsboard installation I use localhost:8080 so I assume my thingsboard server is only started at port 8080 not 5683-> Coap. I would very much appreciate the help.
After enabling coap in thingsboard.yml file, you have to restart thingsboard service on your computer, to do that use
"sudo systemctl stop thingsboard" &
"sudo systemctl start thingsboard"

Trying to setup Neo4j 3.2.0 in ubuntu server

I am trying to setup Neo4j version 3.2.0 in the ubuntu server 14.04.2 LTS
Downloaded the tar and extracted the folder, edited the config file to update the port to 4444, for the time being disabled the bolt connector, listen_address to 0.0.0.0 for the http connector, authentication also disabled just to get started.
bolt connector is updated with the port 7687 even though it is disabled as i was trying earlier with it enabled.
Now when i try to connect to the http://serverip:4444/browser, it says Database access not available and shows me the login screen with host prefilled bolt://serverip:7687
Also I see this error on the console window
WebSocket connection to ws://serverip:7687/
failed: Error in connection establishment:
net::ERR_CONNECTION_TIMED_OUT
Dont understand the issues here, please help me out. I am not sure why is it trying to do a WS to the port assigned to the bolt, when it is disabled at the first place.
Regards
There's a bit of juggling going on for HTTP connector support between the browser and the driver being used, a handoff which isn't complete, and the state of things is the browser is only supporting bolt connections right now.
The javascript bolt driver is being upgraded to handle http connections, I think, so you may need to wait until the next 3.2.x release to use the http connector again.
I think this issue should be tracking it.

Enabling websockets support in packaged mosquitto 1.4.7

How is websocket support enabled in mosquitto 1.4.7 when it's installed via a package manager (apt-get install mosquitto)? I see there is support for it, but I cannot determine how to enable it (and set the port) in configuration. There is an article that seems to indicate it can be enabled when built from source (https://goochgooch.wordpress.com/2014/08/01/building-mosquitto-1-4/).
Is building from source the only option to enable websocket support?
Assuming support is compiled into the build you have then adding the following to the mosquitto.conf should work
listener 9001
protocol websockets
This will start a websocket listener on port 9001
If the build you have doesn't have websocket support then the following error will be printed to the console:
Error: Websockets support not available.

Resources