-
I've been using a single strip of 50 LEDs for years, but now I've connected a second string of 50 to the first set.
I've got a problem where green doesn't work on the second set, but red and blue work fine...
I tried the second set on their own and all colours were fine...
I'm using my EspWiFi for this.
-
-
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"); lightsOff(); lightsOn({r: 0, g: 128, b: 0}, speed); mqtt.subscribe("espruino/rgb"); mqtt.subscribe("espruino/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.
-
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
-
After a little more digging, I noticed I was sending defaults to MQTT and nothing to tinyMQTT.
wifi.dbg()
throws unhandled exceptiontinyMQTT:
mqtt = require("tinyMQTT").create(server); mosquitto logs: 1709312245: New client connected from 192.168.1.100:15450 as 29004900-0c513532-39333638 (p2, c0, k65535). K = keep_alive
MQTT:
mqtt = require("MQTT").create(server, options); // tried different defaults in the options obj, nothing matters mosquitto logs: 1709312100: New connection from 192.168.1.100:44568 on port 8883. 1709312100: New client connected from 192.168.1.100:44568 as random (p2, c1, k10).
Summary:
tinyMQTT :
Mosquitto says connected - YES
Espruino says connected - YES
Receive messages - YESMQTT
Mosquitto says connected - YES
Espruino says connected - NO (Connection Error)
Receive messages - NO3rd part Android app
Mosquitto says connected - YES
Can publish messages - YESAll using same server and port number
-
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?
-
Good news @allObjects I was able to connect this to via macOs and flash latest firmware, now this recognises perfect on Windows.
-
Hi @allObjects and @Gordon thank you for your time with this, I got the notification for updating to 2v20 in the Espruino web ide this morning, and now the Wifi module is connecting as expected again!
-
Hey that's great to hear you were able to reproduce this issue and also have a fix. How would I flash the device with this firmware, hopefully it can be done with the web ide?
@allObjects The link above to the espruino_2v19.123_wifi binary is 404 for me :(
I checked in github but can't see it in any of your repos.
-
Thank you for the reply, the low-level code above was taken from another post that Gordon commented on, he wanted to see what the wifi module reported back, so just to save time I decided to do the same.
The code I am actually running is as follows:
const WIFI_NAME = "<REDACTED>"; const WIFI_OPTIONS = { password : "<REDACTED>" }; const wifi = require("Wifi"); let mqtt; const server = "172.24.0.2"; // 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; let speed = 50; let rgb = {r: 128, g: 128, b: 128}; const leds = 12; let isActive = false; const onInit = () => { lightsOff(); lightsOn(rgb, 300); wifi.on('disconnected', connect); 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"); lightsOff(); lightsOn({r: 0, g: 128, b: 0}, speed); mqtt.subscribe("espruino/rgb"); mqtt.subscribe("espruino/speed"); // mqtt.subscribe("outdoor-motion-sensor"); }); mqtt.on("publish", (pub) => { switch (pub.topic) { case "espruino/rgb": rgb = JSON.parse(pub.message); lightsOff(); lightsOn(rgb, speed); break; case "espruino/speed": speed = pub.message; lightsOff(); lightsOn(rgb, speed); break; case "outdoor-motion-sensor": const activity = JSON.parse(pub.message).activity; if(isActive === activity){ return; }else{ isActive = activity; } const color = isActive ? {r: 255, g: 0, b: 0} : {r: 0, g: 255, b: 0}; speed = isActive ? 200 : 1000; lightsOff(); lightsOn(color, speed); break; } }); mqtt.on("error", (err) => console.log("error", err)); mqtt.connect(); }; const lightsOn = (color, speed) => { if (running) return; let rgb = new Uint8ClampedArray(leds * 3); let pos = 0; const 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(() => { A15.set(); require("neopixel").write(B15, getPattern()); A15.reset(); }, speed); running = true; }; const lightsOff = () => { clearInterval(id); let rgb = new Uint8ClampedArray(leds * 3); const 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; }; const 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; };
The error message is returned here:
if (err) { console.log("wifi error", err); return; }
```
-
I also took some time to try and debug using the following code I saw on another thread:
This is the code you said to try:
var WIFI_BOOT = A13; var WIFI_CHPD = A14; digitalWrite(WIFI_CHPD, 0); // turn off wifi var pins = { rx: A3, tx : A2 }; Serial2.on('data', function(d) { console.log("wifi:",JSON.stringify(d)); }); Serial2.setup(115200, { rx: A3, tx : A2 }); setTimeout(function() { digitalWrite(WIFI_BOOT, 1); // out of boot mode digitalWrite(WIFI_CHPD, 1); // turn on wifi }, 500);
And this is the output
>E.getAnalogVRef() =3.30846754005 > ____ _ | __|___ ___ ___ _ _|_|___ ___ | __|_ -| . | _| | | | | . | |____|___| _|_| |___|_|_|_|___| |_| espruino.com 2v19 (c) 2021 G.Williams > wifi: "r" wifi: "l\u0000l\u009C\u009E\u008E" wifi: "\u0002\u008Cb\u0003\u00E3n\f" wifi: "\f\f\u008C\u001C\u0080l" wifi: "\u00EC\u001Cp\u008C|\u008E\u0082" wifi: "\u009E\u0000\u00ECp\u0002\u0093r\u0093" wifi: "bl\fc\u008C" wifi: "p~\u00F2n\u009F\u0000l" wifi: "on\u009C\u0012b\fb" wifi: "\u001Cp\u008Clb\u000El" wifi: "slp\u00F2o" wifi: "\u00E0\u0082\u009C\u0000\f\f\u0082" wifi: "\u008E\u0080l\f\f\f\f" wifi: "\f\fb\fn" wifi: "\u00E3\u00E3nl\u00EC\u001C" wifi: "\u00E2\u008C\u008Ep\f\u008C|~" wifi: "\u00F2o\u00EE\u0002l\u008C\u008E" wifi: "\u0000l`\u0002" wifi: "\u0090" wifi: "\u0013\u0012on\f" wifi: "\u008Fsl\u000F\u0002o" wifi: "s\u008E\u0093\u009F\u00EF\u0003\f" wifi: "\f\u0002ll`\u0002" wifi: "p\u00F2o\u00E0\u0082\u009C\u0000\f" wifi: "\fr\u008C\u009C\u001C\u0093" wifi: "\u009C\u00E0\f\f\f\fb" wifi: "\fn\u00E3\u00E3n\u00EC" wifi: "\u008F\u009F\u008C\u008Fp\f\u008C|" wifi: "~\u00F3n\u00EF\u0003\f\u008E\u0000" wifi: "l`\u0002" wifi: "\u0090\u0012\u0013n" wifi: "o\f\u008Erl" wifi: "\u000E\u0002nr\u008E\u0092\u009E" wifi: "r\u0002\f\f\u0093\u009C\u00E0" wifi: "l`\u0003p\u00F2n\u00E0\u0083" wifi: "\u0002\f\fs\u008C" wifi: "\u009C\u001C\u0092\u009C\u00E0\u00EC\u001C\u0080" wifi: "\f\fc\fo\u00E2\u00E2o" wifi: "l\u008E\u0090\f\f" wifi: "b\u008C|\u007F\u00F2o\u00EE" wifi: "\u0002\f\u008F\u0000l`\u0003" wifi: "\u0090\u0012\u0013n" wifi: "o\fl`\u0002" wifi: "\u000E\u0002nr\u008F\u0092\u009Es" wifi: "\u0002\f\fs\u0002l" wifi: "`\u0002\u000Er\u0093\u009F" wifi: "s\u0002\f\fr\u0002" wifi: "l`\u0002rl\u008C" wifi: "\u008Co\u009C\u0000\u008Cp\u007F" wifi: "\u00F2n\u009E\u0000\u008C\u009E\u0012c" wifi: "r\u0013non" wifi: "\u008C\u001E\u0000l\u008Cb\u008E" wifi: "`\u008Cp\u0082lc\u000E" wifi: "l\u0000\f\u00ECl\u0080\u0093\u008C" wifi: "\u0003\u00ECl\u0080\u0092\u009C\u0012\u0082" wifi: "\u009C\u0000\f\f\f\f\f" wifi: "\u008C\u001E\u0000\f\u008E\u0080l" wifi: "ll\u007Frl\u0000\f" wifi: "\u00ECl\u0080\u0093\u008C\u0003l" wifi: "ln\u009C\u0012\u0002\f" wifi: "\f\f\f\f\f\u008C" wifi: "\u001E\u0000\f\u0090b\u00F2l" wifi: "\u000El\u0000\f\u00ECl\u0080\u0093" wifi: "\u008C\u0003\u008C\u0090p\u0012s" wifi: "\u0002n\u00EClbb" wifi: "\u0092\u009C\u0000\u008C\u008C\u0000ll" wifi: "\u00E0\u0002c\f\fll" wifi: "pc\u0082\u009E`l\u008E" wifi: "\u0082\u008C\u00ECb\frbr" wifi: "\u0082\u008C\u001Cnc\u0012c" wifi: "\u000Ell\u0092\u009Er\u0002" wifi: "\u0002\f\u009E~\u0003\u008C|" wifi: "\u0092\u00E2ol\u009E\u008E\u0092" wifi: "\u009C\u008C\u0012\f\f\u0002" wifi: "l\f\f\fl`" wifi: "\u0002rl" wifi: "r" wifi: "l\u008F\u0013\u0090o" wifi: "\u0002\u00CC\u00FF" wifi: "\r" wifi: "\nAi-Thi" wifi: "nker Tec" wifi: "hnology" wifi: " Co.,Lt" wifi: "d.\r\n" wifi: "\r" wifi: "\nready\r" wifi: "\n" wifi: "W" wifi: "IFI CON" wifi: "NECTED\r" wifi: "\n" wifi: "W" wifi: "IFI GOT" wifi: " IP\r\n"
-
I am trying to use my Esprunio Wifi, I just updated it to v2.19 firmware successfully and I am trying to connect to my wifi router, something I've done over 100 times in the past. Unfortunately i'm getting an error.
I saw that its possible now to update the Wifi firmware also, it does query the module and gets the current version but trying to update the firmware fails for some reason.
Not having much luck coming back to play with my devices both my Pico and the Esp Wifi giving me problems, hope someone can help me.
-
First of all I own the original Espruino board, Espruino Wifi and the Pico.
I've recently come back to do something on my Pico which hasn't been connected for a couple of years and now it won't connect via the web ide.
When I plug it into a USB port it is found and after about 5 - 10 secs it says its ready to go. Here's some screenshots that may help to debug the problem.
-
-
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.
-
-
@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?
-
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\u00FBJ\u00001\f\u0000\toccupancy0\u0090\u0003\u00FBK\u00001\u0012\u0000\u000Btemperature19.27
Which when decoded:
door1ûJ1 occupancy0ûK1temperature19.27
-
-
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();
-
-
I have a pixel ring and an Espruino WiFi firmware: 2v07.
I am doing some basics MQTT testing, I send a message from my Raspberry PI via an MQTT broker. It's extremely simple as follows:
topic: heartbeat
message: 0 || 1 driven by an occupancy sensor.Here's a snippet of where the values are received and output to the WebIDE:
function onInit() { 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("heartbeat"); }); mqtt.on('publish', function (pub) { console.log(pub.topic, pub.message); if(pub.message === '1') { lightsOn(); }else{ lightsOff(); } }); mqtt.connect(); }
I'll also include an image from another tool I debug topics/messages on Windows, this doesn't appear to show any malformed topic or message.
What is confusing is that i'm only subscribing to the "heartbeat" topic, so how could it even output something other than heartbeat? Like heartb1 or rtbeat1 as seen below!
Any idea what could be causing this, or where to even start debugging something like this using the MQTT library for Espruino?
Thanks, Neil
Oh that's an idea, I'll try the second strip at the beginning...
When you say to use a different pin for the second set, how would this work in code? Would I just keep an index and switch the pin number when I'm in the range of that strip?
Finally, do you have any ideas when new products are being launched as I think the WiFi is getting updated correct?