-
-
-
I'm publishing the same topic over and over again, using the node mqtt module on my computer, and occasionally I'm getting incomplete data printed out in Espruino. I assume the Espruino MQTT code is to blame because the client matched on the topic, yet the output doesn't match.
{ "topic": "sb_platform/v1/tes_16002b00", "message": "100", "dup": 0, "qos": 0, "retain": 0 } 100 Connection refused, unknown return code: 115. { "topic": "sb_platform/v1/tes_16002b00", "message": "100", "dup": 0, "qos": 0, "retain": 0 } 100 { "topic": "sb_platform/v1/tes_16002b00", "message": "100", "dup": 0, "qos": 0, "retain": 0 } 100 { "topic": "sb_platform/v1/tes_16002b00", "message": "100", "dup": 0, "qos": 0, "retain": 0 } 100 MQTT unsupported packet type: 0 [MQTT]0,27,115,98,95,112,108,97,116,102,111,114,109,47,118,49,47,116,101,115,95,49,54,48,48,50,98,48,48,49,48,48 { "topic": "sb_platform/v1/tes_16002b00", "message": "10", "dup": 0, "qos": 0, "retain": 0 } 10 { "topic": "sb_platform/v1/tes_16002b00", "message": "100", "dup": 0, "qos": 0, "retain": 0 } 100 { "topic": "sb_platform/v1/tes_16002b00", "message": "100", "dup": 0, "qos": 0, "retain": 0 } 100 { "topic": "sb_plat", "message": "", "dup": 0, "qos": 0, "retain": 0 } MQTT unsupported packet type: 6 [MQTT]102,111,114,109,47,118,49,47,116,101,115,95,49,54,48,48,50,98,48,48,103,111
-
-
I didn't know it has that feature! Trying it now, but seem to be having troubles.
Using first port, {"path":"/dev/cu.usbmodem1421","usb":[1155,22336],"description":"Espruino board"} Connecting to '/dev/cu.usbmodem1421' Connected Espruino.Core.Utils.getURL: got HTTP status code 404 for http://www.espruino.com/modules/NetworkJS.min.js Espruino.Core.Utils.getURL: got HTTP status code 404 for http://www.espruino.com/modules/net.min.js Espruino.Core.Utils.getURL: got HTTP status code 404 for http://www.espruino.com/modules/net.js Module net not found Espruino.Core.Utils.getURL: got HTTP status code 404 for http://www.espruino.com/modules/NetworkJS.js Module NetworkJS not found
I'll probably figure out why this happens. I see these same messages sometimes in the IDE, but it's fixed if I
reset();save();
. -
To get into the bootloader you just power the board up with the button held down - does that not work?
It does not appear to be working. What does the yellow LED mean?
For modules that have to be loaded off the internet you have to use the right-hand side of the IDE so the IDE can detect their use and load them automatically. The left-hand side goes direct to the Espruino Board, so if it doesn't know about a module it's unable to load it.
Ya, see how it works now.
It'd be worth going through the quick start and a few of the Espruino Pico tutorials - I think a lot of this stuff is covered already there - it might save you some time :)
I did when I got my first board. I saw the section about save and onInit at the time, but I didn't try it out, and I forgot those features existed. I don't learn well by reading, I learn by doing, which is apparently uncommon among developers. FWIW, the Lodash project documentation is really easy to work with. Would be super if Espruino could have similar documentation at some point in the future.
-
Would be nice if there was a way to have the right panel load from my file before sending to Espruino. I would be able to work in my preferred editor, Sublime Text. The Web IDE has a clumsy aspect to it (at least one Macs) because it's a Chrome App, so changing to Chrome using CMD + Tab brings the Web IDE to the front, covering all of Chrome (since I'm on a laptop the majority of the time). So I then have to hit CMD + ` (this hotkey is for changing between multiple windows of the same program on Macs).
I tried the Web IDE in a tab for the first time just now, but it can't find my Espruino.
I guess that for now, I'll just have to use another browser besides Chrome, when I'm working with Espruino.
-
-
Ooohhhhhh, it works. I understand now.
Instead of typing
require("EspruinoWiFi")
in the left pane, it has to go in the right pane:var wifi = require("EspruinoWiFi");
Press
Send to Espruino
dump() // left pane var wifi = { "connect": function (a,b,c) {var f="";void 0!==b.password&&(f=b.password);m(1,function(b){if(b)return c(b);d.cmd("AT+CWJAP="+JSON.stringify(a)+","+JSON.stringify(f)+"\r\n",2E4,function x(a){if(0<=["WIFI DISCONNECT","WIFI CONNECTED","WIFI GOT IP","+CWJAP:1"].indexOf(a))return x;"OK"!=a?setTimeout(c,0,"WiFi connect failed: "+(a?a:"Timeout")):setTimeout(c,0,null)})})}, "disconnect": function () {r(1)}, "getIP": function (a) {var b={};d.cmd("AT+CIFSR\r\n",1E3,function f(d){if(void 0===d)a("Timeout");else{if("+CIFSR:STAIP"==d.substr(0,12))b.ip=d.slice(14,-1);else if("+CIFSR:STAMAC"==d.substr(0,13))b.mac=d.slice(15,-1);else if("OK"==d){a(null,b);return}return f}})}, "startAP": function (a,b,c) { b=b||{};if(!b.password||8>b.password.length)throw Error("Password must be at least 8 characters");var f=b.password?"3":"0";if(b.authMode&&(f={open:0,wpa:2,wpa2:3,wpa_wpa2:4}[b.authMode],void 0===f))throw Error("Unknown authMode "+ b.authMode);void 0===b.channel&&(b.channel=5);m(2,function(e){if(e)return c(e);d.cmd("AT+CWSAP="+JSON.stringify(a)+","+JSON.stringify(b.password)+","+b.channel+","+f+"\r\n",5E3,function(a){"OK"!=a?c("CWSAP failed: "+(a?a:"Timeout")):c(null)})}) }, "stopAP": function () {r(2)}, "scan": function (a) { var b=[];m(1,function(c){if(c)return a(c);d.cmdReg("AT+CWLAP\r\n",5E3,"+CWLAP:",function(a){a=a.slice(8,-1).split(",");b.push({ssid:JSON.parse(a[1]),authMode:w[a[0]],rssi:parseInt(a[2]),mac:JSON.parse(a[3]), channel:JSON.parse(a[4])})},function(c){a(null,b)})}) } }; =undefined
So if I upload code that isn't messed up (trying to support
__non_webpack_require__
causes issues) I think this will work once again.Getting into bootloader probably not working still :(
-
I think I fixed it!
Reading other threads, learned about
dump()
.>dump() // Code saved with E.setBootCode var WIFI_NAME = "XXXXXX"; var WIFI_PASS = "XXXXXX"; var MQTT_HOST = "192.168.1.145"; if (typeof __non_webpack_require__ == 'undefined') { var __non_webpack_require__ = require; } var mqtt = __non_webpack_require__("MQTT"); var wifi = __non_webpack_require__("EspruinoWiFi"); var client = mqtt.create(MQTT_HOST); client.on('connected', function() { client.subscribe("root/branch"); }); client.on('publish', function(pub) { console.log("topic: "+pub.topic); console.log("message: "+pub.message); }); wifi.connect(WIFI_NAME, { password: WIFI_PASS }, function(err) { if (err) { console.log("Connection error: "+err); return; } console.log("Connected!"); client.connect(); }); =undefined
That's my project code! And a clue!
// Code saved with E.setBootCode
.Let's try this then...
>E.setBootCode('') Erasing Flash... Writing... Compressed 114368 bytes to 8 Checking... Done! =undefined >dump() =undefined >
Hooray! Right?
>var wifi = require('EspruinoWiFi') ERROR: SD card must be setup with E.connectSDCard first WARNING: Module "EspruinoWiFi" not found =undefined >
fml
-
I'm working with an Espruino WiFi.
The board seems be working correctly when I run code in the left panel.
However,
require('EspruinoWiFi')
throwsERROR: SD card must be setup with E.connectSDCard first WARNING: Module "EspruinoWiFi" not found
And same result with MQTT. So I try to clear flash.
>reset() =undefined >save() =undefined Erasing Flash... Writing....... Compressed 114368 bytes to 4278 Checking... Done! ERROR: SD card must be setup with E.connectSDCard first WARNING: Module "MQTT" not found ERROR: SD card must be setup with E.connectSDCard first WARNING: Module "EspruinoWiFi" not found Uncaught Error: Field or method "create" does not already exist, and can't create it on undefined at line 11 col 18 var client = mqtt.create(MQTT_HOST);
The last line,
var client = mqtt.create(MQTT_HOST);
is some code from my project. I'm not able to clear it from flash.Also tried
E.setBootCode()
, then save, same result. Also triedE.setBootCode()
, reset, save, still no luck.Decided to try a fresh update. Holding down BTN1, plug in power, see yellow LED for 2s, see red LED flash, then no LED's lit. Can't get into bootloader mode it seems. Also not finding documentation for yellow LED.
-
-
Well, I have been concerned about how Espruino will be profitable for you when marketing to professional users. I have a startup and no funding, pre-revenue, but if you have a support package at the right price for us, I'm happy to buy.
What code I have written, I've shared. Much of what you're developing is too technical for me to contribute to, but I have been a participant where possible.
You mention the interest in having the Espruino in the product being exposed for end users to access. That's a part of my goals as well, for what I'm building.
Will follow up in private message. Thanks for the lengthy and thoughtful response.
-
Here's the output that I get when I run the minified code from terminal:
=undefined Connected! Uncaught Error: Field or method "connect" does not already exist, and can't create it on undefined at line 1 col 86 ...g("Connected!"),void client.connect()) ^ in function called from system
If I paste the unminified code into the web IDE, it works.
-
Here's the code before minifying.
;(function(){ var WIFI_NAME = "XXXXXX"; var WIFI_PASS = "XXXXXX"; var MQTT_HOST = "192.168.1.145"; var mqtt, wifi; mqtt = __non_webpack_require__("MQTT"); wifi = __non_webpack_require__("EspruinoWiFi"); var client = mqtt.create(MQTT_HOST); client.on('connected', function() { client.subscribe("root/branch"); }); client.on('publish', function(pub) { console.log("topic: "+pub.topic); console.log("message: "+pub.message); }); wifi.connect(WIFI_NAME, { password: WIFI_PASS }, function(err) { if (err) { console.log("Connection error: "+err); return; } console.log("Connected!"); client.connect(); }); })();
-
Here's some code that webpack and uglify produced, but Espruino web IDE says it has a lot of problems. I don't see what's wrong with it though.
!function(modules){function __webpack_require__(moduleId){if(installedModules[moduleId])return installedModules[moduleId].exports;var module=installedModules[moduleId]={exports:{},id:moduleId,loaded:!1};return modules[moduleId].call(module.exports,module,module.exports,__webpack_require__),module.loaded=!0,module.exports}var installedModules={};return __webpack_require__.m=modules,__webpack_require__.c=installedModules,__webpack_require__.p="",__webpack_require__(0)}([function(module,exports,__webpack_require__){!function(){var mqtt,wifi,WIFI_NAME="XXXXXX",WIFI_PASS="XXXXXX",MQTT_HOST="192.168.1.145";mqtt=require("MQTT"),wifi=require("EspruinoWiFi");var client=mqtt.create(MQTT_HOST);client.on("connected",function(){client.subscribe("root/branch")}),client.on("publish",function(pub){console.log("topic: "+pub.topic),console.log("message: "+pub.message)}),wifi.connect(WIFI_NAME,{password:WIFI_PASS},function(err){return err?void console.log("Connection error: "+err):(console.log("Connected!"),void client.connect())})}()}]);
-
What ultimately is the grand vision for the Espruino project? Is it ultimately the hope that Espruino will be adopted by professionals and used in a lot of consumer products? Or is it intended to be more of an intro-to-embedded devices product?
First of all, I hope it's the former. And it's incredibly impressive what @Gordon has been able to build here. I get the impression that he's single-handedly building the entire embedded JS platform, which is f****g amazing. Something I could never do, I'm just a simple JS developer and inventor.
But certain aspects of the project lead me to wonder if the latter might be a bit true, or if there's a little less focus on one over the other, than there probably should be. For example, the graphical editor seems to me like more of a nice-to-have than a mission-critical sort of feature. And to a lesser extent, the web IDE also. It's really great that I can paste some code into a box, hit run, and see it just works. That's awesome. But once I've decided to start building my product, with Espruino at the heart of it, I'm not going to be working in the web IDE. I use Sublime Text, and the web IDE doesn't have any of the productivity features I use. Performing a copy-paste every time I want to run my code is nuts. I'm confused why there didn't already exist a CLI tool to solve this. True, there is a CLI Espruino tool, but none of the needed features were included.
My point is this: I would have expected the most important features of the web IDE to be available from CLI before a graphical editor was made, if the focus is on professionals. I think that having a focus on professionals will be important to the success of Espruino in general.
There's a couple other items I'd like to draw attention to.
I've been playing with MQTT and my impression is that this interface isn't as much of a priority as other issues. For an IoT platform product, this seems like an important thing to not only support but have in a very robust state. I would think that MQTT + encryption would be very important for professional applications.
I do realize of course that there's zillions of applications for Espruino's, and people building robots will probably care a lot about motor controller stuff before they care about MQTT. And this actually goes to my point, which is that Gordon is taking on sooooo much, I think it's really important to not build certain things, like a graphical editor. The cost of having a graphical editor is not just building it, but then supporting it over time. Case in point, in this thread:
http://forum.espruino.com/conversations/298305/#comment13410511
It's because the Web IDE was originally made as a website where each file executed in the same scope, and adds itself to the global 'Espruino' variable - I can't just 'require()' everything as-is. Ideally I'd rewrite every file to handle both loading styles, but I don't have the time to do that while also checking it still works fine as a Chrome App, NWjs app, and on the Espruino website.
Gordon, I'm concerned that you've stretched yourself too thin. I would like to offer the friendly suggestion that you even go so far as to drop support for some things, just so you can focus on the truly important areas. Aside from features like this/that whatever for MQTT/BLE whatever, I think unit tests should be in place and with complete code coverage. I use Istanbul and recommend it. I haven't looked at the core Espruino code and don't know if it has tests, but it looks like the Espruino IDE and CLI doesn't have tests.
The thing I'm building is a medical product, and so scrutiny is going to be especially high. JS already has a bad rap (which isn't deserved), but should detractors take a very close look at Espruino under the hood, I worry that the criticisms will be a long list. I suspect people will make blanket criticisms that the system is not robust enough for professional use.
The value of having JS at the heart of the product is the added agility, so it makes great sense to use Espruino as much as possible. Also, the ability to build the product and services all in one language is again a major asset. So my strong preference is to continue using Espruino even in my end product. But overall robustness is a real concern for me.
The web IDE has been buggy lately, and I don't know what's going on. Occasionally the output pane becomes unresponsive, and I have to restart the editor. Then this other issue, I just saw this mystery error tonight:
Connected Uncaught Error: String too big to convert to float at line 1 col 6341 ....stringify(process.env),">>",">") ^
^ not in my code. No idea where this is coming from.
-
Couldn't you automate detection of the Espruino so that the port doesn't have to be entered manually? Even just changing to a different USB port will cause this value to change. In the script that I wrote for this, I copied the code that the web IDE uses to identify Espruino boards and connect to the corresponding port:
https://github.com/stokebrain/morra-build/blob/master/main.js#L23Webpack also has tree-shaking. When I first tried rollup, I concluded it wasn't a good choice because I saw that it was placing top-level variables from all modules, all together in the same scope. I was too concerned about name collision and went back to webpack.
Also, I don't see the smaller footprint that rollup is claiming.
https://vkbansal.me/blog/rollup-first-impressions/I continually see people writing that rollup configuration is easier, but that has not been true for me. Webpack just worked, and rollup continues to require debugging.
I still have some complaints and issues to solve with webpack. For my first project it all worked well, but in my current MQTT test, I'm getting errors when using my build-and-save script. One thing that concerns me is the use of arrays in the build, because I don't know if these will cause performance issues for Espruino.
-
-
Trying to use test.mosquitto.org/. I get a message saying "not authorized". Upon visiting their page, it says I need to use the cert, even for the unencrypted ports. On Espruino.com/MQTT, it says encryption and authentication are not implemented. So Espruino just doesn't work with the public brokers right now?
Below is the code I was using. Instead I'm using Mosca on local now and I have a working connection.
var WIFI_NAME = "XXXXXX"; var WIFI_PASS = "XXXXXX"; var wifi = require("EspruinoWiFi"); var broker = "37.187.106.16"; var options = { client_id : "random", keep_alive: 60, port: 1883, clean_session: true, username: "username", password: "password", protocol_name: "MQTT", protocol_level: 4, }; var mqtt = require("MQTT").create(broker, options); mqtt.on('connected', function() { mqtt.subscribe("test/espruino"); }); wifi.connect(WIFI_NAME, { password: WIFI_PASS }, function(err) { if (err) { console.log("Connection error: "+err); return; } console.log("Connected!"); mqtt.connect(); });
-
-
It has to be happening in the battery circuit, because there's no other circuit between the Espruino and the battery cells, except for that built-in circuit. The PCB's power LED goes out, and the Espruino disconnects from my computer and disappears from available devices.
I changed the wiring so that the Espruino isn't powered by the battery, but via USB only, and the battery is lasting and functioning properly. What it's powering is the PCB which has the fuel gauge and a couple I2C devices.
It's an ugly hack, but I'm on a deadline and this arrangement allows me to power the Espruino off an external USB battery pack.
-
Black battery wire to GND, red battery wire to VUSB. The wires soldered into the back side of the JST connector where the battery plugs into the PCB. There's a fuel gauge in the circuit, but I think that's just for charging. I used a modified USB cable so that the ground and V+ from the computer is not connected, only the data lines are connected. My PCB was designed with a USB connector on it for charging the battery, so I provide the USB power there, until I get the board redesigned.
-
I think my Li+ battery regulator circuit is cutting off power after about 30s of operation. This is the battery. I assume the Espruino Wifi (along with the other slave devices on a PCB) are drawing too much current. How do I select an appropriate battery? This battery is sufficient for just the slave devices on the PCB alone.
@user75453, my mistake, I haven't tried your github code. I tried the code snippet you show in reply #21. I hope the fix makes it into the official Espruino MQTT module.