Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make a USB stick version (without Lora) of paxcounter using new ESP32 S3 USB Device API #877

Open
heaversm opened this issue Jul 8, 2022 · 11 comments
Labels
enhancement New feature or request

Comments

@heaversm
Copy link

heaversm commented Jul 8, 2022

I have a node.js web app that can read from the serial port of the computer using this library.

I want to be able to plug in my Lilygo LORA32 (TTGO v3 v1.6.1) to USB on the computer and ingest the pax value to use in my code to drive a web visualization.

I can see that this is being logged in the serial monitor of VSCODE via : senddata.cpp:91 :

sendData() Sending count results pax=7 wifi=1 ble=6

how would I set something up such that I could listen expressly for the pax value coming from the serial monitor and store that to a variable in node.js? I don't need any actual node.js code, just need to know how to set up the serial output in the esp32-paxcounter code (presumably in senddata.cpp?

Thanks for the help!

@cyberman54
Copy link
Owner

cyberman54 commented Jul 9, 2022

don't do it in senddata.cpp.
Make a new sendserial.cpp using spislave.cpp as template.

@cyberman54
Copy link
Owner

@cyberman54
Copy link
Owner

cyberman54 commented Jul 9, 2022

Here is a How To:

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
  4. a free or freeable serial port

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
4: consider if you want to use the USB port, then you probably want to mute/reroute all console output; or using other GPIO

@cyberman54 cyberman54 added the enhancement New feature or request label Jul 9, 2022
@heaversm
Copy link
Author

Really wish I had the knowledge and expertise to understand how to do this - most of this sounds pretty outside of my wheelhouse (web development / basic arduino / pi). Think I'll need to find a way to hire someone to figure this out for me. Appreciate your help!

@cyberman54
Copy link
Owner

Do you have a concept for No. 3?

@heaversm
Copy link
Author

heaversm commented Jul 13, 2022

Well - all my application needs to do is ingest the total number of devices detected (ble + wifi). If I can get to the point where I can read that value over serial, I am good to go. I tried using the packed decoder from your library that gets put into The Things Network. When I put it into my own code and passing the serial output, it returns a wifi / bluetooth count - but I'm not convinced that it is returning accurate values.

This is what I have:

const parser = serialPort.pipe(
  new ReadlineParser({
    delimiter: "\n",
  })
);

const decodedData = Decoder(data);

where Decoder uses:

function Decoder(bytes) {
  var decoded = {};

  if (bytes.length === 0) {
    return {};
  }

  // only wifi counter data, no gps
  if (bytes.length === 2) {
    return decode(bytes, [uint16], ["wifi"]);
  }
  // wifi + ble counter data, no gps
  if (bytes.length === 4) {
    return decode(bytes, [uint16, uint16], ["wifi", "ble"]);
  }
}

@cyberman54
Copy link
Owner

@heaversm

A simple approach:

TTGO boards have ESP32 without USB, but U0RXD/U0TXD of ESP32 connected to USB chip on board, which is normally used to flash the board and for serial console. For your approach you could "misuse" the serial console. That's simple, try this:

  1. Mute device output on the serial console (= USB port of TTGO board), as far as possible
  2. Add prints of payload to serial console, as needed
  3. Switch off Lora, as it's not needed in this use case

How To:

in paxcounter.conf:
#define VERBOSE 0

in platformio.ini:
debug_level = 0

in senddata.cpp:
add this line
ets_printf("$PAX,%d,%d,%d\r\n", count.pax, count.wifi_count, count.ble_count);
after this line
ESP_LOGD(TAG, "Sending count results: pax=%d / wifi=%d / ble=%d", count.pax, count.wifi_count, count.ble_count);

in halfile, e.g. ttgov21new.h:
#define HAS_LORA 0

Then you should get output like this on USB:

$PAX,22,5,17
$PAX,21,1,20
$PAX,21,1,20
$PAX,21,0,21

@cyberman54
Copy link
Owner

@cyberman54 cyberman54 reopened this Jul 14, 2022
@cyberman54 cyberman54 changed the title utilizing the pax count from senddata.cpp over serial in a connected node.js web app Make a USB device version (without Lora) of paxcounter using new ESP32 S3 USB API Jul 14, 2022
@cyberman54 cyberman54 changed the title Make a USB device version (without Lora) of paxcounter using new ESP32 S3 USB API Make a USB stick version (without Lora) of paxcounter using new ESP32 S3 USB Device API Jul 14, 2022
@heaversm
Copy link
Author

heaversm commented Jul 15, 2022

It worked!
pax

Thank you.

I'm not entirely sure why ets_printf works and not ESP_LOGD - I tried searching the ESP-IDF docs for that function and it just says

See ets_printf with no link.

But I did find this rust documentation, which indicates it prints out to "UART and other devices".

At any rate - very grateful for your help, thank you.

@cyberman54
Copy link
Owner

ESP_LOGD is based on ets_printf, but considers log level. Which we set to NONE. To mute all console output for your use case.

@cyberman54
Copy link
Owner

@heaversm so, could you proceed with you project?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants