Crash with MQTT
-
I have been using MQTT properly with the following code for a long time, and then yesterday I noticed my buttons weren't responding and when checking the Flic Hub Studio console I see that my script is crashing over and over again when running
mqttClient.connect()
with the following error:TypeError: Invalid type at invoke (native) at connectWithHostAndPort (core.js:1273) at <anonymous> (core.js:1332) at func (core.js:2325) at nextTickHandler (core.js:2334)
Here is my whole MQTT code, and I am using the latest version of
mqtt.js
that is posted on https://github.com/50ButtonsEach/flic-hub-sdk-mqtt-jsconst mqttClient = require('./mqtt').create(mqttBroker, {username: mqttUsername, password: mqttPassword}) // https://github.com/50ButtonsEach/flic-hub-sdk-mqtt-js mqttClient.on('connected', () => { console.log(`Connected to MQTT Broker ${mqttBroker}`) mqttClient.subscribe('[TOPIC]') }) mqttClient.on('disconnected', () => { throw new Error(`DISCONNECTED from MQTT Broker ${mqttBroker}`) // Error to restart script if disconnected from MQTT broker. }) mqttClient.on('publish', (pub) => { console.log(`\nReceived MQTT Message on Topic: ${pub.topic}\n${pub.message}`) // Handle button actions here. }) mqttClient.connect() setInterval(() => { if (!mqttClient.connected) throw new Error('MQTT Broker NOT CONNECTED') }, 900000) // Check every 15 minutes that MQTT Broker is connected, and throw error to restart script if not. // This check is important if fails to connect to MQTT Broker at launch, when the "disconnected" event would never be sent.
-
I just noticed this post https://community.flic.io/topic/18577/mqtt-issue-on-firmware-version-4-4-5 and updated Flic Hub to version 4.4.6 which appears to have solved the crash.