The HTML code splits data into lines in this one.
//WSDesp8266 24Jan2018 //http//192.168.1.6:8080 //ESP8266 with Espruino flashed // list of Wifi and passwords var SSID="xxxxxx"; var key="keykeykey"; var Startagain=0; var myinterval; var n =4, chk=2*1024; var tdata=new Uint8Array(chk); var i; for(i=0;i<1024;i++){ tdata[i]=0x30; tdata[i+1024]=0x31; }//next i var page = "<html>\r\n<body>\r\n<textarea id=\"demo\" rows=\"32\" cols=\"64\"></textarea>\r\n<script>\r\nvar ws;\r\nvar data=\"\";\r\n//setTimeout(function(){\r\nws = new WebSocket(\"ws://\" + location.host + \"/my_websocket\", \"protocolOne\");\r\nws.onmessage = function (event) { \r\ndata+=event.data;\r\ndocument.getElementById(\"demo\").innerHTML = data;\r\nws.send(\"Hello to Espruino!\"); \r\n };\r\n//setTimeout(function() { ws.send(\"Hello to Espruino!\"); }, //1000);}\r\n//,1000);\r\n\r\n</script></body>\r\n</html>\r\n" ; function onPageRequest(req, res) { res.writeHead(200, {'Content-Type': 'text/html'}); res.end(page); } function test(){ console.log("Start connection process"); var wifi = require("Wifi"); console.log("Try Connecting to WiFi ",SSID); wifi.connect(SSID,{password:key}, function(err) { console.log(err); if (err){Startagain=1;return; } console.log("connected? err=", err, "info=", wifi.getIP()); console.log("Wi-Fi Connected"); clearInterval( myinterval); var t=getTime(); var server = require('ws').createServer(onPageRequest); server.listen(8080); server.on("websocket", function(ws) { ws.on('message',function(msg) { n--; print("n=",n,"t:",(getTime()-t).toFixed(3),"sec"); print("[WS] "+JSON.stringify(msg)); if(n) ws.send(E.toString(tdata)); }); t=getTime(); ws.send(E.toString(tdata)); print("n=",n,"t:",(getTime()-t).toFixed(3),"sec"); }); });//end connect }//end test myinterval=setInterval(function () { console.log("Test for error"); if(Startagain){ Startagain=0; test(); }//end of Startagain }, 2000); test();
1v95 Copyright 2017 G.Williams Espruino is Open Source. Our work is supported only by sales of official boards and donations: http://espruino.com/Donate Flash map 512KB:256/256, manuf 0x1f chip 0x8401 >Start connection process Try Connecting to WiFi faux =undefined null connected? err= null info= { "ip": "192.168.1.12", "netmask": "255.255.255.0", "gw": "192.168.1.1", "mac": "5c:cf:7f:8b:1b:99" } Wi-Fi Connected n= 4 t: 0.015 sec n= 3 t: 0.118 sec [WS] "Hello to Espruino!" n= 2 t: 0.209 sec [WS] "Hello to Espruino!" n= 1 t: 0.327 sec [WS] "Hello to Espruino!" n= 0 t: 0.426 sec [WS] "Hello to Espruino!" >
8192 bytes sent 0.426 - 0.015 = 0.411 seconds 8192 / 0.411 = 19,931.9 bytes per second 19931.9 * 8 = 159,454.9 bits per second
@ClearMemory041063 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.
Running on Sparkfun Thing -dev ESP8266 board
The HTML code splits data into lines in this one.
Sending 2 kbytes of data 4 times
8192 bytes sent
0.426 - 0.015 = 0.411 seconds
8192 / 0.411 = 19,931.9 bytes per second
19931.9 * 8 = 159,454.9 bits per second