You are reading a single comment by @Wilberforce and its replies. Click here to read the full conversation.
  • Further progress made:

    1. save() works - and on reboot loads saved code
    2. wifi.save() saves the current connects and reloads on reboot

    So after wifi connect and save, here is a example using websockets:

    function onInit() {
      
      console.log('on init...');
    
    var wifi=require("Wifi");
    //wifi.connect(ssid, {password: password}, function() {
    
    wifi.on('connected', function(details) { 
      console.log("Connected to access point, listening for clients",details);
    
      var http = require("http");
      
      
     function onPageRequest(req, res) {
        //console.log(req);
      res.writeHead(200, {'Content-Type': 'text/html'});
      res.end(page);
     }
    
      var page=`
    <html lang="en">
      <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width,initial-scal­e=1">
        <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/boo­tstrap/3.3.5/css/bootstrap.min.css">
      </head>
      <body>
        <div class="well well-lgt">
          <div class="panel-heading">
            <h3>Websockets</h3>
          </div>
          <button class="btn btn-warning" id="send" onclick="ws.send(JSON.stringify({click:{­count:count}}));;count=count+1;this.inne­rHTML='Send '+count">Send to Espruino</button>
          <ul id="list" class="list-group"></ul>
        </div>
        <script>
    	var ws, count = 1;
      setTimeout(function () {
    
      ws = new WebSocket("ws://" + location.host + "/my_websocket", "protocolOne");
        ws.jsend=function(o) {
       this.send(JSON.stringify(o));
    	};
      ws.onmessage = function (event) {
        console.log({
          msg : event.data
        });
        var ul = document.getElementById("list");
        var li = document.createElement("li");
        li.className = "list-group-item";
        li.appendChild(document.createTextNode(e­vent.data));
        ul.appendChild(li);
      };
      setTimeout(function () {
    	//ws.send(JSON.stringify({click:{count:c­ount}}));
        //ws.send(JSON.stringify({info:{value:'H­ello to Espruino!'}}));
        //ws.send(JSON.stringify({date:{date : new Date()}}));
    	ws.jsend({info:{value:'Hello to Espruino!'}});
        ws.jsend({date:{date : new Date()}});
      }, 1000);
    }, 1000);
    </script>
      </body>
    </html>
    `;
    
    var ws_outer;
      
      function sendTime() {
        ws_outer.send(JSON.stringify({data:new Date().ms}));
      }
    
    
     var server = require('ws').createServer(onPageRequest­);
     server.listen(80);
     server.on("websocket", function(ws) {
       ws_outer=ws;
        ws.on('message',function(msg) { console.log((msg)); });
        ws.send("Hello from Espruino!");
        sendTime();
     });
    
    
    });
    };
    

    open a browser with the address echoed:

    Connected to access point, listening for clients {
      "ip": "192.168.15.11",
      "netmask": "255.255.255.0",
      "gw": "192.168.15.1"
     }
    

    Still lots of vars free:

    >process.memory();
    ={ "free": 3858, "usage": 1142, "total": 5000, "history": 528 }
    >ESP32.getState();
    ={
      "sdkVersion": "1.0.0(c418d6b)",
      "freeHeap": 97864 }
    > 
    
About

Avatar for Wilberforce @Wilberforce started