Avatar for Coder2012


Member since Jan 2015 • Last active Apr 2024
  • 16 conversations

Most recent activity

  • Avatar for Coder2012

    I've been away in Mexico, just updated and its working great. Thanks again Gordon, any news on the next Espruino Wifi or other products coming out?

  • Avatar for Coder2012

    Ahh good shout, seem I can use the standard MQTT library even if there's an error. So now instead of waiting for a successful connection (which never comes) I just run my subscribes in the on error handler instead.

    mqtt.on("error", (err) => {
        console.log("error", err);
        console.log("mqtt connected");
        lightsOn({r: 0, g: 128, b: 0}, speed);

    Doesn't matter that I receive an error NaN, everything works as expected afterwards. Thanks for supporting me on this Gordon its good enough for a home automation project I'm working on. Looking forward to getting the next Espruino you put out in the future.

  • in Pico / Wifi / Original Espruino
    Avatar for Coder2012

    c stands for clean session apparently.

    c0: This indicates the clean session status. "c0" means that the clean session is set to false. When a client connects with a clean session set to true (c1), it means the broker should not store any subscriptions or undelivered messages for the client when it disconnects. With clean session set to false (c0), the broker will store subscriptions and undelivered messages for the client.

    p stand for QoS. So p2 would be QoS level 2.

    Take it with a pinch of salt until I've verified this as it's a quick ChatGPT search

  • in Pico / Wifi / Original Espruino
    Avatar for Coder2012

    After a little more digging, I noticed I was sending defaults to MQTT and nothing to tinyMQTT.

    wifi.dbg() throws unhandled exception


    mqtt = require("tinyMQTT").create(server);
    mosquitto logs:
    1709312245: New client connected from as 29004900-0c513532-39333638 (p2, c0, k65535).
    K = keep_alive


    mqtt = require("MQTT").create(server, options);
    // tried different defaults in the options obj, nothing matters
    mosquitto logs:
    1709312100: New connection from on port 8883.
    1709312100: New client connected from as random (p2, c1, k10).


    tinyMQTT :
    Mosquitto says connected - YES
    Espruino says connected - YES
    Receive messages - YES

    Mosquitto says connected - YES
    Espruino says connected - NO (Connection Error)
    Receive messages - NO

    3rd part Android app
    Mosquitto says connected - YES
    Can publish messages - YES

    All using same server and port number

  • in Pico / Wifi / Original Espruino
    Avatar for Coder2012

    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 on port 8883.
    1708970867: New client connected from 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 = ""; // 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 = () => {
    const connect = () => {
      console.log("wifi connecting...");
      wifi.connect(WIFI_NAME, WIFI_OPTIONS, (err) => {
        if (err) {
          console.log("wifi error", err);
        console.log("wifi connected");
    const connectMQTT = () => {
      console.log("connecting to mqtt");
      mqtt = require("MQTT").create(server, options);
      mqtt.on("connected", () => {
        console.log("mqtt connected");
      mqtt.on("publish", (pub) => {
        console.log(pub.topic, pub.message);
      mqtt.on("error", (err) => console.log("error", err));

    Full output in Espruino IDE

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

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

  • in Pico / Wifi / Original Espruino
    Avatar for Coder2012

    Good news @allObjects I was able to connect this to via macOs and flash latest firmware, now this recognises perfect on Windows.