Internet-enabled Espruino Problems

Posted on
  • I'm trying to load the GPS module onto my puck.js using the loadModule function at in the "Internet-enabled Espruino" section at https://www.espruino.com/Modules (I'm not using the Espruino Web IDE, but am trying to get things working from a web application I'm running locally on XAMPP).

    1) I call the code from my web application, and it seems to load the GPS module, but I get an error "Uncaught ReferenceError: exports is not defined at GPS.js:41"
    2) Is that the correct process? Or should I be writing the code to the puck instead of including it in a file in my web application?

    Many thanks for any suggestions.

  • Sat 2019.03.23

    Hi @RolandGalibert, I'm late to the party here, but I just checked your last post:

    GPS Module not sending data on Puck.js

    http://forum.espruino.com/conversations/­324744

    and it appears (then #22) everything was working.



    If I understand what was being done there, the require("GPS") is loading the GPS module into the Puck memory area. Is that the task what is attempted to be done here? Was save() used to store that working code and module to the Puck when the WebIDE was connected then?



    Just got called away. Need to handle an issue, back later . . . .


    In the meantime . . . .
    Could you please post process.env so that others may have an idea as to which Espruino version is used, in case there are updates that I'm not aware of.

    and, . . . the code that is currently running on the Puck and the web app code that is running on the local server.

  • Hi Roland,

    The 'Internet enabled Espruino' section is for when you have an Espruino device that does itself have an internet connection - I don't think that applies here. Sounds like you were trying to load the module on your PC rather than on the Puck.js itself, which definitely wouldn't work.

    The easy/sensible solution is to just use the Web IDE (or command line tools) to upload the code you want to the Puck, then save it. You can then connect with whatever other software you want and then the module will be on there for you to use with whatever you do next.

    However if for whatever reason you don't want to do that, you can follow the 'Modules from Storage' section on https://www.espruino.com/Modules ...

    Ideally do the above from the IDE/CLI as well - but when you've done that the GPS module will be in storage ready to be called up whenever you need it.

  • Thanks, Gordon. I did eventually see that I was loading the module onto my PC and not the puck, and wound up (kind of) getting things to work. Perhaps you can answer a couple of FYI questions:

    1) The general reason I'm doing all these flips and twists is because I'm trying to save as much flash memory as possible, so I was trying to get around saving the module to flash since it would be written to RAM anyway (does that all make sense?) I'm working on a project where the puck will regularly log things like temperature and GPS location over a month, maybe longer, and might not have a connection during that to transfer those measurements elsewhere.

    2) Just out of curiosity, if I continue with my crazy idea of writing the module directly to puck RAM, are there some commands to tell the puck that the module code should be in a separate namespace/module (similar (I think) to require("Storage").write("module" ... )

    I did get the module to work by using a JavaScript fetch in my PC application to get your code in https://www.espruino.com/modules/GPS.min­.js and write it to the puck, first writing a command "var exports = {}" but it seems that might mess things up if I ever needed to load another module which used exports (or at least exports.connect).

  • I was trying to get around saving the module to flash since it would be written to RAM anyway

    Ahh - that's not actually the case. If you do the Storage option (or 'Save on Send': http://www.espruino.com/Saving) then the code is stored in flash and executed from there, so it doesn't use much RAM at all.

    Even if you use the normal 'save()' the code stored in ROM is stored compressed, so is actually pretty dense. GPS is super small anyway though (789 bytes!).

    are there some commands to tell the puck that the module code should be in a separate namespace/module

    I'm not sure I really understand the question...

    If you actually want to load everything into RAM from your own app, you might find it's easier to use the command-line tools with the -o file.js option - they'll wrap all the needed code together for you (using Modules.addCached, which is the solution for messing around with exports) and then write it to a JS file. You can then take that file and upload it from your app, and job done :)

    If you're trying to save memory, you could take a look at using the built-in compression library to compress the data you save: http://www.espruino.com/Reference#t_heat­shrink

    You could also try and add some external hardware - if you have 2 data pins free you could add an I2C EEPROM/flash memory which could give you a megabyte or more of memory.

  • Okay, great. That's definitely good to know that the module will be run from flash. I also admit that it's definitely possible 512 kB of memory will be more than I'll ever need. And many thanks for all the other tidbits of information.

  • @RolandGalibert, if you have initialization modules that and you can save the code reliably after they run and re-powering can pick up the initialized state, then there is an option to get rid of such modules after their execution. How much space you though get back all depends on how much of that initialization data is not referenced anymore after execution and the Modules cache is holding onto them as the only one that keeps it from getting garbage collected.

    If you have initialization code that uses very verbose, human readable data which you transform into compressed, machine readable only, binary compact objects, that's where you get some RAM back. But depending on the Espruino device there are other options as @Robin points out.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Internet-enabled Espruino Problems

Posted by Avatar for RolandGalibert @RolandGalibert

Actions