You are reading a single comment by @user76916 and its replies. Click here to read the full conversation.
  • Hi there,

    So, if you have a require statement, you have to write the statement (or your code) on the right side of IDE and upload. This process downloads any dependency from the internet and uploads them correctly to the device. You will get a module not found error if you write a require statement in the REPL.
    A typical program would then have an onInit() function and a save() statement at the end of file for persistence.
    The modules are downloaded from https://github.com/espruino/EspruinoDocsĀ­/tree/master/devices
    A typical program would look like this-

    clearWatch();
    var wifi;
    var werr;
    let WIFI_NAME = 'something';
    let WIFI_OPTIONS = { password: 'something' };
    let w_conn = 0;
    
    function onInit() {
      console.log('here');
      connWiFi().then(succ => {
        w_conn = 1;
        console.log('connected !');
        digitalPulse(LED2, 1, 100);
      }, err => {
        werr = err;
        console.log('some error in wifi connection');
      });
    }
    function connWiFi() {
      let prom = new Promise((res, rej) => {
        wifi = require('EspruinoWiFi');
        wifi.connect(WIFI_NAME, WIFI_OPTIONS, err => {
          if(err) rej(err);
          else res(1);
        });
      });
      return prom;
    }
    save();
    
About

Avatar for user76916 @user76916 started