Saving modules and using saved functions?

Posted on
  • Hello
    Is it somehow possible to call a function you have saved on the ESP8266??

    For example:
    I would like to save the stepper module on the ESP8266 so I am able to do stuff like:

    var motorLeft = new StepperMotor({
      pins:[D0,D2,D4,D5],
      pattern:[0b0010,0b0001,0b0100,0b1000]
    });
    

    without having to get the module off the web and upload it everytime.
    The problem with this is that if I connect to the ESP8266 over wifi, my computer is no longer connected to the web and can therefore no longer get the module.

    And also, would it be possible to save something like this:

    function forward(steps) {
      motorRight.moveTo(motorRight.getPosition­()+steps, 1);
      motorLeft.moveTo(motorLeft.getPosition()­-steps, 1);
    }
    

    to the ESP8266, so that I can just send something like this: forward(1000);

    Thanks :)

  • Read up on how require works and how the save function works.

  • It sounds like as @Wilberforce says just saving the code will do what you want... Here's a good start: http://www.espruino.com/Saving

    However if you simply type var StepperMotor = require("StepperMotor") into the right-hand side of the IDE, choose 'even after reset' for 'Save on Send' from the IDE options, upload, and then turn 'save on send' to off again, you can then write code and type save() and it'll save, and can even use reset() to reset state, but you'll always have access to the saved code you saved originally.

  • Ah I see, thank you so much :)

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

Saving modules and using saved functions?

Posted by Avatar for Hapseleg @Hapseleg

Actions