• PICO shimmed to ESP8266.
    I use wifi.getIP() and print the resulting IP address, then assign it to a global variable.
    Printing the global variable MyIP doesn’t work.
    Later typing MyIP; into the left pane I get the IP address.
    So what’s going on and is there a solution?

    //MyIP.js
    //26Sep 2016
    //espruino board with ESP8266
    //PICO  with ESP8266
    //var Hardware=0; //Espruino board
    var Hardware =1; //PICO
    var SSID="ssis";
    var key= "routerpw";
    var Serial;
    var MyIP="";
    function test(){
    if(Hardware===1)Serial=Serial2;
    if(Hardware===0)Serial=Serial4;
    if(Hardware===1){
     digitalWrite(B9,1); // enable on Pico Shim V2
     Serial.setup(115200, { rx: A3, tx : A2 }); //Pico
    }
    if(Hardware===0)Serial.setup(115200, { rx: C11, tx : C10 }); 
    //espruino board
    console.log("Start connection process");
    var wifi = require("ESP8266WiFi_0v25").connect(Serial, function(err) {
      if (err)return 1;// throw err;
    console.log("Reset the ESP8266");
      wifi.reset(function(err) {
        if (err)return 1;// throw err;
        console.log("Connecting to WiFi");
        wifi.connect(SSID,key, function(err) {
          if (err)return 1;//throw err;
          wifi.getIP(function(l,ip){console.log("IP= ",ip,"\n\r"+l);MyIP=ip;});
          console.log("Wi-Fi Connected");
          console.log("MyIP= ",MyIP,"XXX");
          console.log("MyIP= "+MyIP+"XXX");
    // Now you can do something, 
     var server = require("net").createServer(function(c) {
      // A new client as connected
      c.write("Hello");
      c.on('data', function(data) {
        console.log(">"+JSON.stringify(data));
      });
      c.end();
    });
    server.listen(1234);
        });
      });
    });
    }//end test
    var x;
    console.log("Start");
    x=test();
    if(x!==0)console.log("Try again");//error seen
    if(x===0) console.log("Exit Seen");
    

    The output:

    >echo(0);
    Start
    Start connection process
    Try again
    =undefined
    Reset the ESP8266
    Connecting to WiFi
    Wi-Fi Connected
    MyIP=   XXX
    MyIP= XXX
    IP=  192.168.1.3
    null
    >MyIP;
    ="192.168.1.3"
    >
    
    

    1 Attachment

About