Reputation: 187
I am using mosquitto mqtt both with MQTT protocol and MQTT over websockets protocol. Some client use mqtt protocol and some uses websocket protocol due to their limitations. MQTT port is 1883 and websocket port is 8083. The problem is that I want to share all the topics on both port i.e. on websocket and MQTT. What type of configurations i should do in my MQTT broker or any other solution?
In other words I want to listen to all topics on websocket(port 8083) which are published on mqtt(port 1883) on same broker and vise versa.
mosquitto.conf file is following
allow_anonymous false
password_file /etc/mosquitto/passwd
listener 8083 127.0.0.1
protocol websockets
Upvotes: 0
Views: 1887
Reputation: 59608
You don't have to change anything.
There is only one topic space shared across all listeners/protocols with mosquitto.
The following mosquitto.conf works:
port 1883
listener 8083
protocol websockets
Used with the following nodejs app to test websockets:
var mqtt = require('mqtt')
var client = mqtt.connect('ws://localhost:8083')
client.on('connect', function () {
client.subscribe('#')
client.publish('presence', 'Hello mqtt')
})
client.on('message', function (topic, message) {
// message is Buffer
console.log("%s - %s", topic, message.toString())
})
and native MQTT messages injected with mosquitto_pub -t "foo" -m "bar"
and monitored with mosquitto_sub -v -t '#'
Whole thing running mosquitto v1.4.14 (from the mosquitto ppa) on Ubuntu 16.04
Upvotes: 2