Modules - what am I doing wrong #6207
Replies: 1 comment
-
Posted at 2019-12-06 by Robin Fri 2019.12.06 Hi James, any more detail revealed in Is node-poweredup.js in folder \Modules and calling code.js in ????? Not at development PC, on lunch break, more later this eve > EDIT: > Calling code.js file would reside in \Projects Posted at 2019-12-06 by user106443 Hi Robin Thankyou that helped, It looks the module i am trying to use if the wrong type ie node module and there doesn't appear to have .js or .min.js file. I install the module via NPM, is there simple way around this Many Thanks James Posted at 2019-12-07 by Robin Fri 2019.12.06 I did a quick update of post #1 Hi @user106443, now that the 504 Gatway errors (main web site fine just forum) are over (2 hour wait 9-11pm CST) I'm able to respond. From the line of calling code in post #1, it appears you are well versed and may have already persued this help page:
James, I don't want to mislead with the unknown, I just don't have enough experience with Node or NPM to provide a suitable response. > 'the module i am trying to use if the wrong type' However, I dare try:
Should the above link not provide enough detail, and a running example is still required, I could whip together a sample demo 'Hello World' test page if that would help. Posted at 2019-12-07 by maze1980 If you want to use nodejs modules use nodejs, e.g. on a pc, rpi or opi. Posted at 2019-12-07 by @allObjects @user106443
as @maze1980 points out, because I may use ES5/ES6 things that are not implemented yet or are impractical to implement in Espruino, last but not least because of the resources on the mcs used, but also because of the way Espruino JavaScript interpreter genuinely works. NodeJs lives in a different context and makes therefore different presumptions. One of them is: memory is practically limit less - even more so for short periods - and code is 'compiled' into virtual machine code. These is perfect fine thinking for servers or browsers where NodeJs runs and browserified modules run. Transpilers can help to 'bring things down' to implemented functionality, but that covers only half the story. Posted at 2019-12-09 by @gfwilliams If the module of interest has just one JS file, you can rename that to the module name and stick it straight in the modules folder and it should work. If it's a multi-file module chances are it's too big to run on Espruino :( There was a (beta) NPM module loader in the IDE for a while, but it was such a nightmare it got removed. A good 95% of NPM modules (if not more) pull in so many dependencies they fill up Espruino's memory before you write any code Posted at 2019-12-09 by @fanoush From this example https://github.com/nathankellenicki/node-poweredup#nodejs-sample-usage and this source of the module https://github.com/nathankellenicki/node-poweredup/blob/master/src/poweredup-node.ts there is no chance this will work in Espruino as is. However maybe the misunderstanding is even bigger, @user106443 what Espruino device you want to use to run your newly written code? What are you trying to do? Espruino IDE is not meant to be running your javascript code directly in the browser on your Mac OS X. It is targeted for some small device like puck.js Posted at 2019-12-09 by ThePlayShed Thanks for everyone for the reply, Yes it looks like the the modules is multi files, and it seems very complicated to try and combine into one. The project is to try and make a remote for daughters bluetooth lego train, it had working in browser so was hoping to port it over but nothing is ever that simple I am currently trying to see adapting 'Bluetooth LE HID Keyboards' library work. I just need to try and find the correct modifier keys Wish me luck Posted at 2019-12-09 by ThePlayShed Hi All Just a little update, I've managed to hack in the node-module when it's running on my mac and got it print me the code for certain commands, so it should be a little simpler If anyone could point me in right direct for the best way to this raw data to my device that would be grand "Code to Send: 00001624-1212-efde-1623-785feabcd123 Buffer 81 00 11 51 00 64" I am very greatful for any help James Posted at 2019-12-09 by @allObjects Great little fun project! Did you notice some particular packet size(s)? Do you know abut the layout of the packages - what is at what position in the package and what the value means? Is it sent binary or in hex char? Does the communication happened paired or just advertised w/ address in pay load?
Looks like this 'spot' may provide insights... https://github.com/LEGO/lego-ble-wireless-protocol-docs PS: James it looks that you have two differen Espruino forum IDs - user106443 and user104759 - is that correct? First started the thread, latter used in last two posts of yours... Posted at 2019-12-09 by ThePlayShed Thanks the lego link very helpful Yes it looks like the message it send contains the 16 bytes in hex followed buffer string that appears to vary in length. ie Buffer 05 00 01 02 02 or 0a 00 41 00 00 01 00 00 00 01 sorry didn't realise i was using two account the previous message was sent from my work. Posted at 2019-12-09 by @allObjects you mean 16 bytes in binary? 32 nibbles... otherwise it would be 32 bytes... I guess you used hex for a display of an Uint8... ...yep... 'buffer' is self-describing message: 1st byte is length in Uint8... (message length includes the length byte)... Protocol is GATT - means communication in connected state - see https://learn.adafruit.com/introduction-to-bluetooth-low-energy/gatt (anyway a helpful link... things broken down and explained for someone or something like me / my brain). Of course, for BLE all roads lead to https://www.bluetooth.com/specifications/ Posted at 2019-12-12 by ThePlayShed Hi All Thanks allobjects that helped but my progress is still quite slow, i have managed to connect to the train and disconnect but can't work out the best way to send the buffer. I am still trying to get my head around javascript so maybe missing something quite obvious here's my current code var devices; NRF.connect("e0:7d:ea:0c:03:29").then(function(g) { function send_message() { function train_disconnect() { setInterval(function() { any advice would be greatly appreciated Cheers James Posted at 2019-12-13 by Robin Hello James, any chance you would re-edit your code posting so that line numbers will appear along with color hilighting? Hilight the code block, then click the < / > code button between the Quote button and Preview button, or, Place three backticks (below the tilde key and next to the numeral 1 key) just before and just after the code block. This will enhance and make reading easier. Posted at 2019-12-13 by ThePlayShed Thanks For have a look Robin is this a better layout ?
Posted at 2019-12-13 by @allObjects @user104759 perfect! It make code much more readable and easier to discuss. Posted at 2019-12-15 by ThePlayShed Sorry To keep asking, I am seem to making some progress using a paired back node script and now rewriting in to use on the espruino, however I am stuck finding a way of making 'Buffer.from' working, Is there espruino equivalent ? I am looking to run this line
Posted at 2019-12-15 by Robin Sun 2019.12.15
It is actually a Javascript language method. W3Schools is where I go. There is even a 'Try It' button to click! Reference link for Array handling: Posted at 2019-12-16 by ThePlayShed Thanks for replying unfortantly it does like Array.from unless is need to done a slight different way in espruino
Posted at 2019-12-16 by Robin My mistake, should have double checked using the exact link I provided. Muddled with 'find' Try this forum post with tons of examples and links: I think this is what you are after:
Posted at 2019-12-26 by ThePlayShed Thanks Robin, that eventually worked however i realise i was missing a step and had to send a two different commands to make it work. I managed to get me remote made in time for christmas so thank you all for you help, here a video of my remote in action https://www.instagram.com/p/B6inY2XgasT/?igshid=16amjui8jcves I hope you all had great a christmas Posted at 2019-12-26 by Robin Thr 2019.12.26 Thank you and Merry Christmas James @user104759 to you and your family. James, now that is one really cool project for the kiddies! and, . . . I'm sure you had as much fun getting it to work, . . . didn't you! ;-) Now the train has an Espruino onboard, time to one-up that toy manufacturer, and add some LED headlights, train whistle *(not quite sure how to do that - maybe there is a sound module)*, electro-magnetic disconnect coupling, and simulated smoke?? Had an idea, would you take the time to create a forum post under the 'Projects' heading to show off this result? Including both some static images along with the video link. Having *(all)* most of the code would really assist others to get a head start in doing other similar projects. Now, it would be really cool if that project could be extended using the *Blockly* graphical programming model, *(click < / > icon at bottom of the WebIDE)* so that the kiddies could 'program' the running train the way they want, perhaps? Just a thought . . . . Posted at 2019-12-27 by @allObjects @user104759 great to hear that the Christmas celebration was elevated by this fun application... Thanks for the video. Enjoyed it very much. Posted at 2020-01-06 by @gfwilliams That's amazing - thanks for posting the results! The controller looks awesome too! Would you be willing to post up your finished code in some form? Having a way to control LEGO sounds like it'd be amazingly useful for loads of people. By the way I noticed in the code sample above you had Posted at 2020-01-06 by @gfwilliams Also, I should add that I'll be restarting the "free Espruino board for a write-up" offer soon (in fact I'm still unofficially doing it) so if you did write this up somewhere I could send you a new device to help with some other fun projects :) Posted at 2020-01-22 by ThePlayShed Sorry for late rely, yes I ditched the NRF.nfcSend, and used characteristic.writeValue, I will get my code together and try and write up brief tutorial |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2019-12-06 by user106443
Hi There
I am afraid I am complete newbee of Espruino, so please forgive me if this is some thing silly. I am hoping to use module but not have much luck
I am on Mac OsX and using the web IDE, I can see the projects so I think i am using the correct program.
on my root folder I've set up a project folder called 'Espruino' and have gone into the setting -> project and set the sandbox as ~/Espruino this created lots of folders including modules, I copied my module in there
now when i run my first line of code ie
const PoweredUP = require("node-poweredup");
it say the module can not be found am I doing something daft ?
Any Help would greatly appreciated
Cheers
James
Beta Was this translation helpful? Give feedback.
All reactions