Further progress made:
save()
wifi.save()
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-scale=1"> <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/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.innerHTML='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(event.data)); ul.appendChild(li); }; setTimeout(function () { //ws.send(JSON.stringify({click:{count:count}})); //ws.send(JSON.stringify({info:{value:'Hello 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 } >
@Wilberforce started
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Further progress made:
save()
works - and on reboot loads saved codewifi.save()
saves the current connects and reloads on rebootSo after wifi connect and save, here is a example using websockets:
open a browser with the address echoed:
Still lots of vars free: