ESP32 - Data Event on Serial2 only one event

Posted on
  • Hello guys !
    I'm new on this forum and beginner in using Espruino. I have some troubles with serial comminication. I'm trying to create a bridge between a TCP and Serial, on the Esp32 board (ESP-WROOM-32).

    let net = require('net');
    let port = 11000;
    
    Serial2.setup(9600, {
        rx: D16,
        tx: D17
    });
    
    // Create NET server
    let server = net.createServer(function (socket) {
    
        socket.on('data', function (datas) {
            console.log("TCP RECEIVED:" + datas.toString());
           // Send datas from TCP over Serial
            Serial2.println(datas.toString());
            console.log("SERIAL SEND :" + datas.toString());
        });
    
        Serial2.on('data', function (str) {
            console.log("SERIAL RECEIVED:" + str.toString());
            socket.write(str.toString());
        });
    });
    
    server.listen(port);
    

    The problem is when the function "Serial2.write(...)" is called, there is no longer a receiving event on "Serial2.on('data',..." when I send data to the serial.

    Before the calling, it works perfertly, but after there is no more event.

    Is there a function for data events after a write? Or do you have the same problem on your Esp32 with Espruino?

    Excuse me for my english, it's not my first language :)

    Hope you can help me

  • The problem persists.Here is a simpler example with my console return. We notice that the event on the serial reception does not work anymore after a writing.

    Code Esp32 - Esrpuino

    Serial2.setup(9600, {rx:D16,tx:D17});
    
    Serial2.on('data', function(data) {
      console.log("<SERIAL> "+data.toString());
      Serial2.write("Hello from Esp32\n");
    });
    

    Console

    TEST_1
    SEND:TEST_1
    RECV:Hello from Esp32
    TEST_2
    SEND:TEST_2
    TEST_3
    SEND:TEST_3
    
    

    Can you help me ?

About

ESP32 - Data Event on Serial2 only one event

Posted by Avatar for mco @mco

Actions