Console via network socket?

Posted on
  • I've been running an ESP8266 on a Pico to control a servo (venetian blind tilt), using HTTP. However, I'm switching to a TCP socket instead to control via nc, so that I can do immediate variable control from a remote rotary encoder rather than the slow open-request-response-close HTTP method.

    That seems to be working, but I was wondering if it was possible to effectively do socket.setConsole(); I know it's not that straightforward, as it would be if it were acting as a serial port, but is there some way of passing incoming data from socket.on('data', function () { /* pass to console */ })? It'd be nice to just send servo.set(...) commands via nc rather than making up a new protocol.

    Incidentally, I was having trouble running the HTTP server and the TCP socket server running at the same time, even though from what I can see AT+CIPMUX=1 is set. Code:

       var ESP8266 = require("ESP8266WiFi_0v25");
       var Net = require('net');
       var HTTP = require('http');
       // ...
       wifi.connect(..., ..., function (err) {
            // ...
            http = HTTP.createServer(onRequest);
            ssock = Net.createServer(onConnect);

    Error is:

       >Uncaught Error: CIPSERVER failed (no change)
        at line 2 col 20

    If either the http pair or the ssock pair are commented, no problem. Before I spend too much time fiddling, has anyone managed to do two separate servers at the same time, or is this a known limitation?

    Thanks, as ever :)

  • You should be able to shift the Espruino console over with:

    var server = net.createServer(function(c) {
      console.log('server connected');
      c.write('Your welcome message!\r\n');

    You won't be able to Ctrl-C out of loops and things though, since the Wireless is handled with the same priority as normal JS code.

    With multiple servers, I'm afraid that while Espruino doesn't have a problem with it, the ESP8266 module can't handle it (at least using the current ESP8266 AT firmware - I'm sure they could change it in the future).

  • Perfect, thanks @Gordon... it looks like it'll do what I want as long as I'm careful. I had an inkling it'd have something to do with Loopback!

  • That works both ways, you could always do something like is on:Ā­ole

    It's a lot less flexible, but in a way is easier because you're sending one thing to evaluate in one request

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview

Console via network socket?

Posted by Avatar for tom.gidden @tom.gidden