Most recent activity
-
Sorry for such a late response, my laptop broke and I had to reset up everything from scratch on a new machine.
So one of my goals here was to get the REPL to be accessible over websockets. I tried the following as suggested, and it resulted in the program emitting the following error messages over websockets to my webIDE.
ws.on('message', function(msg) { LoopbackB.write(msg); }); LoopbackB.on('data',function(msg) { ws.send(msg); });
complete code
var host = "192.168.1.***"; var WebSocket = require("ws"); var ws = new WebSocket(host, { path: '/', port: 8080, // default is 80 protocol: "echo-protocol", // websocket protocol name (default is none) protocolVersion: 13, // websocket protocol version, default is 13 origin: 'Espruino', keepAlive: 60, headers: { some: 'header', 'ultimate-question': 42 } // websocket headers to be used e.g. for auth (default is none) }); ws.on('open', function() { console.log("Connected to server"); ws.send("esp:Connected"); }); ws.on('message', function(msg) { LoopbackB.write(msg.toString()); }); LoopbackB.on('data',function(msg) { ws.send(msg); }); setTimeout(function() { LoopbackA.setConsole(); },100);
Error transmitted over websockets continually until program is forced to stop
<- Telnet UncauUncaught SyntaxError: Got ':' expected EOF at Uncaught SyntaxError: Got ':' expected EOF at =19 =un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=unUncaught Syn>> at Uncaught Erro> at line 1 c> at line 1 cUncaught SyntaxError: Got '^' exUncaught Syn>>=und=und=und=undUncaught SyntaxError: Got ':' expected E=und=undUncaught SyntaxError: Got ':' expected E=und=undUncaught SyntaxError: Got ':' expected E=und=undUncaught SyntaxError: Got ':' expected E=und=und=und=undUnca=und=undUncaught Synt
The exact error msg is the following
=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un>=un received: <- Telnet UncauUncaught SyntaxError: Got ':' expected EOF at Uncaught SyntaxError: Got ':' expected EOF at =19
I'm not sure what I'm doing wrong. Any insight? line 19 is just closing braces.
-
Ok Ill try that, but I think the infinite loop is being caused by the ws server broadcasting the msg to everyone. So basically if the device sends
something
it getssomething
back which it then sends out again... I'll have to update my server for individual addressing.edit. I tried that and there was no response at all. Im going to work on the indvidual addressing for ws to fix the bounce back of msgs for the esp8266.
-
Ok so I put in the `setTimeout(function() { LoopbackA.setConsole();},100); and it WORKS!!! HUZZAH, but there is an issue, after sending over the response, it sends over an infinite stream of the error after logging the return. I have to reset manually to kill the stream.
I think this is because the error msg itself counts as
data
and so theLoopbackB.on('data',function(msg){ ws.send(msg); });
function goes into an infinite loop.Webconsole below.
>>Server:Ready! >>console.log("Hello"); >>Hello Uncaught TypeError: Expecting a number or something iterable, got undefined at line 2 col 29 LoopbackB.write(command()); ^ in function called from system >>Uncaught SyntaxError: Got ':' expected EOF at line 2 col 19 Uncaught TypeError: Expecting a number or something iterable... ^ in function "command" called from line 2 col 28 LoopbackB.write(command()); ^ in function called from system >>Uncaught SyntaxError: Got ':' expected EOF at line 1 col 21 Uncaught SyntaxError: Got ':' expected EOF ^ in function "command" called from line 2 col 28 LoopbackB.write(command()); ^ in function called from system >>Uncaught SyntaxError: Got ':' expected EOF at line 1 col 21 Uncaught SyntaxError: Got ':' expected EOF ^ in function "command" called from line 2 col 28 LoopbackB.write(command()); ^ in function called from system >>Uncaught SyntaxError: Got ':' expected EOF at line 1 col 21 Uncaught SyntaxError: Got ':' expected EOF ^ in function "command" called from line 2 col 28 LoopbackB.write(command()); ^ in function called from system >>Uncaught SyntaxError: Got ':' expected EOF at line 1 col 21 Uncaught SyntaxError: Got ':' expected EOF ^ in function "command" called from line 2 col 28 LoopbackB.write(command()); ^ in function called from system >>Uncaught SyntaxError: Got ':' expected EOF at line 1 col 21 Uncaught SyntaxError: Got ':' expected EOF ^ in function "command" called from line 2 col 28 LoopbackB.write(command()); ^ in function called from system >>Uncaught SyntaxError: Got ':' expected EOF at line 1 col 21 Uncaught SyntaxError: Got ':' expected EOF ^ in function "command" called from line 2 col 28 LoopbackB.write(command()); ^ in function called from system
-
Ok I think I know what the issue is basically the
write
method has an issue with passing it functions. Feel free to look at the screenshot or logs below.When I pass
LoopbackA.write("Hello");
,Hello
is transmitted across ws.When I pass
LoopbackB.write(digitalWrite(D5,1));
The LED is turned on, but the error below is given.When I pass
LoopbackB.write(digitalWrite(D5,0));
The LED is turned off, but the error below is given.When I pass
console.log("test");
test prints out to the ESPRUINO IDE but is not transmitted and the same error is given.I also tried directly passing
console.log("test");
intoLoopbackB
but got the same error.Check out the attached screenshot, it's much easier to see.
Console from ESPRUINO WEB IDE>LoopbackA.write("Hello"); =undefined >LoopbackA.write(digitalWrite(D5,1)); Uncaught TypeError: Expecting a number or something iterable, got undefined at line 1 col 35 LoopbackA.write(digitalWrite(D5,1)); ^ >
CONSOLE FROM MY WEB APP
>>Server:Ready! >>Hello
-
-
I was messing around and shifting code, I moved
LoopbackA.setConsole();
to the bottom, and the device started to transmit error messages to my webUI over websockets!!! So it's possible just not configured correctly.in function "command" called from line 2 col 27 LoopbackB.write(command()); ^ in function called from system > received:Uncaught SyntaxError: Got ?[8] expected EOF at line 1 col 1 Uncaught SyntaxError: Got ?[8] expected EOF ^
I am very EXCITED will keep you guys posted.
-
-
hmm it makes sense, but when I execute the code and send over something along the lines of
console.log("hi");
the loopback wont trigger thews.send(msg);
to send me backhi
I'm not sure if I just misunderstood the concept.My understanding is that
LoopbackA
andLoopbackB
are connected, data sent to one comes out the other one. In this manner, if I set console toLoopbackA
, and then write my ws incoming command the following function should work.I've been testing with
console.log("Hello");
from my ws server and I expectHello
back. I know the ws stuff is working fine, so it's probably that i miscoded the loopbacks.LoopbackA.setConsole(); var host = "192.168.1.103"; var WebSocket = require("ws"); var ws = new WebSocket(host, { path: '/', port: 8080, // default is 80 protocol: "echo-protocol", // websocket protocol name (default is none) protocolVersion: 13, // websocket protocol version, default is 13 origin: 'Espruino', keepAlive: 60, headers: { some: 'header', 'ultimate-question': 42 } // websocket headers to be used e.g. for auth (default is none) }); ws.on('open', function() { console.log("Connected to server"); ws.send("esp:Connected"); }); ws.on('message', function(msg) { console.log(msg); var command = new Function(msg); LoopbackA.write(command()); }); LoopbackB.on('data',function(msg){ ws.send(msg); });
Ahh, it makes sense now. My server is set to broadcast all messages to all ws devices that are connected. I'll reconfigure it with an ID system for routing. That should hopefully solve my issue.
I'll keep you updated thanks!