I am working on a project with multiple brokers, the first one is IBM IoT Watson, and the second one is my broker.
I am trying to connect to both of them, listen to changes to my broker, and publishing them to IBM Watson IOT.
I am using nodejs ibmiotf and mqtt.js,
here's the code:
const mqtt = require('mqtt');
const Client = require("ibmiotf");
const appClientConfig = require('../config').watsonIoTConfigs;
const rp = require('request-promise');
let appClient = new Client.IotfApplication(appClientConfig);
appClient.connect();
let myClient = new mqtt.connect('tcp://myserver', {
clientId: 'id222s2',
username: 'username',
password: 'password',
port: 221112,
will: {
topic: 'server_disconnected',
payload: "Server disconnected!, please call technical support",
qos: 2
}
});
appClient.on("connect", () => {
console.log('ibmiot connected');
appClient.subscribeToDeviceStatus();
appClient.subscribeToDeviceEvents();
});
myClient.on('message', function (topic, message) {
appClient.publish("topic1", "json", 'something') // here the ibmiotf disconnect
}
then I got this error once it tries to publish :
[BaseClient:connect] Iotfclient is offline. Retrying connection
And after that, it never connect and gives me :
Error : [ApplicationClient:publish] Client is not connected
what is the reason behind this?