• I am using my Espruino Wifi updated to 2v21. I have a strange problem, although I have used the MQTT library before without any problems, it seem to error for me now. I am able to connect and use tinyMQTT but I want to use QoS > 0 which is only available in MQTT.

    I am running mosquitto in a container on my raspberrypi. If I try to connect using the MQTT library I get the following output:

    Log from the mosquitto container:
    1708970867: New connection from 192.168.1.100:44538 on port 8883.
    1708970867: New client connected from 192.168.1.100:44538 as 29004900-0c513532-39333638 (p2, c1, k60, u'username').

    Log from Espruino IDE:
    Connection refused, unknown return code: NaN.

    Here is the code for the MQTT example:

    const WIFI_NAME = "BT-redacted";
    const WIFI_OPTIONS = { password : "redacted" };
    const wifi = require("Wifi");
    let mqtt;
    
    const server = "192.168.1.77"; // the ip of your MQTT broker
    const options = {
      client_id: getSerial(),
      keep_alive: 60,
      port: 8883,
      clean_session: true,
      username: "username",
      password: "password",
      protocol_name: "MQTT",
      protocol_level: 4,
    };
    
    const onInit = () => {
      connect();
    };
    
    const connect = () => {
      console.log("wifi connecting...");
      wifi.connect(WIFI_NAME, WIFI_OPTIONS, (err) => {
        if (err) {
          console.log("wifi error", err);
          return;
        }
        console.log("wifi connected");
        connectMQTT();
      });
    };
    
    const connectMQTT = () => {
      console.log("connecting to mqtt");
      mqtt = require("MQTT").create(server, options);
    
      mqtt.on("connected", () => {
        console.log("mqtt connected");
        mqtt.subscribe("espruino/rgb");
        mqtt.subscribe("espruino/speed");
      });
    
      mqtt.on("publish", (pub) => {
        console.log(pub.topic, pub.message);
      });
    
      mqtt.on("error", (err) => console.log("error", err));
      mqtt.connect();
    };
    

    Full output in Espruino IDE

     ____                 _
    |  __|___ ___ ___ _ _|_|___ ___
    |  __|_ -| . |  _| | | |   | . |
    |____|___|  _|_| |___|_|_|_|___|
             |_| espruino.com
     2v21 (c) 2023 G.Williams
    >
    >onInit()
    wifi connecting...
    =undefined
    wifi connected
    connecting to mqtt
    error Connection refused, unknown return code: NaN.
    > 
    

    What could be different about MQTT v tinyMQTT for me now?

About

Avatar for Coder2012 @Coder2012 started