Flic Home

    Community

    • Login
    • Search
    • Popular
    • Users

    Crash with MQTT

    Flic Hub SDK
    1
    2
    114
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • pico
      pico last edited by pico

      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-js

      const 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.
      
      1 Reply Last reply Reply Quote 0
      • pico
        pico last edited by

        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.

        1 Reply Last reply Reply Quote 0
        • First post
          Last post