logo elektroda
logo elektroda
X
logo elektroda

Inspecting OBK logs with ncat - shortcut without the Web application

max4elektroda 1668 4
ADVERTISEMENT
📢 Listen (AI):
  • Sometimes I like a short look in the logs of an OpenBeken device without starting the web app and open the "logs" menu.

    Or I like to save or filter the logs over a longer period.

    This can be easily achieved by the connecting to port 9000 of the device.

    I learned about this feature from a comment from @miegapele on git and would like to share it here.


    On linux you would probably use nc/netcat. So, e.g. when working on the Driver for DS1820, I used:

    max@max-PC:~$ nc 192.168.0.37 9000 | grep DS1820
    Info:CFG:DS1820 - asked for conversion - Pin 2
    Info:CFG:DS1820 - Pin=2 temp=+19.37 
    Info:CFG:DS1820 - High=1 Low=54 Val=310 Tc=1937  -- Read CRC=79 - calculated:79 
    Info:CFG:DS1820 - asked for conversion - Pin 2
    Info:CFG:DS1820 - Pin=2 temp=+19.37 
    Info:CFG:DS1820 - High=1 Low=54 Val=310 Tc=1937  -- Read CRC=79 - calculated:79 
    Info:CFG:DS1820 - asked for conversion - Pin 2
    Info:CFG:DS1820 - Pin=2 temp=+19.37 
    Info:CFG:DS1820 - High=1 Low=54 Val=310 Tc=1937  -- Read CRC=79 - calculated:79 
    Info:CFG:DS1820 - asked for conversion - Pin 2
    Info:CFG:DS1820 - Pin=2 temp=+19.37 
    Info:CFG:DS1820 - High=1 Low=54 Val=310 Tc=1937  -- Read CRC=79 - calculated:79 
    Info:CFG:DS1820 - asked for conversion - Pin 2
    Info:CFG:DS1820 - Pin=2 temp=+19.37 
    Info:CFG:DS1820 - High=1 Low=54 Val=310 Tc=1937  -- Read CRC=79 - calculated:79 
    Info:CFG:DS1820 - asked for conversion - Pin 2
    Info:CFG:DS1820 - Pin=2 temp=+19.37 
    Info:CFG:DS1820 - High=1 Low=54 Val=310 Tc=1937  -- Read CRC=79 - calculated:79 
    Info:CFG:DS1820 - asked for conversion - Pin 2
    Info:CFG:DS1820 - Pin=2 temp=+19.37 




    On Windows (if you didn't install WSL) my preferred "swiss army knife" for tasks like this is a windows port of "busybox" (I get the binary from here).

    So you can just start a "shell" there with "busybox sh" and simply use the same command as above :-).

    Screenshot of a Windows console showing the use of busybox to analyze device logs.

    And if there are times, when you miss md5sum, awk or sed - it's also there in this useful little binary.

    The access to the network log is not a full replacement for the log on the hardware UART. But I really like it, especially when "waiting" for entries in the log.

    Cool? Ranking DIY
    About Author
    max4elektroda
    Level 20  
    Offline 
    max4elektroda wrote 502 posts with rating 114, helped 21 times. Been with us since 2024 year.
  • ADVERTISEMENT
  • #2 21246672
    p.kaczmarek2
    Moderator Smart Home
    Very nice method, even I was not aware about that! Still, it could be also good to have logs stored in LittleFS, maybe? At least for debugging purposes and with some filtering, so we don't wear out flash too fast.
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #3 21246726
    divadiow
    Level 34  
    Cool! You could also do it with PowerShell
    Code: Powershell
    Log in, to see the code


    Screenshot showing a PowerShell script for retrieving and filtering logs from a specified IP address and port. Screenshot of a Windows PowerShell window displaying MQTT logs.
  • ADVERTISEMENT
  • #4 21263048
    jkwim
    Level 12  
    max4elektroda wrote:
    Sometimes I like a short look in the logs of an OpenBeken device without starting the web app and open the "logs" menu.

    Or I like to save or filter the logs over a longer period.

    This can be easily achieved by the connecting to port 9000 of the device.

    I learned about this feature from a comment from @miegapele on git and would like to share it here.


    On linux you would probably use nc/netcat. So, e.g. when working on the Driver for DS1820, I used:

    max@max-PC:~$ nc 192.168.0.37 9000 | grep DS1820
    Info:CFG:DS1820 - asked for conversion - Pin 2
    Info:CFG:DS1820 - Pin=2 temp=+19.37 
    Info:CFG:DS1820 - High=1 Low=54 Val=310 Tc=1937  -- Read CRC=79 - calculated:79 
    Info:CFG:DS1820 - asked for conversion - Pin 2
    Info:CFG:DS1820 - Pin=2 temp=+19.37 
    Info:CFG:DS1820 - High=1 Low=54 Val=310 Tc=1937  -- Read CRC=79 - calculated:79 
    Info:CFG:DS1820 - asked for conversion - Pin 2
    Info:CFG:DS1820 - Pin=2 temp=+19.37 
    Info:CFG:DS1820 - High=1 Low=54 Val=310 Tc=1937  -- Read CRC=79 - calculated:79 
    Info:CFG:DS1820 - asked for conversion - Pin 2
    Info:CFG:DS1820 - Pin=2 temp=+19.37 
    Info:CFG:DS1820 - High=1 Low=54 Val=310 Tc=1937  -- Read CRC=79 - calculated:79 
    Info:CFG:DS1820 - asked for conversion - Pin 2
    Info:CFG:DS1820 - Pin=2 temp=+19.37 
    Info:CFG:DS1820 - High=1 Low=54 Val=310 Tc=1937  -- Read CRC=79 - calculated:79 
    Info:CFG:DS1820 - asked for conversion - Pin 2
    Info:CFG:DS1820 - Pin=2 temp=+19.37 
    Info:CFG:DS1820 - High=1 Low=54 Val=310 Tc=1937  -- Read CRC=79 - calculated:79 
    Info:CFG:DS1820 - asked for conversion - Pin 2
    Info:CFG:DS1820 - Pin=2 temp=+19.37 


    I have CYGWIN in my Windows machine.
    Added nc and now it becomes very handy to filter log entries in real time.

    $ nc 192.168.1.250 9000 | awk '/SENSOR NOT/ {print}'
    Error:CMD:cmd SENSOR NOT found (args {"Time":"2024-10-14T21:50:14","ENERGY":{"Power": 1.210776,"ApparentPower": 40.349151,"ReactivePower": 40.330982,"Factor":0.030007,"Voltage":242.087265,"Current":0.166671,"ConsumptionTotal":2059.686523,"Yesterday": 423.476654,"ConsumptionLastHour":0.000000}})
    Error:CMD:cmd SENSOR NOT found (args {"Time":"2024-10-14T21:50:14","ENERGY":{"Power": 1.210776,"ApparentPower": 40.349151,"ReactivePower": 40.330982,"Factor":0.030007,"Voltage":242.087265,"Current":0.166671,"ConsumptionTotal":2059.686523,"Yesterday": 423.476654,"ConsumptionLastHour":0.000000}})
    


    $ nc 192.168.1.250 9000 | awk '/SENSOR NOT/ {gsub(/,/," ");print $16}'
    "ConsumptionTotal":2053.459472
    "ConsumptionTotal":2053.460449
    "ConsumptionTotal":2053.461181
    "ConsumptionTotal":2053.461914
    "ConsumptionTotal":2053.462646
    "ConsumptionTotal":2053.463623
    "ConsumptionTotal":2053.464111
    "ConsumptionTotal":2053.464843
    "ConsumptionTotal":2053.465820
    "ConsumptionTotal":2053.466552
    "ConsumptionTotal":2053.466796
    "ConsumptionTotal":2053.467285


    Complex filtering can be done on the command line to troubleshoot issues:

    $ nc 192.168.1.250 9000 | awk '/SENSOR NOT/ {gsub(/,/," ");print $16} /energycounter/ {gsub(/50-250/,"");print}'
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic openbk7231N-NW/energycounter_last_hour/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic openbk7231N-NW/energycounter_2_days_ago/get
    "ConsumptionTotal":2053.552246
    "ConsumptionTotal":2053.552978
    Info:MQTT:Publishing val 2023-09-13T16:31+05:30 to openbk7231N-NW/energycounter_clear_date/get retain=0
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic openbk7231N-NW/energycounter_clear_date/get
    "ConsumptionTotal":2053.553955
    "ConsumptionTotal":2053.554687
    "ConsumptionTotal":2053.555175
    "ConsumptionTotal":2053.556396
    Info:MQTT:Publishing val 2053.556 to openbk7231N-NW/energycounter/get retain=0
    Info:MQTT:Publishing val 1615.548 to openbk7231N-NW/energycounter_today/get retain=0
    Info:MQTT:Publishing val 423.476 to openbk7231N-NW/energycounter_yesterday/get retain=0
    Info:MQTT:Publishing val 8.245 to openbk7231N-NW/energycounter_3_days_ago/get retain=0
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic openbk7231N-NW/energycounter/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic openbk7231N-NW/energycounter_today/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic openbk7231N-NW/energycounter_yesterday/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic openbk7231N-NW/energycounter_3_days_ago/get
    "ConsumptionTotal":2053.556884
    "ConsumptionTotal":2053.557617
    "ConsumptionTotal":2053.558349
  • #5 21307105
    morgan_flint
    Level 14  
    I've just tried this with PuTTy and works like a charm:
    Screenshot of PuTTY configuration with IP address and telnet port. Screenshot of a PuTTY session displaying TuyaMCU log data.
📢 Listen (AI):
ADVERTISEMENT