In my project I am trying to have multiple Raspberry Pi devices as "publishers" with one broker in the middle and countless subscribers to get info from certain topics.
I am having problems with connecting broker and publisher, it just stops on console.log("Before connection")
and is unwilling to go further.
Broker:
const aedes = require('aedes')
const server = require('net').createServer(aedes.handle)
const port = 1883
server.listen(port, function() {
console.log('Server je pokrenut na portu ', port)
})
Publisher:
const mqtt = require('mqtt');
const client = mqtt.connect('mqtt://127.0.0.1:1883')
console.log("Before connection")
client.on("connect", function () {
console.log("Connected before interval")
setInterval(function () {
console.log("Before publish")
client.publish('NameOfTopic', 'Hello mqtt');
console.log('Message Sent');
}, 5000);
});
I know something is happening because when I kill publisher, broker gets also killed with error event on Socket instance, error number -4077, code econnreset