rust icon indicating copy to clipboard operation
rust copied to clipboard

Error in the handling of the serial buffer

Open RCGV1 opened this issue 1 year ago • 7 comments

I was running the network management client, which was connected via serial to a node running the latest version. I got this error: [2025-01-04][06:54:56][ERROR][meshtastic::connections::stream_buffer] Could not find header sequence [0x94, 0xc3], purging buffer and waiting for more data

RCGV1 avatar Jan 04 '25 22:01 RCGV1

That's not really an error, this just says there's random data coming down the serial port, most probably our debug logging. The client will just discard it.

caveman99 avatar Jan 05 '25 19:01 caveman99

I guess the "fix" would be to lower message severity to debug or trace.

krant avatar Feb 02 '25 02:02 krant

If it's random data from debug logging which is expected, I don't think this should cause an ERROR log message. I'll look into it at some point. I also don't think downgrading log message severity is the solution, it could hide important issues with user setup or bugs.

lukipuki avatar Feb 19 '25 16:02 lukipuki

I reproduced this, it's not a cosmetic problem, it pollutes the logs if you log every error. For me it's hundreds of lines of logs every twenty seconds. If I run meshtastic --port /dev/ttyACM0 --noproto, I get battery state every 20 seconds, it's probably that.

lukipuki avatar Jul 15 '25 17:07 lukipuki

I tried to fix this in the same way the Python packages does it, see

  • https://github.com/meshtastic/python/blob/213faa0cae0504ca5b49a03fa9a3c47c75ecca09/meshtastic/stream_interface.py#L173
  • https://github.com/meshtastic/python/blob/213faa0cae0504ca5b49a03fa9a3c47c75ecca09/meshtastic/stream_interface.py#L132

However, I wasn't successful, I'll try again when I have more time.

As a workaround, you can ignore the logs of meshtastic::connections::stream_buffer.

  • For env_logger, you can add .filter_module("meshtastic::connections::stream_buffer", log::LevelFilter::Off)
  • For fern, you can add .level_for("meshtastic::connections::stream_buffer", log::LevelFilter::Off)

lukipuki avatar Jul 15 '25 19:07 lukipuki

While developing my project I did some more tests. The crate also prints 3 log messages (WARN, ERROR and ERROR) when you unplug the serial device, when one would suffice.

The whole logging, at least for serial needs an overhaul.

lukipuki avatar Jul 16 '25 19:07 lukipuki

+1 for the overhaul. I had a gut feeling about that too and replicated python parser some time ago - https://github.com/krant/meshtastic-rs/blob/patch/src/connections/stream_buffer.rs#L45-L73. It was working fine for me, but one test was failing (I believe python implementation would fail that test too) so I did not bother to create a PR.

krant avatar Jul 16 '25 19:07 krant