I'm testing on a ESP8266-01 with 1MB of flash, I think the NodeMCU has 4MB.
The latest test program follows and allows for you to refresh the page to get multiple timings.
I've also change the HTML script to display data.length instead of data.
I've added process.memory() to fix a bug in E.toString() and asked for the bug to be examined in another post.
Once the page is online you might try from a command prompt ping IP address
example ping 192.168.1.13
This will give you an idea of the wifi speed and if there is a lot of traffic or errors occurring.
//WSDesp8266B 28Jan2018
//http//192.168.1.6:8080
//ESP8266 with Espruino flahed
// list of Wifi and passwords
var SSID="ssid";
var key="keykey";
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.length;\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));
process.memory();
}else{
process.memory();
n=4;
}//end else
});
t=getTime();
ws.send(E.toString(tdata));
process.memory();
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();
Here is some output:
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 1MB:512/512, manuf 0xe0 chip 0x4014
>Start connection process
Try Connecting to WiFi faux
=undefined
Test for error
Test for error
null
connected? err= null info= {
"ip": "192.168.1.13",
"netmask": "255.255.255.0",
"gw": "192.168.1.1",
"mac": "18:fe:34:cb:2c:23"
}
Wi-Fi Connected
n= 4 t: 0.016 sec
n= 3 t: 0.098 sec
[WS] "Hello to Espruino!"
n= 2 t: 0.169 sec
[WS] "Hello to Espruino!"
n= 1 t: 0.239 sec
[WS] "Hello to Espruino!"
n= 0 t: 0.309 sec
[WS] "Hello to Espruino!"
n= 4 t: 0.012 sec
n= 3 t: 0.083 sec
[WS] "Hello to Espruino!"
n= 2 t: 0.151 sec
[WS] "Hello to Espruino!"
n= 1 t: 0.881 sec
[WS] "Hello to Espruino!"
n= 0 t: 0.951 sec
[WS] "Hello to Espruino!"
n= 4 t: 0.012 sec
n= 3 t: 0.089 sec
[WS] "Hello to Espruino!"
n= 2 t: 0.164 sec
[WS] "Hello to Espruino!"
n= 1 t: 0.233 sec
[WS] "Hello to Espruino!"
n= 0 t: 0.307 sec
[WS] "Hello to Espruino!"
n= 4 t: 0.012 sec
n= 3 t: 0.089 sec
[WS] "Hello to Espruino!"
n= 2 t: 0.846 sec
[WS] "Hello to Espruino!"
n= 1 t: 0.909 sec
[WS] "Hello to Espruino!"
n= 0 t: 0.994 sec
[WS
Some variation in the speed
Here are some ping timings:
Microsoft Windows [Version 10.0.16299.192]
(c) 2017 Microsoft Corporation. All rights reserved.
C:\Users\jj>ping 192.168.1.13
Pinging 192.168.1.13 with 32 bytes of data:
Reply from 192.168.1.13: bytes=32 time=2ms TTL=128
Reply from 192.168.1.13: bytes=32 time=2ms TTL=128
Reply from 192.168.1.13: bytes=32 time=3ms TTL=128
Reply from 192.168.1.13: bytes=32 time=3ms TTL=128
Ping statistics for 192.168.1.13:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 2ms, Maximum = 3ms, Average = 2ms
C:\Users\jj>ping 192.168.1.13
Pinging 192.168.1.13 with 32 bytes of data:
Reply from 192.168.1.13: bytes=32 time=2ms TTL=128
Reply from 192.168.1.13: bytes=32 time=1ms TTL=128
Reply from 192.168.1.13: bytes=32 time=2ms TTL=128
Reply from 192.168.1.13: bytes=32 time=3ms TTL=128
Ping statistics for 192.168.1.13:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 1ms, Maximum = 3ms, Average = 2ms
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.
Since you are using a NodeMCU the flashing map is described here:
FlashNodeMCU
I'm testing on a ESP8266-01 with 1MB of flash, I think the NodeMCU has 4MB.
The latest test program follows and allows for you to refresh the page to get multiple timings.
I've also change the HTML script to display data.length instead of data.
I've added process.memory() to fix a bug in E.toString() and asked for the bug to be examined in another post.
Once the page is online you might try from a command prompt ping IP address
example ping 192.168.1.13
This will give you an idea of the wifi speed and if there is a lot of traffic or errors occurring.
Here is some output:
Some variation in the speed
Here are some ping timings: