Mosquitto mqtt on ubuntu for windows - bash

I'm trying to setup a mosquitto mqtt server on windows using bash on ubuntu on windows because the code I'm try to run is that of Linux but I've been getting this error. I've surfed through the internet for days now and still haven't found a solution,
1588558652: Warning: Mosquitto should not be run as root/administrator.
1588558652: mosquitto version 0.15 (build date 2018-09-05 15:14:14+0000) starting
1588558652: Opening ipv4 listen socket on port 1883.
1588558652: Opening ipv6 listen socket on port 1883.
1588558652: Error: Address already in use
Mind you I'm not a coder so I'm new to all of this. Thanks for helping...

The error is telling you what is wrong: Some other program already has port 1883 open and is using it....thus Mosquitto can't use it.
You can find out which program has port 1883 open by using something like this (Not sure if it works on all Ubuntu's, but works on my v16.04.6 LTS):
netstat -pan | grep 1883

Related

Mosquitto ERR_CONNECTION_REFUSED using websockets (paho client) on win 10

I've read all the threads with similar questions, but couldn't find an answer.
Mosquitto config:
listener 1883 127.0.0.1
protocol mqtt
listener 9001 127.0.0.1
protocol websockets
log output:
1567705166: mosquitto version 1.6.2 starting
1567705166: Config loaded from C:\Program Files (x86)\mosquitto\mosquitto.conf.
1567705166: Opening ipv4 listen socket on port 1883.
1567705166: Opening websockets listen socket on port 9001.
1567705166: Opening websockets listen socket on port 1883.
Chrome devtools:
mqttws31.js:977 WebSocket connection to 'ws://127.0.0.1:9001/mqtt' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
I've tried many things but nothing helped:
Trying websockets only
Trying another port (1883 and 9001 instead of 8080)
Switching off Windows firewall
If I change the config file to:
#listener 1884 127.0.0.1
#protocol mqtt
#listener 1883 127.0.0.1
protocol websockets
Mosquitto listens for websockets on port 1883 but logfile reads:
1567706943: mosquitto version 1.6.2 starting
1567706943: Config loaded from C:\Program Files (x86)\mosquitto\mosquitto.conf.
1567706943: Opening websockets listen socket on port 1883.
1567706943: Error in poll: No error.
1567706943: Error in poll: No error.
1567706943: Error in poll: No error.
1567706943: Error in poll: No error.
1567706943: Error in poll: No error.
1567706943: Error in poll: No error.
1567706943: Error in poll: No error.
1567706943: Error in poll: No error.
1567706943: Error in poll: No error.
1567706943: Error in poll: No error.
changing config to:
protocol websockets
listener 8080 127.0.0.1
protocol mqtt
Gives me a logfile that says:
1567707450: mosquitto version 1.6.2 starting
1567707450: Config loaded from C:\Program Files (x86)\mosquitto\mosquitto.conf.
1567707450: Opening ipv4 listen socket on port 8080.
1567707450: Opening websockets listen socket on port 1883.
(no extra crap)
After following up on answer no 1:
config:
protocol websockets
listener 1883 127.0.0.1
protocol mqtt
console:
WebSocket connection to 'ws://127.0.0.1:1883/mqtt' failed: Error during WebSocket handshake: net::ERR_CONNECTION_RESET
log:
1567716915: mosquitto version 1.6.2 starting
1567716915: Config loaded from C:\Program Files (x86)\mosquitto\mosquitto.conf.
1567716915: Opening ipv4 listen socket on port 1883.
1567716915: Opening websockets listen socket on port 1883.
1567716920: New connection from 127.0.0.1 on port 1883.
1567716920: Socket error on client <unknown>, disconnecting.
1567716920: New connection from 127.0.0.1 on port 1883.
1567716920: Socket error on client <unknown>, disconnecting.
5492: Error in poll: No error.
1567715492: Error in poll: No error.
1567715492: Error in poll: No error.
1567715492: Error in poll: No error.
1567715492: Error in poll: No error.
1567715492: Error in poll: No error.
Tried another websockets client (https://www.eclipse.org/paho/clients/js/utility/) --> Failed to connect: AMQJSC0001E Connect timed out.
I can't get websockets to work with any configuration / port...
Can anyone confirm that Websockets in Mosquitto (32bit version 1.6.2 or 1.6.4) for Win10 are working ?
Your first config file won't work because you have both native MQTT and Websockets both trying to listen on port 1883. (this is because the default listener starts on port 1883), Not 100% sure how this is possible unless it's some strange IPv6 thing on Windows.
The second, is just changing the default listener protocol to Websockets, which in theory should work, assuming you try and connect to port 1883 from the webpage.
The third one makes the default listener on port 1883 Websockets and native on 8080. Again should work assuming you are trying to connect to 1883
The simplest config to enable Websockets should look like this:
listener 9001 127.0.0.1
protocol websockets
This will leave the native default listener alone on port 1883 (listening on all interfaces, use bind_address 127.0.0.1 before the listener line to make it only listen on localhost) and start the Websocket listener on port 9001
This turned out to be quite the challenge.
First I tried to get things working using an online broker and client. Still not working. I then switched to another computer and everything was working fine.
Switching back to the original computer I decided to test if websockets where working at all by going to https://www.websocket.org/echo.html
From that moment on everything started to work. First the online broker and client and then also the local server and clients. I have no idea why...

New connection from ::1 on port 8883. Socket error on client <unknown>, disconnecting

I'm trying to connect/publish from broker to web, but it's not work.
I am already searching on the internet, but cannot find anything to solve it.
example when someone told me to untag bridge_protocol on mosquitto.conf , it's not work but get another error.
my mosquitto version is 1.4.9
I think something need to change on mosquitto.conf
When I try mosquitto -v -c mosquitto.conf
the result is :
mosquitto version 1.4.9
config loaded from mosquitto.conf
opening ipv4 and 6 socket on port 8883
new connection from :11 on port 8883.
socket error on client <unknown>, disconecting.
I can connect/publish from Broker to web.
I'm going to make a guess here...
It looks from the log that you have just changed the default port mosquitto is listening on from 1883 to 8883 most likely with the port configuration option.
You are then trying to connect to this from a webpage using the Paho JavaScript client.
This is failing because while you have changed the port you have not told mosquitto that it needs to use the websocket protocol for that port. This is because the Paho JavaScript client can only use MQTT over WebSockets not native MQTT.
The way to fix this is to reset the default port back to 1883 and then add a listener on port 8883 specifically set up to use WebSockets.
e.g. a mosquitto.conf like this:
port 1883
listener 8883
protocol websockets

Able to open TCP port but not listening

Using Add rule in windows firewall, I was able to open TCP port 15537. When i am trying to executing command netstat -ano on terminal windows, this port is not listed. I tried to execute telnet command on terminal window (e.g. telnet IP port) but getting
Connecting To localhost...Could not open connection to the host, on port 15537: Connect failed
Then I downloaded PortQry application and execute it from different machine, this machine is also in the same network, the result I received was
"Not Listening".
I already spent more than 2 days and asked internal group but could not find solution.
Note: both machines are having Windows 10 OS.
No solution is needed as no problem is indicated in the question. You have opened a TCP port successfully. You have not made any attempt to cause anything to listen to that TCP port.
It's not clear what results you expected, but you got the results that you should have expected. Nothing is wrong. The port is open because you opened it. Nothing is listening on that port because you didn't set anything to listen on that port.
There may be some forwarding rules? Since the purpose of access is not on the local machine, the netstat command cannot see the port on listening, but it can see the next action based on this port, usually to do some forwarding
I am not very familiar with windows firewall configuration, but I know that if there is a forwarding rule in linux, like
-p tcp -m tcp --dport 8080 -j {other forwading chain}
we can not see 8080 listening on this host (netstat -tunpl), but telnet host:8080 may see connected
Use nmap instead of netstat for detecting opening port
nmap -p your_port_number your_local_ip
Run service on that port
For eg- In my case,in order to open port,I use
"service ssh start" or "service apache2 start "and it's open port 22 and 80 for connection respectively in my linux machine.
On using nmap in my lan network both ports opened.
Hope it help

mosquitto (mqtt broker) is refusing connections over websockets

I've set up a mosquitto broker but it refuses to connect over websockets
here is my conf file:
# Place your local configuration in /etc/mosquitto/conf.d/
#
# A full description of the configuration file is at
# /usr/share/doc/mosquitto/examples/mosquitto.conf.example
pid_file /var/run/mosquitto.pid
persistence true
persistence_location /var/lib/mosquitto/
log_dest file /var/log/mosquitto/mosquitto.log
include_dir /etc/mosquitto/conf.d
listener 1883 0.0.0.0
listener 8008 0.0.0.0
protocol websockets
and I don't have any conf at conf.d
Using the PAHO javascript client I get a ERR_CONNECTION_REFUSED
by the way I'm using debian jessie as OS
-------------------------------------EDIT 1----------------------------------
I've lowered the iptables and it still not working.
The usual way to connect is working (with port 1883)
Here is the output when I start mosquitto
1477788244: mosquitto version 1.4.10 (build date Thu, 25 Aug 2016 10:12:09 +0100) starting
1477788244: Using default config.
1477788244: Opening ipv4 listen socket on port 1883.
1477788244: Opening ipv6 listen socket on port 1883.
The important line in the startup output is here:
1477788244: Using default config.
This says that mosquitto is using it's built in config (only listen on 1883 for native MQTT traffic) and not even reading your config file.
If you just start mosquitto with no command line options this is what is uses, it will not look for a config file in /etc/mosquitto/.
You need to explicitly tell mosquitto where it's config file with the -c option.
mosquitto -c /etc/mosquitto/mosquitto.conf
Depending on how you installed mosquitto you may need to edit the scripts that automatically start it on boot. This is probably in here: /etc/init.d/mosquitto

Couldn't start riemann health

I'm new to Riemann and also new to ruby and Clojure as well.
When I implementation of the riemann command:
riemann-health
The error message is
Riemann::Client::TcpSocket::Error Could not connect to 127.0.0.1:5555:Errno::ECONNREFUSED: Connection refused - connect(2)
/var/lib/gems/1.9.1/gems/riemann-client-0.2.5/lib/riemann/client/tcp_socket.rb:233:in `connect_nonblock'
My develop environment is:
Ubuntu 14.04.2 LTS
riemann version is 0.2.10.
java version "1.8.0_45"
ruby 1.9.3p484
I'm assuming that you are running Riemann and riemann-dash on the same computer and not using docker for either of these:
Riemann listens to
port 5555 udp for events
port 5555 tcp for events
port 5556 tcp for queries
so there are several combinations of possible problems:
riemann is not running at all
riemann started up, and then fell over and died.
this happens when it has no config file for instance.
riemann is not listening on 5555 tcp
riemann is not listening on 5555 udp
riemann is listening to the incorrect interface (aka "bind address")
If riemann where configured to listen to 1.2.3.4:5555 then it would not respond to connections from localhost (127.0.0.1)
the connection is being blocked by some firewall (no, don't turn your firewall off)
riemann is listening on udp and you are sending tcp (or the other way around)
once you have convinced yourself that the riemann process is still running run
sudo netstat -nlp | grep 5555
and be sure you can see that riemann is infact listening to port 5555 both tcp and udp. Then install netcat and make sure you can connect to those ports with
nc -v localhost:5555
and
nc -uvv localhost:5555
asdfasfd
(yes you need to type some gobbeldy to get the second example to actually send a packet.
If you still havent got a connection install etherial or tcpdump and start sniffing.
If you are running docker, and using riemann in UDP then there are a whole other set of things to check.

Resources