Avatar for Coder2012

Coder2012

Member since Jan 2015 • Last active May 2021
  • 12 conversations
  • 47 comments

Most recent activity

  • in Pico / Wifi / Original Espruino
    Avatar for Coder2012

    Thanks Gordon, this does indeed speed things up a little bit.

  • in Pico / Wifi / Original Espruino
    Avatar for Coder2012

    I have an Espruino Wifi which I've used with WS2811 which performs really well. I've been testing a new neopixel strip of 144 LEDs but they are painfully slow like even with an interval of 10ms they barely change colour every half second. The brightness and colours are fine, just updating too slow.

    I've also tried to power the strip separately from the Espruino Wifi but that also makes no difference.

    I've been using the pattern examples on the main Espruino site to test my hardware. If there are any tips to improve the speed I'm all ears.

  • in Pico / Wifi / Original Espruino
    Avatar for Coder2012

    Tested for a half hour here, I assume I picked up the latest MQTT with my require statement. All looks good to me Gordon, thank you for taking the time to fix this.

  • in Pico / Wifi / Original Espruino
    Avatar for Coder2012

    @MaBe There's a screenshot in my original post, which is from MQTT Explorer which is on Windows, this shows the values as correct that arrive from the broker.

    In my latest screenshot, on the left in white is the output from node-red which also looks correct. Do you think that this could indicate corruption somewhere on the Espruino side?

  • in Pico / Wifi / Original Espruino
    Avatar for Coder2012

    @Gordon

    I've commented out the calls to update the neopixel and I'm still getting strange chars appearing. Although it did fix my issue with the basic example, oddly I can still replicate this without the neopixel writes.

    I am debugging the wifi data and these chars do come through there it seems:

    \u0007\u0000\u0004door1\u0090\u0003\u00F­BJ\u00001\f\u0000\toccupancy0\u0090\u000­3\u00FBK\u00001\u0012\u0000\u000Btempera­ture19.27
    

    Which when decoded:

    door1ûJ1	occupancy0ûK1temperature19.27
    
  • in Pico / Wifi / Original Espruino
    Avatar for Coder2012

    With tinyMQTT library I get the following chars:

  • in Pico / Wifi / Original Espruino
    Avatar for Coder2012

    I seem to get additional characters now as per below:

    Here is my src, just incase there's anything else that could be contributing to this problem. Once again I don't see any issues in the MQTT traffic tool I use on Windows.

    const server = "192.168.1.64"; // the ip of your MQTT broker
    const options = {
      // ALL OPTIONAL - the defaults are below
      client_id: "random", // the client ID sent to MQTT - it's a good idea to define your own static one based on `getSerial()`
      keep_alive: 60, // keep alive time in seconds
      port: 1883, // port number
      clean_session: true,
      username: "username", // default is undefined
      password: "password", // default is undefined
      protocol_name: "MQTT", // or MQIsdp, etc..
      protocol_level: 4, // protocol level
    };
    
    let id = null;
    let temp = 0;
    let running = false;
    const leds = 12;
    
    function onInit() {
      lightsOff();
      lightsOn(getRndColor(), 300);
    
      wifi.connect(WIFI_NAME, WIFI_OPTIONS, function (err) {
        if (err) {
          return;
        }
        startMQTT();
      });
    }
    
    function startMQTT() {
      mqtt = require("MQTT").create(server, options);
    
      mqtt.on("connected", function () {
        mqtt.subscribe("door");
        mqtt.subscribe("occupancy");
        mqtt.subscribe("temperature");
      });
    
      mqtt.on("publish", function (pub) {
        console.log(pub.topic, pub.message);
        switch (pub.topic) {
          case "door":
            if (pub.message === "2") {
              lightsOff();
              lightsOn({ r: 80, g: 0, b: 0 }, 50);
            }
            break;
    
          case "occupancy":
            if (pub.message === "1") {
              lightsOff();
              lightsOn({ r: 0, g: 80, b: 0 }, 100);
            }
            break;
    
          case "temperature":
            temp = Number(pub.message);
            lightsOff();
            switch (true) {
              case temp <= 18:
                lightsOff();
                lightsOn({ r: 3, g: 171, b: 255 }, 200);
                break;
    
              case temp > 18 && temp < 20:
                lightsOff();
                lightsOn({ r: 255, g: 162, b: 0 }, 200);
                break;
    
              case temp >= 20:
                lightsOff();
                lightsOn({ r: 255, g: 0, b: 0 }, 200);
                break;
            }
            break;
        }
      });
    
      mqtt.connect();
    }
    
    function lightsOn(color, speed) {
      if (running) return;
    
      let rgb = new Uint8ClampedArray(leds * 3);
      let pos = 0;
    
      function getPattern() {
        pos = (pos + 1) % leds;
    
        rgb[pos * 3 + 0] = color.g;
        rgb[pos * 3 + 1] = color.r;
        rgb[pos * 3 + 2] = color.b;
    
        for (var i = 0; i < leds * 3; i++) rgb[i] *= 8 / leds;
    
        return rgb;
      }
    
      id = setInterval(function () {
        A15.set();
        require("neopixel").write(B15, getPattern());
        A15.reset();
      }, speed);
      running = true;
    }
    
    function lightsOff() {
      clearInterval(id);
      let rgb = new Uint8ClampedArray(leds * 3);
    
      function getReset() {
        for (let i = 0; i < rgb.length; ) {
          rgb[i++] = 0;
          rgb[i++] = 0;
          rgb[i++] = 0;
        }
        return rgb;
      }
    
      A15.set();
      require("neopixel").write(B15, getReset());
      A15.reset();
      running = false;
    }
    
    function getRndColor() {
      let color = {
        r: Math.round(Math.random() * 255 + 25),
        g: Math.round(Math.random() * 255 + 25),
        b: Math.round(Math.random() * 255 + 25),
      };
      return color;
    }
    
    onInit();
    
  • in Pico / Wifi / Original Espruino
    Avatar for Coder2012

    @Gordon

    Unfortunately, after adding more subscriptions to other topics, the problem seems to be happening again. Sorry for the delay replying.

Actions