Open heaversm opened 2 years ago
don't do it in senddata.cpp. Make a new sendserial.cpp using spislave.cpp as template.
Here is a How To:
You need
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
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!
Do you have a concept for No. 3?
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"]);
}
}
@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:
How To:
1)
in paxcounter.conf:
#define VERBOSE 0
in platformio.ini:
debug_level = 0
2)
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);
3) in halfile, e.g. ttgov21new.h:
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
reopened as enhancement idea with new titel
It worked!
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.
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.
@heaversm so, could you proceed with you project?
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 insenddata.cpp
?Thanks for the help!