• dev
  • Nodejs MQTT implementation issue

Hi!

I'm having trouble with mqtt implementation in nodejs. I'm connecting with the example nodejs script, with a clean:false setting:

const mqtt = require('mqtt');

const client = mqtt.connect('mqtts://mqtt.flespi.io:8883', {
  clientId: 'flespi-examples-mqtt-client-nodejs',
  // see https://flespi.com/kb/tokens-access-keys-to-flespi-platform to read about flespi tokens
  username: `FlespiToken ${process.env.FlespiToken}`,
  protocolVersion: 5,
  clean: false
});

But when I check the settings of the session, it clearly says, it's a clean session:

{
  "result": [
    {
      "size": 0,
      "ip": "37.76.123.229",
      "id": 2761155786,
      "connected": true,
      "cid": 2042338,
      "clean": true,
      "client_id": "flespi-examples-mqtt-client-nodejs",
      "expires": 0
    }
  ]
}

I don't really see what could be the problem here...

    • Edited

    Hello. Try adding the parameter to the configuration:

    sessionExpiryInterval: 600

    Example:

    const mqtt = require('mqtt');
    
    const client = mqtt.connect('mqtts://mqtt.flespi.io:8883', {
      clientId: 'flespi-examples-mqtt-client-nodejs',
      // see https://flespi.com/kb/tokens-access-keys-to-flespi-platform to read about flespi tokens
      username: `FlespiToken ${process.env.FlespiToken}`,
      protocolVersion: 5,
      clean: false,
      properties: {
        sessionExpiryInterval: 600
      }
    });

    By the way, our AI assistant in the chat on flespi.io (upper right corner) handles such questions very well. ;)

    Thanks, it solves it indeed!

    Will check the AI assistant too!

    Write a Reply...