I have wrote some test codes:
function onInit(){ var ssid = "ssid"; var wifiOpts = {password:"pwd"}; var wifi = require("Wifi"); wifi.connect(ssid, wifiOpts, function(err){ console.log("connected? err=", err, "info=", wifi.getIP()); var WebSocket = require("ws"); var host = "192.168.1.9"; var ws = new WebSocket(host,{ path: '/', port: 5004, // default is 80 protocolVersion: 13, // websocket protocol version, default is 13 origin: 'Espruino', keepAlive: 60, }); ws.on('open', function() { console.log("connected"); //ws.send('hello, server'); var packet = "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"; var pktNum = 0; var ta = 0; var id = setInterval(function(){ var t1 = getTime(); ws.send(btoa(packet)); pktNum ++; console.log("Packet NO.: " + pktNum + ", time used: " + (t2 = getTime() - t1) + "s"); ta += t2; if(pktNum >=101){ console.log("total time used: " + ta +"s"); clearInterval(id); } }, 100); }); }); }
the result:
connected? err= null info= { "ip": "192.168.1.30", "netmask": "255.255.255.0", "gw": "192.168.1.1", "mac": "30:ae:a4:03:96:a8" } connected Packet NO.: 1, time used: 0.85709s Packet NO.: 2, time used: 0.838764s Packet NO.: 3, time used: 0.856456s Packet NO.: 4, time used: 0.837004s Packet NO.: 5, time used: 0.845455s Packet NO.: 6, time used: 0.847384s Packet NO.: 7, time used: 0.84427s Packet NO.: 8, time used: 0.850653s Packet NO.: 9, time used: 0.840083s Packet NO.: 10, time used: 0.841126s Packet NO.: 11, time used: 0.849597s Packet NO.: 12, time used: 0.846575s Packet NO.: 13, time used: 0.851111s Packet NO.: 14, time used: 0.845253s Packet NO.: 15, time used: 0.861927s Packet NO.: 16, time used: 0.848568s Packet NO.: 17, time used: 0.85375s Packet NO.: 18, time used: 0.839241s Packet NO.: 19, time used: 0.837366s Packet NO.: 20, time used: 0.846501s Packet NO.: 21, time used: 0.851264s Packet NO.: 22, time used: 0.844203s Packet NO.: 23, time used: 0.850979s Packet NO.: 24, time used: 0.851601s Packet NO.: 25, time used: 0.844725s Packet NO.: 26, time used: 0.846098s Packet NO.: 27, time used: 0.84291s Packet NO.: 28, time used: 0.844193s Packet NO.: 29, time used: 0.850243s Packet NO.: 30, time used: 0.854025s Packet NO.: 31, time used: 0.84941s Packet NO.: 32, time used: 0.84723s Packet NO.: 33, time used: 0.84363s Packet NO.: 34, time used: 0.850008s Packet NO.: 35, time used: 0.843929s Packet NO.: 36, time used: 0.859503s Packet NO.: 37, time used: 0.845025s Packet NO.: 38, time used: 0.838622s Packet NO.: 39, time used: 0.86317899999s Packet NO.: 40, time used: 0.847434s Packet NO.: 41, time used: 0.841337s Packet NO.: 42, time used: 0.84749s Packet NO.: 43, time used: 0.845084s Packet NO.: 44, time used: 0.859161s Packet NO.: 45, time used: 0.854041s Packet NO.: 46, time used: 0.853847s Packet NO.: 47, time used: 0.84596s Packet NO.: 48, time used: 0.855874s Packet NO.: 49, time used: 0.846709s Packet NO.: 50, time used: 0.850626s Packet NO.: 51, time used: 0.855101s Packet NO.: 52, time used: 0.843922s Packet NO.: 53, time used: 0.855193s Packet NO.: 54, time used: 0.850098s Packet NO.: 55, time used: 0.85086299999s Packet NO.: 56, time used: 0.843604s Packet NO.: 57, time used: 0.840063s Packet NO.: 58, time used: 0.849205s Packet NO.: 59, time used: 0.84311899999s Packet NO.: 60, time used: 0.847484s Packet NO.: 61, time used: 0.855748s Packet NO.: 62, time used: 0.856332s Packet NO.: 63, time used: 0.849081s Packet NO.: 64, time used: 0.847368s Packet NO.: 65, time used: 0.8664s Packet NO.: 66, time used: 0.855494s Packet NO.: 67, time used: 0.845644s Packet NO.: 68, time used: 0.840538s Packet NO.: 69, time used: 0.847404s Packet NO.: 70, time used: 0.852032s Packet NO.: 71, time used: 0.84936300000s Packet NO.: 72, time used: 0.847706s Packet NO.: 73, time used: 0.851532s Packet NO.: 74, time used: 0.842296s Packet NO.: 75, time used: 0.84484s Packet NO.: 76, time used: 0.847341s Packet NO.: 77, time used: 0.851096s Packet NO.: 78, time used: 0.85451s Packet NO.: 79, time used: 0.853806s Packet NO.: 80, time used: 0.857314s Packet NO.: 81, time used: 0.842491s Packet NO.: 82, time used: 0.84421200000s Packet NO.: 83, time used: 0.846194s Packet NO.: 84, time used: 0.841761s Packet NO.: 85, time used: 0.86257s Packet NO.: 86, time used: 0.847736s Packet NO.: 87, time used: 0.843611s Packet NO.: 88, time used: 0.84158s Packet NO.: 89, time used: 0.84169s Packet NO.: 90, time used: 0.84392s Packet NO.: 91, time used: 0.841432s Packet NO.: 92, time used: 0.849577s Packet NO.: 93, time used: 0.848673s Packet NO.: 94, time used: 0.841546s Packet NO.: 95, time used: 0.845739s Packet NO.: 96, time used: 0.849719s Packet NO.: 97, time used: 0.839512s Packet NO.: 98, time used: 0.838894s Packet NO.: 99, time used: 0.850167s Packet NO.: 100, time used: 0.857364s Packet NO.: 101, time used: 0.846186s total time used: 85.66558500000s
per 230 bytes packet needs 850ms to be transfered to websocket server(nodejs).
@Aifer 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.
I have wrote some test codes:
the result:
per 230 bytes packet needs 850ms to be transfered to websocket server(nodejs).