-
Notifications
You must be signed in to change notification settings - Fork 2
Description
here is the node js code to connect the device that bind to the profile that use the Sparkplug, but leave bellow error, on my macOS.
if I change the profile to the default profile without Sparkplug, the connection is OK, how to fix that?
json@json-MacBook-Air SparkplugB % node test.js
error code: 3 error message: Connection refused: Server unavailable
error code: 3 error message: Connection refused: Server unavailable
const mqtt = require('mqtt');
const userName = 'xxxxxxxxxxxxxxxx';
const domain = 'thingsboard.cloud';
const port = 1883;
const brokerUrl = mqtt://${domain}:${port}
;
const options = {
username: userName,
port: port
};
const topic = 'spBv1.0/myGroup/DBIRTH/test_EON_Edge_001/sub_devices_002';
const protobufMessage = Buffer.from('0880a5e6baec311801', 'hex');
const client = mqtt.connect(brokerUrl, options);
client.on('connect', function () {
console.log('Connected successfully to the broker');
client.publish(topic, protobufMessage, { qos: 0 }, function (err) {
if (err) {
console.error('Publish error:', err.message);
} else {
console.log('Message published successfully');
}
client.end(); // Close the connection when done
});
});
client.on('error', (error) => {
console.error('error code:', error.code, "error message: ", error.message);
});