Avatar for Esper

Esper

Member since Jun 2017 • Last active Jul 2017
  • 1 conversations
  • 16 comments

Most recent activity

  • in JavaScript
    Avatar for Esper

    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 gets something 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.

  • in JavaScript
    Avatar for Esper

    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 the LoopbackB.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
    
  • in JavaScript
    Avatar for Esper

    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"); into LoopbackB 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
    
  • in JavaScript
    Avatar for Esper

    The issue seems to be either LoopbackA.setConsole(); or LoopbackB.write(command());
    The function we wrote works when testing using the usb console LoopbackA.write("Hello");

    Im going to try and use the eval function and see if it makes a difference.

  • in JavaScript
    Avatar for Esper

    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.

  • in JavaScript
    Avatar for Esper

    That didn't work either, I will start debugging now, and will let you guys know when I find the solution.

  • in JavaScript
    Avatar for Esper

    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 the ws.send(msg); to send me back hi I'm not sure if I just misunderstood the concept.

    My understanding is that LoopbackA and LoopbackB are connected, data sent to one comes out the other one. In this manner, if I set console to LoopbackA, 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 expect Hello 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);
    });
    
  • in JavaScript
    Avatar for Esper

    would it be something like this? I would set the console to loopbackA and then call an on data listener for loopbackB and send that via ws?

    LoopbackA.setConsole();
    LoopbackB.on('data',function(msg){
     ws.send(msg);
    });
    
  • in JavaScript
    Avatar for Esper

    I am using a esp8266 12e developing board by NODEMCU given to me by my professor to get an initial setup going. I plan on buying ESPRUINO WIFIs so I can use https and other functionality so i can scale my device network.

    I wrote my own simple web ide and am using a websocket server. I'll look at the docs for loopbackA and loopbackB and see if i can figure it out!

    Thanks, once I'm done ill put up a tutorial.

Actions