I am trying to use an ESP32 device to send custom messages to a computer via USB (e.g. CP2102<->UART), as well as be able to record all console messages (boot log, printf, etc) to display them on the computer and/or save them to a log file, etc.
I'd like to be able to use a single USB<->serial connection to send both my custom messages, and the log lines (maybe using multiple UARTs, but only if they can share the same USB port). Any suggestions on how to do this?
Some basic ideas I have thought of, but there might be a much better way:
- Override esp-idf logging, convert everything to JSON (e.g. {level: "ESP_LOGI", msg: "blah"}), so custom messages would also be JSON alongside the regular logs.
- Use some framing protocol (eg. SLIP encoding w/ begin/end) when switching between sending LOGS and MESSAGES.
- I think this is what serial PPP is sometimes used for? Maybe esp-idf logging could be overridden to send PPP packets for each log message?