Avatar for user106712

user106712

Member since Dec 2019 • Last active Sep 2020
  • 6 conversations
  • 20 comments

Most recent activity

    • 5 comments
    • 429 views
  • in ESP8266
    Avatar for user106712

    Using hubSerial.available() - rather than hubSerial.data('on') - to chunk the input stream seems to make some difference (fewer errors) at 4800 baud. But no difference at 2400 (mostly good) or 9600 (bad transmission). See code below (both .available and .on('data') fragments are included:

    var d0 = console.log;
    var debug = console.log;
    
    var hubSerial = new Serial();
    var usbSerial = new Serial();
    
    function onInit() {
        hubSerial.setup(4800, { // problematic when baud rate=9600
            rx: NodeMCU.D5,
            tx: NodeMCU.D6
        });
        usbSerial.setup(9600, {
            rx: NodeMCU.D9,
            tx: NodeMCU.D10
        });
    
        usbSerial.on('data', function (data) {
            try {
                hubSerial.print(data);
            } catch (e) {
                d0("failed to send on hub's data");
            }
        });
      
        //*
        hubSerial.on('framing', function (data) {
            d0("framing error");
        });
        
        setInterval(() => {
            let n = hubSerial.available();
            if (n > 0) {
                //d0(n);
                let d = hubSerial.read(0);
                usbSerial.print(d);
            }
        }, 200);
        //*/
    
        /*
        hubSerial.on('data', function (data) {
            try {
             // d0(data.length);
                usbSerial.print(data);
            } catch (e) {
                d0("failed to send on usb's data");
            }
        });
        //*/
    }
    
  • in ESP8266
    Avatar for user106712

    I am using two soft serials, taking input from one UART and passing it to the USB UART.

    var hubSerial = new Serial(); 
        hubSerial.setup(2400, { // problematic when baud rate=9600
            rx: NodeMCU.D5,
            tx: NodeMCU.D6
        });
        var usbSerial = new Serial(); 
        usbSerial.setup(9600, {
            rx: NodeMCU.D9,
            tx: NodeMCU.D10
        });
    
        usbSerial.on('data', function (data) {
            try {
                hubSerial.print(data);
            } catch (e) {
                d0("failed to send on hub's data");
            }
        });
        hubSerial.on('data', function (data) {
            try {
                usbSerial.print(data);
            } catch (e) {
                d0("failed to send on usb's data");
            }
        });
    

    d0() is essentially console.log over port 23.

    The PIN assignment cannot be changed hence the use of soft serial. I think the issue is that .on('data',..) is coming back 1 or 2 bytes at a time. I will experiment using .available().

  • in ESP8266
    Avatar for user106712

    From http://www.espruino.com/USART

    "As software serial doesn't use dedicated hardware there are some compromises:

    Baud rates significantly above 9600 baud are unlikely to be reliable
    Sending more than one or two characters will block execution of other JavaScript code until completion (hardware serial ports have a ~100 byte transmit buffer)
    Software serial reception will become increasingly unreliable the higher the CPU load."

    In my application, I use soft serial (rx=D5, tx=D6). I get bursts of 60+ bytes (5x a second) from an external source. I find that anything beyond 2400 baud increases errors in the data received. What's the experience of others?

    Using an Amica 8266 board.

  • in ESP8266
    Avatar for user106712

    The socket object returned from createServer() shows (using JSON.stringify(sock)):

    {"type":0,"sckt":15,"conn":true}

    Are the above the only key/value pairs available?

    sock.remoteAddress and sock.remotePort are both undefined.

    Can these be discovered somehow?

  • in Puck.js, Pixl.js and MDBT42
    Avatar for user106712

    Not as far as I know. Both Pucks now behave well. Thanks.

  • in Puck.js, Pixl.js and MDBT42
    Avatar for user106712

    Your first line (D25,D26) produces result but not (D26,D26)!

    
    var cmds = {
    
        // main menu top left - select
        mainSelect: [
    9.0, 4.4, 0.6, 0.5, 0.6, 1.6, 0.6, 1.6, 0.6, 0.5, 0.6, 0.5, 0.6, 0.5, 0.6, 0.5, 0.6, 1.6, 0.6, 1.6, 0.6, 0.5, 0.6, 1.6, 0.6, 0.5, 0.6, 0.5, 0.6, 0.5, 0.6, 0.5, 0.6, 0.5, 0.6, 0.5, 0.6, 0.5, 0.6, 0.5, 0.6, 0.5, 0.6, 1.6, 0.6, 0.5, 0.6, 1.6, 0.6, 0.5, 0.6, 1.6, 0.6, 1.6, 0.6, 1.6, 0.6, 1.6, 0.6, 0.5, 0.6, 1.6, 0.6, 0.5, 0.6, 1.6, 0.6, 42.9, 9.0, 2.2, 0.6, 95.9, 9.0, 2.2, 0.6, 95.9, 9.0, 2.2, 0.6, 95.9, 9.0, 2.2, 0.6, 95.9, 9.0, 2.2, 0.6, 95.9, 9.0, 2.2, 0.6, 95.9, 9.0, 2.2, 0.6, 95.9, 9.0, 2.2, 0.6
    ]};
    
    /* received on the other end (D25,D26):
    4.4,0.5,0.6,0.5,1.6,0.5,1.6,0.6,0.5,0.5,­0.5,0.5,0.5,0.5,0.5,0.6,1.6,0.6,1.6,0.6,­0.5,0.6,1.6,0.6,0.5,0.6,0.5,0.6,0.5,0.6,­0.5,0.6,0.5,0.6,0.5,0.6,0.5,0.6,0.5,0.6,­0.5,0.5,1.6,0.6,0.5,0.6,1.6,0.6,0.5,0.6,­1.6,0.5,1.6,0.6,1.6,0.6,1.6,0.5,0.5,0.6,­1.6,0.6,0.5,0.6,1.6,0.6,42.9,8.9,2.3,0.5­,95.9,8.9,2.3,0.5,95.9,8.9,2.2,0.7,95.9,­8.9,2.2,0.7,95.9,8.9,2.2,0.6,95.9,9.0,2.­2,0.6,95.9,9.0,2.2,0.6,95.9,8.9,2.2
    0.2
    */
    

    I guess I will use D25,26 for transmission.

    A query: not sure why the first value is consistently missing (i.e. 9.0).

    Am I in fact transmitting the inverse pattern or am I just not understanding the IR protocol? (The definition file was captured (transmitted from a physical remote) using the same Receiver code, i.e. (from you!)

    function onInit() {
    
        digitalWrite(D2, 0);
        pinMode(D1, "input_pullup");
        var d = [];
        setWatch(function (e) {
            d.push(1000 * (e.time - e.lastTime));
        }, D1, {
            edge: "both",
            repeat: true
        });
    
    
        var lastLen = 0;
        setInterval(function () {
            if (d.length && d.length == lastLen) {
                d.shift(); // remove first element
                console.log(d.map(a => a.toFixed(1)).toString());
                d = [];
            }
            lastLen = d.length;
        }, 200);
    
        setInterval(() => LED3.toggle(), 500);
    
    }
    
  • in Puck.js, Pixl.js and MDBT42
    Avatar for user106712

    Thanks - I am using v2.05 firmware (Sep 2019 vintage PuckJS). The onboard IR LED transmits in the ~940nm (same as mine) so it's odd that the same receiver does not see it.

    I have now inverted the roles of the two PuckJS. Again the same phenomenon (second Puck sees the IR signal from my own LED but not Puck's). It is unlikely that the transmitter on both Pucks are faulty. But I don't have anything else to test them with. Any idea?

Actions