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

(Question) How to (only) log values sent? #73

Closed
eikowagenknecht opened this issue Mar 5, 2021 · 2 comments
Closed

(Question) How to (only) log values sent? #73

eikowagenknecht opened this issue Mar 5, 2021 · 2 comments
Labels

Comments

@eikowagenknecht
Copy link

I'm currently experiencing a strange phenomena where one of my modbus devices "automatically" turns itself on. To investigate this further, my idea was to set the logging level in mbusd so that I can see what is sent to the device and when.

I discovered that up lo loglevel 4 sending does not create any log entries, in level 5 it begins to log the request but also very much information that I don't need like all read requests (which happen every 5 seconds) and lots of entries regarding the connection state, so there is very much data written. Logging the response needs an even higher loglevel.

This is currently logged for every command I send (21 lines):

05 Mar 2021 18:12:35 conn_open(): accepting connection from 192.168.40.39
05 Mar 2021 18:12:35 queue_new_elem(): length now is 1
05 Mar 2021 18:12:35 conn[192.168.40.39]: state now is CONN_HEADER
05 Mar 2021 18:12:35 conn[192.168.40.39]: state now is CONN_RQST_FUNC
05 Mar 2021 18:12:35 conn[192.168.40.39]: state now is CONN_RQST_TAIL
05 Mar 2021 18:12:35 conn[192.168.40.39]: request: [f7][06][00][64][00][00]
05 Mar 2021 18:12:35 conn[192.168.40.39]: state now is CONN_TTY
05 Mar 2021 18:12:35 tty: state now is TTY_RQST
05 Mar 2021 18:12:35 tty: state now is TTY_RESP
05 Mar 2021 18:12:35 tty: estimated 8 bytes, waiting 308332 usec
05 Mar 2021 18:12:35 tty: rx offset is 0
05 Mar 2021 18:12:35 tty: read 8 bytes of 8, offset 0
05 Mar 2021 18:12:35 tty: state now is TTY_PROC
05 Mar 2021 18:12:35 tty: response read (total 8 bytes, offset 0 bytes)
05 Mar 2021 18:12:35 tty: response is correct
05 Mar 2021 18:12:35 conn[192.168.40.39]: state now is CONN_RESP
05 Mar 2021 18:12:35 tty: state now is TTY_PAUSE
05 Mar 2021 18:12:35 conn[192.168.40.39]: state now is CONN_HEADER
05 Mar 2021 18:12:35 conn_close(): closing connection from 192.168.40.39
05 Mar 2021 18:12:35 queue_delete_elem(): length now is 0
05 Mar 2021 18:12:36 tty: state now is TTY_READY

This would be the information I'd like to log:

05 Mar 2021 18:12:35 conn[192.168.40.39]: request: [f7][06][00][64][00][00]
05 Mar 2021 18:12:35 conn[192.168.40.39]: response: [f7][06][00][64][00][00][dc][83]

Is there a possibility to achieve a log like this without generating tens of thousands of lines of logs?

@eikowagenknecht eikowagenknecht changed the title (Question) How to log values sent? (Question) How to (only) log values sent? Mar 5, 2021
@3cky 3cky added the question label Mar 9, 2021
@3cky
Copy link
Owner

3cky commented Mar 9, 2021

Right now mbusd doesn't have an option to log request/responses only, but you could use -L- option to enable logging to stdout and then use filtering. Something like this:

mbusd -p /dev/ttyUSB0 -s 9600 -P 502 -d -v5 -L- | grep "request:\|response:" > log.txt

@eikowagenknecht
Copy link
Author

Thanks for the workaround, that will do the trick for now :-)

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

No branches or pull requests

2 participants