-
• #2
sorry, Hi, all
in web IDE if I put
require("Encoder").connect(A1,A2,function (direction) {
step += direction;
print(step);
});
i get
ERROR: Function not found! Skipping. at line 1 col 20
require("Encoder").connect(A1,A2,function (direction) {
at the moment I have connected internet
Gordon, what can be problem? -
• #3
IDE is from chrome store
-
• #4
Hi Andrey,
That's you problem I'm afraid. We haven't uploaded the latest version to the Chrome Web Store yet. However if you install the version from GitHub it should work:
https://github.com/espruino/EspruinoWebIDE
You will probably need to install an espruino-nightly image as well
-
• #5
Last night i was playing around with my just arrived and shiny new two Espruino boards. With the pack of two and included NRF24L01P wireless modules, I had the exact same issue when my code did try to load the NRF module as described on the corresponding Espruino page (http://www.espruino.com/NRF24L01P).
Since Gordons last answer to this issue is 2 month old I would like to ask if we still have to install the Espruino WebIDE from GitHub for this issue to resolve?
Is it easier to run the modules from an microSD card or would the WebIDE be the recommended start with Espruino? Previously I did use Espruino on my Olimex-STM32 and the WebIDE. But the 100% CPU bug contuinously forced me to do a complete restart of Chrome after some time. So currently the WebIE is not my real favorite way to go.
P.S.: It is cool to finally have the real boards in my hands after following this project for all the time. Nice work and keep up that great project!
-
• #6
Hi #kai,
Thanks!
The Web IDE in the Chrome Web Store has been able to do this for a month or more. Is it just that you pasted the code into the left-hand side rather than the right? The Web IDE doesn't parse the code you type on the left so it doesn't load the module.
If you don't want to use the right-hand side, just type:
require("NRF24L01P")
on the right-hand side and clickSend to Espruino
. That'll load the module, and then you can use the left-hand side as normal.Web IDE is definitely recommended. Stick with it as in a month or so Chrome will update and it'll fix the 100% CPU issue (or you can install Chrome Canary if you can't wait).
You can load modules off of micro SD, but honestly it's not recommended as you're always sure to get the newest version if you do it with the Web IDE.
-
• #7
Hi Gordon,
no I did paste the code to the right pane of the WebIDE. The following is what i am doing exactly...
Left pane right after startup of the WebIDE and connecting to my Espruino boardConnected =undefined >trace() #1[r1,l1] Object { #4[r1,l0] Name: '>timers' #5[r2,l0] Array [ ] #6[r1,l0] Name: '>watches' #7[r2,l0] Array [ ] #9[r1,l0] Name: '>history' #10[r1,l0] Array [ #11[r1,l0] Name: int 0 #8[r1,l0] String echo(0); #14[r1,l0] Name: int 1 #16[r1,l0] String console.log(\"<<\"+\"<<<\"+JSON.stringify(process.env)+\">>>\"+\">>\"); #25[r1,l0] Name: int 2 #48[r1,l0] String echo(1); ] #13[r1,l0] Name: 'console' #12[r1,l0] Function { } #15[r1,l0] Name: 'JSON' #21[r1,l0] Function { } #24[r1,l0] Name: 'process' #23[r1,l0] Function { } } =undefined >
Right pane holds the slightly enhanced example code for the NRF24L01P module...
SPI1.setup({sck:A5, miso:A6, mosi:A7}); var nrf = require("NRF24L01P").connect(SPI1, B0, B1); function onInit() { print(nrf); if (typeof nrf != "undefined") { nrf.init([0,0,0,0,1], [0,0,0,0,2]); print("NRF Library loaded!"); } else { print("Error! NRF Library not loaded!"); } } onInit(); setInterval(function() { nrf.slaveHandler(); }, 50);
After sending the code to the Espruino the following shows up in the left pane of the WebIDE:
>reset(); =undefined _____ _ | __|___ ___ ___ _ _|_|___ ___ | __|_ -| . | _| | | | | . | |_____|___| _|_| |___|_|_|_|___| |_| http://www.espruino.com 1v47 Copyright 2014 Gordon Williams ------------------------------------------- >echo(0); ERROR: Function not found! Skipping. at line 1 col 32 var nrf = require("NRF24L01P").connect(SPI1, B0, B1); ^ undefined Error! NRF Library not loaded! =undefined ERROR: Using '.' operator on non-object at line 2 col 8 nrf.slaveHandler(); ^ at line 2 col 21 nrf.slaveHandler(); ^ in function called from system ERROR: Using '.' operator on non-object at line 2 col 8 nrf.slaveHandler(); ^ at line 2 col 21 nrf.slaveHandler(); ^ in function called from system ERROR: Using '.' operator on non-object at line 2 col 8 nrf.slaveHandler(); ^ at line 2 col 21 nrf.slaveHandler(); ^ in function called from system ... >clearInterval(); =undefined >
When copying the code for the module from teh Espruino website into the Editor (right pane of the WebIDE) my Espruino also has problems to interpret the Javascript code. Maybe i should use the minified versions to check if it works?
Anyways, after clearing up all those inline '/..../' style comments the code did work last night, but i got some timing errors on the Espruino console (left pane in WebIDE). Maybe i can reproduce these again tomorrow if it helps. -
• #8
Sorry for that rubbish code blocks, the forum (if you want to call it like that) is a pain while formatting IMO
-
• #9
Hi #kai, they're working on a new editor. All you need to do for code is to add ``` but to leave a new line before and after it (I edited your post and it's fine now)
I just tried your code here and it does work. Are you sure it's not just that you don't have a reliable internet connection, so the Web IDE is unable to load the modules? We really need to add an error console to it so it can report these problems properly...
For the timing issue, do you mean you get
INTERNAL ERROR: Timeout on SPI RX
? Perhaps you could trySPI1.setup({sck:A5, miso:A6, mosi:A7,baud:100000});
instead ofSPI1.setup({sck:A5, miso:A6, mosi:A7});
. I'm unsure why that happens but I'll try and fix it asap... -
• #10
Hi @Gordon!
No, my internet connection is perfect reliable, i need it for work and other internet-centric hobbies.
I claim to also understand what the WebIDE does and where it loads the modules from. So i also don't really see a reason for my issues. May it have something to do with the Javascript modules? On my first impression the minified version of the NRF24L01P module does differ from the non-minified one. Not only in the variable names, but i haven't had the time to check this in depth.Yes, that was the timing issue which i did encounter and will try that extra argument which you do suggest. With my hands on the boards back at home i will report back later...
-
• #11
Can you use the version of the Web IDE from here instructions are on that page. You should them be able to right-click in the window and click 'inspect element', followed by 'Console'.
Then, when you click the 'send to espruino' button you should be able to see if the Web IDE is having any issues...
-
• #12
Here i am back with what @Gordon did suggest. First I did deletie the installed Web IDE from Google Chrome (). Then after downloading the Web IDE from GitHub using the ZIP file, I did unpack and install it. Now i have Version 0.32.0 installed.
After launching the new Web IDE I did send my code as listed above to the Espruino board and my console contains the following. Seems to be correct to me in the console, but unfortunately the Espruino console still shows the same errors as in my previous posts :-/
>>> Connecting espruino_status.js:40 Set Slow Write = true espruino_serial.js:170 Object bitrate: 9600 bufferSize: 4096 connectionId: 2 ctsFlowControl: false dataBits: "eight" name: "" parityBit: "no" paused: false persistent: false receiveTimeout: 0 sendTimeout: 0 stopBits: "one" __proto__: Object espruino_serial.js:62 Device found (connectionId=2) terminal.js:41 >>> Sending... espruino_status.js:40 Sending "\u0003echo(0);\nconsole.log(\"<<\"+\"<<<\"+JSON.stringify(process.env)+\">>>\"+\">>\");\n" espruino_serial.js:115 >>> Sent espruino_status.js:40 Got "echo(0);\r\n<<<<<{\"VERSION\":\"1v48\",\"BUILD_DATE\":\"Jan 30 2014\",\"BUILD_TIME\":\"13:32:24\",\"BOARD\":\"ESPRUINOBOARD\",\"CHIP\":\"STM32F103RCT6\",\"CHIP_FAMILY\":\"STM32F1\",\"FLASH\":262144,\"RAM\":49152}>>>>>\r\n" espruino_process.js:47 >>> Connected espruino_status.js:40 FIRMWARE: Current 1v48, Available 1v48 espruino_flasher.js:363 Firmware >1.43 supports faster writes espruino_flasher.js:367 Set Slow Write = false espruino_serial.js:170 watt nu 42 USART 0 Array[2] espruino_board.js:328 watt nu 43 USART 0 Array[2] espruino_board.js:328 watt nu 44 USART 0 Array[2] espruino_board.js:328 watt nu 50 USART 0 Array[2] espruino_board.js:328 Config.set(code, SPI1.setup({sck:A5, miso:A6, mosi:A7}); var nrf = require("NRF24L01P").connect(SPI1, B0, B1); function onInit() { print(nrf); if (typeof nrf != "undefined") { nrf.init([0,0,0,0,1], [0,0,0,0,2]); print("NRF Library loaded!"); } else { print("Error! NRF Library not loaded!"); } } onInit(); setInterval(function() { nrf.slaveHandler(); }, 50);) espruino_config.js:61 loadModule(NRF24L01P) espruino_modules.js:75 - NRF24L01P requires [] espruino_modules.js:94 Sending... Modules.removeAllCached();Modules.addCached("NRF24L01P","function NRF(a,b,c,d){this.CSN=b;this.CE=c;this.PAYLOAD=d?d:16;this.BASE_CONFIG=8;this.cmd=\"\";this.spi=a;this.callbacks=[]}NRF.prototype.C={CONFIG:0,STATUS:7,CD:9,RX_ADDR_P0:10,RX_ADDR_P1:11,TX_ADDR:16,RX_PW_P0:17,RX_PW_P1:18,R_REGISTER:0,W_REGISTER:32,R_RX_PAYLOAD:97,W_TX_PAYLOAD:160,FLUSH_TX:225,FLUSH_RX:226};\nNRF.prototype.init=function(a,b){digitalWrite(this.CE,0);digitalWrite(this.CSN,1);this.setRXAddr(a);this.setTXAddr(b);this.setReg(this.C.RX_PW_P0,this.PAYLOAD);this.setReg(this.C.RX_PW_P1,this.PAYLOAD);this.setReg(this.C.CONFIG,this.BASE_CONFIG|3);digitalWrite(this.CE,1)};NRF.prototype.setReg=function(a,b){this.spi.send([this.C.W_REGISTER|a,b],this.CSN)};NRF.prototype.setAddr=function(a,b){b=b.clone();b.splice(0,0,this.C.W_REGISTER|a);this.spi.send(b,this.CSN)};\nNRF.prototype.setRXAddr=function(a){this.setAddr(this.C.RX_ADDR_P1,a)};NRF.prototype.setTXAddr=function(a){this.setAddr(this.C.RX_ADDR_P0,a);this.setAddr(this.C.TX_ADDR,a)};NRF.prototype.getReg=function(a){return this.spi.send([this.C.R_REGISTER|a,0],this.CSN)[1]};NRF.prototype.getAddr=function(a){a=this.spi.send([this.C.R_REGISTER|a,0,0,0,0,0],this.CSN);a.splice(0,1);return a};NRF.prototype.getStatus=function(a){return this.getReg(this.C.STATUS)};\nNRF.prototype.dataReady=function(){return 14!=(this.getReg(this.C.STATUS)&14)};NRF.prototype.getData=function(){for(var a=[this.C.R_RX_PAYLOAD],b=0;b<this.PAYLOAD;b++)a.push(0);a=this.spi.send(a,this.CSN);a.splice(0,1);this.setReg(this.C.STATUS,64);return a};\nNRF.prototype.send=function(a){this.setReg(this.C.STATUS,48);digitalWrite(this.CE,0);this.setReg(this.C.CONFIG,this.BASE_CONFIG|2);this.spi.send(this.C.FLUSH_TX,this.CSN);a=a.clone();a.splice(0,0,this.C.W_TX_PAYLOAD);this.spi.send(a,this.CSN);digitalWrite(this.CE,1);for(a=1E3;a--&&!(this.getReg(this.C.STATUS)&48););0>=a&&print(\"TX timeout\");a=!0;this.getReg(this.C.STATUS)&16&&(print(\"TX not received \"+this.getReg(this.C.STATUS)),a=!1);digitalWrite(this.CE,0);this.setReg(this.C.CONFIG,this.BASE_CONFIG|\n3);digitalWrite(this.CE,1);this.setReg(this.C.STATUS,48);return a};NRF.prototype.slaveHandler=function(){for(;this.dataReady();){var a=this.getData(),b;for(b in a){var c=a[b];0===c&&\"\"!==this.cmd?(c=this.cmd,this.cmd=\"\",print(\"...>\"+c),c=\"\"+eval(c),print(\"...=\"+c),this.sendStringTimeout(c,500)):0!==c&&(this.cmd+=String.fromCharCode(c))}}};\nNRF.prototype.masterHandler=function(){for(;this.dataReady();){var a=this.getData(),b;for(b in a){var c=a[b];if(0===c&&\"\"!==this.cmd){c=this.cmd;this.cmd=\"\";var d=this.callbacks.splice(0,1)[0];void 0!==d&&d(c)}else 0!==c&&(this.cmd+=String.fromCharCode(c))}}};NRF.prototype.sendString=function(a){for(var b=0;b<=a.length;b+=this.PAYLOAD){for(var c=[],d=0;d<this.PAYLOAD;d++)c[d]=Integer.valueOf(a[b+d]);for(d=3;0<d--&&!this.send(c););}};NRF.prototype.sendCommand=function(a,b){this.callbacks.push(b);this.sendString(a)};\nNRF.prototype.sendStringTimeout=function(a,b){var c=this;setTimeout(function(){c.sendString(a)},b)};exports.connect=function(a,b,c,d){return new NRF(a,b,c,d)};\n"); SPI1.setup({sck:A5, miso:A6, mosi:A7}); var nrf = require("NRF24L01P").connect(SPI1, B0, B1); function onInit() { print(nrf); if (typeof nrf != "undefined") { nrf.init([0,0,0,0,1], [0,0,0,0,2]); print("NRF Library loaded!"); } else { print("Error! NRF Library not loaded!"); } } onInit(); setInterval(function() { nrf.slaveHandler(); }, 50); espruino_codewriter.js:42 >>> Sending... espruino_status.js:40 Sending "echo(0);\nModules.removeAllCached();Modules.addCached(\"NRF24L01P\",\"function NRF(a,b,c,d){this.CSN=b;this.CE=c;this.PAYLOAD=d?d:16;this.BASE_CONFIG=8;this.cmd=\\\"\\\";this.spi=a;this.callbacks=[]}NRF.prototype.C={CONFIG:0,STATUS:7,CD:9,RX_ADDR_P0:10,RX_ADDR_P1:11,TX_ADDR:16,RX_PW_P0:17,RX_PW_P1:18,R_REGISTER:0,W_REGISTER:32,R_RX_PAYLOAD:97,W_TX_PAYLOAD:160,FLUSH_TX:225,FLUSH_RX:226};\\nNRF.prototype.init=function(a,b){digitalWrite(this.CE,0);digitalWrite(this.CSN,1);this.setRXAddr(a);this.setTXAddr(b);this.setReg(this.C.RX_PW_P0,this.PAYLOAD);this.setReg(this.C.RX_PW_P1,this.PAYLOAD);this.setReg(this.C.CONFIG,this.BASE_CONFIG|3);digitalWrite(this.CE,1)};NRF.prototype.setReg=function(a,b){this.spi.send([this.C.W_REGISTER|a,b],this.CSN)};NRF.prototype.setAddr=function(a,b){b=b.clone();b.splice(0,0,this.C.W_REGISTER|a);this.spi.send(b,this.CSN)};\\nNRF.prototype.setRXAddr=function(a){this.setAddr(this.C.RX_ADDR_P1,a)};NRF.prototype.setTXAddr=function(a){this.setAddr(this.C.RX_ADDR_P0,a);this.setAddr(this.C.TX_ADDR,a)};NRF.prototype.getReg=function(a){return this.spi.send([this.C.R_REGISTER|a,0],this.CSN)[1]};NRF.prototype.getAddr=function(a){a=this.spi.send([this.C.R_REGISTER|a,0,0,0,0,0],this.CSN);a.splice(0,1);return a};NRF.prototype.getStatus=function(a){return this.getReg(this.C.STATUS)};\\nNRF.prototype.dataReady=function(){return 14!=(this.getReg(this.C.STATUS)&14)};NRF.prototype.getData=function(){for(var a=[this.C.R_RX_PAYLOAD],b=0;b<this.PAYLOAD;b++)a.push(0);a=this.spi.send(a,this.CSN);a.splice(0,1);this.setReg(this.C.STATUS,64);return a};\\nNRF.prototype.send=function(a){this.setReg(this.C.STATUS,48);digitalWrite(this.CE,0);this.setReg(this.C.CONFIG,this.BASE_CONFIG|2);this.spi.send(this.C.FLUSH_TX,this.CSN);a=a.clone();a.splice(0,0,this.C.W_TX_PAYLOAD);this.spi.send(a,this.CSN);digitalWrite(this.CE,1);for(a=1E3;a--&&!(this.getReg(this.C.STATUS)&48););0>=a&&print(\\\"TX timeout\\\");a=!0;this.getReg(this.C.STATUS)&16&&(print(\\\"TX not received \\\"+this.getReg(this.C.STATUS)),a=!1);digitalWrite(this.CE,0);this.setReg(this.C.CONFIG,this.BASE_CONFIG|\\n3);digitalWrite(this.CE,1);this.setReg(this.C.STATUS,48);return a};NRF.prototype.slaveHandler=function(){for(;this.dataReady();){var a=this.getData(),b;for(b in a){var c=a[b];0===c&&\\\"\\\"!==this.cmd?(c=this.cmd,this.cmd=\\\"\\\",print(\\\"...>\\\"+c),c=\\\"\\\"+eval(c),print(\\\"...=\\\"+c),this.sendStringTimeout(c,500)):0!==c&&(this.cmd+=String.fromCharCode(c))}}};\\nNRF.prototype.masterHandler=function(){for(;this.dataReady();){var a=this.getData(),b;for(b in a){var c=a[b];if(0===c&&\\\"\\\"!==this.cmd){c=this.cmd;this.cmd=\\\"\\\";var d=this.callbacks.splice(0,1)[0];void 0!==d&&d(c)}else 0!==c&&(this.cmd+=String.fromCharCode(c))}}};NRF.prototype.sendString=function(a){for(var b=0;b<=a.length;b+=this.PAYLOAD){for(var c=[],d=0;d<this.PAYLOAD;d++)c[d]=Integer.valueOf(a[b+d]);for(d=3;0<d--&&!this.send(c););}};NRF.prototype.sendCommand=function(a,b){this.callbacks.push(b);this.sendString(a)};\\nNRF.prototype.sendStringTimeout=function(a,b){var c=this;setTimeout(function(){c.sendString(a)},b)};exports.connect=function(a,b,c,d){return new NRF(a,b,c,d)};\\n\");\n\nSPI1.setup({sck:A5, miso:A6, mosi:A7});\nvar nrf = require(\"NRF24L01P\").connect(SPI1, B0, B1);\nfunction onInit() {\n print(nrf);\n if (typeof nrf != \"undefined\") {\n nrf.init([0,0,0,0,1], [0,0,0,0,2]);\n print(\"NRF Library loaded!\");\n } else {\n print(\"Error! NRF Library not loaded!\");\n }\n}\nonInit();\nsetInterval(function() {\n nrf.slaveHandler();\n}, 50);\necho(1);\n" espruino_serial.js:115 >>> Sent espruino_status.js:40
-
• #13
After using the non-mimified version and cleaning up those inline "/..../" comments the modules does seem to work now. But only with the addition of the "baud:100000" parameter to the SPI module.
-
• #14
Minifying sometimes has problems with handling requires and loading modules (Modules.-commands) The way this is minified by Google could be one reason for your problems. Same happens with binary data (0b0001...), which is also not know to minify.
May be we have to split minifying, to minify code only, not the modules. -
• #15
I think there are still some issues with minifying the code. I have disabled all optimisations in the web IDE as there have been instances where my code (without modules) did not run when using any of the optimisations. So I would assume that splitting the minification between code and modules will only provide limited relief.
-
• #17
Not immediately, as at the moment I didn't think it was important to save such code. I just turned all optimisations off. So far, none of the code seems to have any issues with minifying or simple optimisations, so it must have been some very specific code, as you would find in modules. The only thing I notice is that the advanced optimisations screw up your function names, which may not be what you want. If I do find an example in my code in the coming days, I'll be sure to post it here.
-
• #18
@JumJum - 0b001/etc is already handled for the docs here: https://github.com/espruino/EspruinoDocs/blob/master/bin/build.js
However it's in the ES6 standard, so just enabling support for that in the minifier (if it exists) should help.
@#kai, glad it's working after some tweaking. Looks from the logs like it's found and is loading the module though. What does
require("NRF24L01P")
in the LHS (after writingrequire("NRF24L01P")
in the RHS) actually report back? -
• #19
@Gordon, just tested uglifyjs and it doesn't handle 0b001.
I could not find any enabler in googles minify or uglifyjs to support 0b001/etc.
Pretty sure, this will change, but right now, there is no way.
If anybody knows better, please let me know.BTW uglifyjs could be the better solution compared to google minifier.
The way, how http://lisperator.net/uglifyjs/#demo supports clicking in minified code and see what this was in not modified code is great. To give one example only. -
• #20
Hmm. That's a shame. It's probably a pretty easy tweak though - at least it wasn't too hard to modify jshint.
I think google's minifier does some much more interesting optimisations - especially when it knows that values aren't public. Still, it'd be nice to do minification without having to use a third party website...
-
• #21
Actual status of checking uglifyjs is not funny.
It is not working inside chrome web app. Reason is usage of eval somewhere in uglifyjs
Setting a content security policy is refused.
If anybody knows more, please let me know.
Did you have any more information? An example?
Are you using the latest web IDE from git, or the one on the chrome web store.