Hello!
I want to connect with pure Javascript (Websocket).
But I can’t receive messages.
Can you tell me in what format you need to subscribe to topics? And publish in a topic.
Ports are open. I can connect via MQTT Explore(ws://192.168.1.100:18883). But I can’t send messages.
For example, to topic “/devices/wb-mr6cu_43/controls/K1/on” send a message “0”
Working example (bash):
mqtt pub -t ‘/devices/wb-mr6cu_43/controls/K1/on’ -h ‘192.168.1.100’ -m ‘0’
Thank you in advance!
I wrote a simple bridge that works. But I want to understand how to subscribe to selected topics by
pure WebSocket. And how to send them.
const WebSocketServer = require('ws');
const wss = new WebSocketServer.Server({port: 8080})
const mqtt = require('mqtt')
const client = mqtt.connect('mqtt://127.0.0.1:1883')
wss.on("connection", ws => {
ws.send('Welcome, you are connected!');
ws.on('message', (data) => {
let message;
try {
message = JSON.parse(data);
if (message.hasOwnProperty('topic') && message.hasOwnProperty('message')) {
client.publish(message.topic, message.message)
}
} catch (e) {
return;
}
});
})