• There is no "fs" module built in stock ESP port. How can I save some data in runtime?

  • http://forum.espruino.com/conversations/­279700/?offset=25#comment12891564

    Also, depending on what sort of storage is appropriate, an eeprom (ex AT24 series) could be used.

  • The File class won't be available on ESP8266 as there's no filesystem library built in.

    By far the easiest (IMO) for small amounts of data would be to just use this library: http://www.espruino.com/FlashEEPROM

    For it to 'just work' you'd either want a 'cutting edge' ESP8266 build (so newer than 1v85), or you can hard-code the start address with:

    var f = new (require("FlashEEPROM"))(0x076000);
    
  • What size "files" are you looking to store?

    You can used the flash module.

  • I just want to store some ESSID, password and a 16-bit-counter. So it might be considered as a "small storage necessity".

    I think FlashEEPROM will suffice my needs. I'll test and post a feedback.

  • The wifi lbrary wifi.save() saves EESID and password for you already!
    So it might just be the 16 bit counter...

    the Flasheprom module stores with indexes, it might be over complicated for your needs - the flash module might be enough!

  • I am totally sure that I tried above ...require("FlashEEPROM")... code a few hours ago and it returned an object, but now it fails with following error message:

     _____                 _ 
    |   __|___ ___ ___ _ _|_|___ ___ 
    |   __|_ -| . |  _| | | |   | . |
    |_____|___|  _|_| |___|_|_|_|___|
              |_| http://espruino.com
     1v85 Copyright 2016 G.Williams
    Espruino is Open Source. Our work is supported
    only by sales of official boards and donations:
    http://espruino.com/Donate
    Flash map 512KB:256/256, manuf 0xe0 chip 0x4014
    >require("FlashEEPROM")
    WARNING: Module "FlashEEPROM" not found
    =undefined
    >
    
  • @Wilberforce I need to store ESSID and password except from default ones. I will hardcode a default ESSID+password and save an additional one. If new ESSID+password fails long enough, I will fallback to the default one. That's why I need some other place to store these values.

    Anyway, there is only Flash module seems to work. I'll follow this document and write some simple driver functions. I'll get back to you.

  • @ceremcem it could be that you have a bad network connection? These modules are loaded off the net, and if the connection goes down they won't get pulled in.

    Worst case you could store them locally, or even copy/paste the module code into the top of your code file.

  • To add to this: Just typing require("FlashEEPROM") on the left hand side will never work.

    You need to use it on the right-hand side and click upload - then the Web IDE gets a chance to scan your code, see what modules are needed, and load them up automatically.

    It's worth reading I've pasted code into the left-hand side of the Web IDE and it doesn't work on the Troubleshooting page at: http://www.espruino.com/Troubleshooting

  • @Gordon Now I understand better. I'm still trying to understand the working mechanism of Espruino, but clearly I didn't yet.

    The fact is, I'm not using the Web IDE. I have built a toolset (and will publish when ready for daily usage) where the main purpose is to use Livescript transparently. So I may manually download FlashEEPROM module.

  • I would suggest using the web ide and get things working, and then move to your setup will be the quicker path!

    The web idea is very interactive and allows quick prototyping.

  • Yeah, that'll be your problem then ;) Some modules are built in, but all the others are loaded on demand.

    There's are some tweaks that go on in the background when uploading to avoid some nasty edge cases.

    You could look at https://github.com/espruino/EspruinoTool­s (on NPM as https://www.npmjs.com/package/espruino) - this is a command-line (and library) version of the same code.

    You could bodge something up very easily that ran Livescript over your code and uploaded it with EspruinoTools.

    Or you could modify the Web IDE from https://github.com/espruino/EspruinoWebI­DE. If there's a web service that converted LiveScript to JavaScript it'd be trivial to write a plugin like this that took the code and converted it just before uploading.

  • @ceremcem, you could put a set of SSIDs and Passwords into a module that is then uploaded to the board when uploading the application code to the board happens. See some details in this post. To make that happen, you place the modules into the modules folder in your sandbox (IDE configurable directory structure).

  • It seems a little bit diverged, but not at all: Could you please take a look at this problem because I guess this is the only problem left. If I can make a bundle by myself, I can use FlashEEPROM module.

    PS: I'm dealing with this problem since I'm not able to use EspruinoWebIDE right now.

  • @ceremcem, in mentioned post I cover amost to the T what you are looking for: a module that defines a class with method(s) to use JavaScript in an object-oriented way rather than script way: the first - something() function defines the class, and the hello() function a method on the instances of something - instances crated with new something(...), as you state on stackoverflow post. Btw - for the sake of useful convention(s), class names start with a capital letter... ;-).

    The solution can happen even in one file or even in two files. Let's look at each option in a separate post.

  • FIRST Option: Single Module File

    Create a module - js file - with the following content:

    // Something.js in .../modules folder of IDE Settings-PROJECT
    var Something = function(name) {
      this.name = name;
    };
    Something.prototype.sayHello = function() {
      console.log("Hello, my name is " + this.name + "!");
    };
    exports = Something;
    

    To use the Something module, enter following code into edit pane of Espruino Web IDE, upload it, and then press BTN (equal to BTN1):

    var Something = require("Something"); // pull in class w/ require module
    var thisThing = new Something("ThisThing"); // create a 1st instance of class
    var thatThing = new Something("ThatThing"); // create a 2nd instance of class
    setWatch(function() { thisThing.sayHello(); // make 1st instance say hello...
      }, BTN1, { repeat:true, edge:"rising", debounce:50}); // ...on button press
    setWatch(function(){ thatThing.sayHello(); // make 2nd instance say hello...
      }, BTN1, { repeat:true, edge:"falling", debounce:50}); // ...on button release
    

    An almost perfect example you find developed in this conversation:
    Software Buttons - Many buttons from just one hardware button. @Gordon made even a change to the export part of the Espruino firmware to accommodate this approach in a straight forward way, which you find in this conversation: How to create a module that is a 'Class' - aka a function usable with new - or: How to make require() return a function and not an object.

  • @allObjects Thank you, here I could achieve the solution:

    # create bundle
    BUNDLE="init.min.js"
    echo "" > ${BUNDLE}
    
    # Register modules via `Modules.addCached()` method
    # see: http://forum.espruino.com/comments/12899­741/
    MODULE_NAME="FlashEEPROM"
    MODULE_STR=$(uglifyjs -c -m -- ${MODULE_NAME}.js | sed 's/\"/\\\"/g' | sed "s/\n//g")
    echo "Modules.addCached(\"${MODULE_NAME}\", \"${MODULE_STR}\");" >> ${BUNDLE}
    uglifyjs -c -m --  init.js >> ${BUNDLE}
    

    Now I can require("FlashEEPROM") as expected.

  • @ceremcem, urvw! ...yep that works... but your context is a ...shell, is it? Are you cross-generating/composing modules from very modular source files?

  • Yes, the context is BASH shell. I'm familiar with BASH more than Javascript in such jobs.

    I don't know, I feel really lost while going after being able to use FlashEEPROM module :)

  • @ceremcem, what other language(s) are you comfortable with?

  • SECOND Option: Multiple, Nested Module Files

    Create the following Something_Class.js and Something_methods.js files in the sandbox modules folder. As you notice, the class file uses the methods file and *'mixes' its properties - methods - into the prototype (added a sayGoodbye() as a second method to show how mixing in of multiple methods multiple is achieved).

    // Something_Class.js in .../modules folder of IDE Settings-PROJECT
    var Something = function(name) {
      this.name = name;
    };
    
    var methods = require("Something_methods");
    for (var methodName in methods) // mix separately defined methods into...
      Something.prototype[methodName] = methods[methodName]; // ...prototype
                          
    exports = Something;
    
    // Something_methods.js in .../modules folder of IDE Settings-PROJECT
    exports =
    { sayHello: function() {
        console.log("Hello, my name is " + this.name + "!");
      }
    , sayGoodbye: function() {
        console.log("Bye-bye from " + this.name + "!");
      }
    };
    

    Usage is only slightly different: Instead of pulling Something module, you pull Something_Class module, but you still pull only one module...:

    var Something = require("Something_Class"); // pull in class w/ require module
    var thisThing = new Something("ThisThing"); // create a 1st instance of class
    var thatThing = new Something("ThatThing"); // create a 2nd instance of class
    setWatch(function() { thisThing.sayHello(); // make 1st instance say hello...
      }, BTN1, { repeat:true, edge:"rising", debounce:50}); // ...on button press
    setWatch(function(){ thatThing.sayHello(); // make 2nd instance say hello...
      }, BTN1, { repeat:true, edge:"falling", debounce:50}); // ...on button release
    setTimeout(function(){ thisThing.sayGoodbye(); }, 45000);
    setTimeout(function(){ thatThing.sayGoodbye(); }, 60000);
    
    

    mixin - mixing the properties of one Javascript object into another one is a very Javascript typical pattern... that shows Javascripts extreme dynamic properties, and - neither last nor least - one that give Javascript almost the power of the Interfaces w/ Implementations pattern found in Java. (A class that implements multiple interfaces mixes multiple sets of methods into a new class definition, which can also be defined by a 'mixed in' constructor using a helper construct.)

  • @allObjects
    Well, I was comfortable with PHP in the past, but nowadays I feel very comfortable with Python*, Livescript*, Bash**; and very uncomfortable with Javascript and C#* (but I use when I have to)...

  • Thank you all for everything, the problem has been solved. Here are the results:

    configFile = null;
    configInit = function(){
      if (configFile === null) {
        configFile = getFile();
      }
    };
    configWrite = function(index, value){
      configInit();
      configFile.write(index, value);
    };
    configRead = function(index){
      configInit();
      return E.toString(configFile.read(index));
    };
    

    Usage:

    >configWrite(0, "hello")
    =undefined
    >configWrite(1, "world")
    =undefined
    >configRead(0)
    ="hello"
    >configRead(1)
    ="world"
    >
    
  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

[SOLVED] Is there anyway to have a filesystem-like facility on ESP8266?

Posted by Avatar for ceremcem @ceremcem

Actions