1

I have an esp32 board loaded with this software which is logging values about the number of detected wifi and bluetooth devices detected via LoraWAN. In senddata.cpp it seems to be logging out the values that I need (though I'm not quite sure I understand how or where it is sending them via serial):

ESP_LOGD(TAG, "Sending count results: pax=%d / wifi=%d / ble=%d", count.pax, count.wifi_count, count.ble_count);

I set up a node.js app with the SerialPort.io library to be able to read data coming over serial. I've successfully identified the COM port on my PC that is receiving data, and I can log out the data buffer as follows:

const SerialPort = require("serialport").SerialPort;

const serialPort = new SerialPort({
  path: "COM4",
  baudRate: 9600,
  autoOpen: false,
});

serialPort.open(function (error) {
  if (error) {
    console.log("failed to open: " + error);
  } else {
    console.log("serial port opened");

    serialPort.on("data", function (data) {
      // get buffered data and parse it to an utf-8 string
      console.log(data);
      data = data.toString("utf-8");
      console.log(data);
    });

    serialPort.on("error", function (data) {
      console.log("Error: " + data);
    });
  }
});

Which yields output in node.js as a buffer, e.g. <Buffer bc 08 AD> and, after the toString("utf-8") as a bunch of gibberish. Clearly I am not encoding or decoding the serial output properly, but I'm not sure where to make adjustments. Does anyone know how I can get this serial output into the proper format to use in node.js?

--- Update Re: Questions ---

The board is a ttgo / lilygo lora32 - the library I used seems to say it supports both this board and communication over SPI. I am able to get readable data via the debug console in platform.io extension for vscode on windws / mac. I believe the baud is 9600, which was the only thing I seemed to need to specify on the serialports.io side.

I did receive this advice from the library author:

You need

  1. a messagebuffer, to store the payload
  2. a queue, as buffer for the serial data
  3. a protocol, suitable for your application

1+2: see spislave.cpp (change the SPI transmit calls by serial port calls) 3: consider overhead and checksum, e.g. transfer the payload as byte array or UTF8 string, e.g. comma separated string with checksum, as used in NMEA.

Unfortunately I'm a bit out of my depth to make sense of that (though I'm working on it).

Also - the javascript code that has successfully worked via the things network uses to decode the payload from the board is here.

4
  • Can you receive readable data from the ESP32 on your computer using standard comms software? E.g. PuTTY on Windows, screen or minicom on Linux, etc.? Are the serial port settings correct (speed, bits, parity..)?
    – jcaron
    Jul 10, 2022 at 21:36
  • What type of board are you using? If the board does not have UART/USB conversion built-in, what are you using for this? Note also that the software you use is not designed to send data over serial, you are just counting on debug logs, which may or may not be enabled depending on your build settings. But bc 08 ad definitely does not look like text.
    – jcaron
    Jul 10, 2022 at 21:50
  • The board is a ttgo / lilygo lora32 - tinyurl.com/lilygo - the library I used seems to say it supports both this board and communication over SPI. I am able to get readable data via the debug console in platform.io extension for vscode on windws / mac. I believe the baud is 9600, which was the only thing I seemed to need to specify on the serialports.io side. Updated the question with this context.
    – mheavers
    Jul 10, 2022 at 22:37
  • If you're getting gibberish, you have either the speed/parity, etc set wrong or got something wrong with flow control. I was going to say maybe also grounding issues but you're able to make it work with certain software. Are you sure it isnt running ppp or some other thing on top of plain serial ? Jul 18, 2022 at 20:26

1 Answer 1

0

The problem may be related to this issue. This is how I got it working.

const port = new SerialPort({
  path: "COM4", baudRate: 115200,
  databits: 8,
  parity: false,
  stopbits: 1
});
port.on("open", function () {
  port.set({
    dtr: true,
    rts: true
  });

    // Read data from the port and parse as JSON
  port.on('data', (data) => {
    console.log('Data', data.toString('utf8'));
  });
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.