How to Record Ping360 Log Data in a .bin File? ( like as pingviwer GUI record sensor log )

I am using a Raspberry Pi to interface with a Ping360 sensor and record data in a .bin log file format, similar to PingViewer. The Ping360 sensor is connected to my headless Raspberry Pi, and I aim to accomplish this using a Python script.

I have established communication with the Ping360 sensor using the ping-python libraries. The sensor is connected to the Raspberry Pi via serial communication, and I am using the following code to start the connection:

from brping.ping360 import Ping360
myPing = Ping360()
myPing.connect_serial("/dev/ttyUSB0", 115200)

message = myPing.get_device_data()

        if message is not None:
            print("Payload:")
            print(f"  - mode: {message['mode']}")
            print(f"  - gain_setting: {message['gain_setting']}")
            print(f"  - angle: {message['angle']}")
            print(f"  - transmit_duration: {message['transmit_duration']}")
            print(f"  - sample_period: {message['sample_period']}")
            print(f"  - transmit_frequency: {message['transmit_frequency']}")
            print(f"  - number_of_samples: {message['number_of_samples']}")
            print(f"  - data_length: {len(message['data'])}")
            data_hex_strings = [f'0x{byte:02x}' for byte in message['data']]
            print(f"  - data: {data_hex_strings}")

However, I am unsure how to save sensor log data in a .bin file like PingViewer.

Can someone guide me on modifying my Python script to continuously store Ping360 sensor log data in a .bin file? I’d appreciate help with code modifications and additional steps. Your assistance would be invaluable in recording the sensor data for analysis.

this data decode from pingviewer gui
Decode message format

--------------------------------------------------
ID: 2300 - device_data
Header: start_1: 66 start_2: 82 payload_length: 1214 message_id: 2300 src_device_id: 2 dst_device_id: 0
Payload:
  - mode: 1
  - gain_setting: 0
  - angle: 8
  - transmit_duration: 11
  - sample_period: 88
  - transmit_frequency: 750
  - number_of_samples: 1200
  - data_length: 1200
  - data: ['0x40', '0x91', '0xc3', '0xe6', '0xff', '0xff', '0xff', '0xff', '0xff', '0xff', '0xff', '0xff', '0xff', '0xff', '0xff', '0xff', '0xff', '0xff', '0xff', '0xff', '0xff', '0xff', '0xff', '0xff', '0xff', '0xff', '0xff', '0xff', '0xff', '0xff', '0xf3', '0xec', '0xf3', '0xfb', '0xff', '0xff', '0xff', '0xff', '0xff', '0xff', '0xff', '0xff', '0xff', '0xff', '0xf6', '0xf0', '0xe5', '0xe0', '0xde', '0xdc', '0xd8', '0xd6', '0xd7', '0xd0', '0xd5', '0xe0', '0xea', '0xf7', '0xff', '0xff', '0xff', '0xff', '0xff', '0xff', '0xff', '0xff', '0xff', '0xff', '0xff', '0xfb', '0xf8', '0xf5', '0xf2', '0xed', '0xea', '0xe8', '0xe5', '0xe2', '0xe1', '0xe0', '0xdc', '0xd8', '0xd2', '0xcc', '0xc4', '0xc1', '0xc0', '0xc2', '0xc5', '0xc6', '0xc3', '0xbd', '0xb3', '0xa6', '0x9f', '0xa2', '0xa7', '0xac', '0xaf', '0xb0', '0xb4', '0xb7', '0xb9', '0xba', '0xb8', '0xb4', '0xad', '0xa7', '0xa4', '0x9f', '0x99', '0x89', '0x92', '0xa2', '0xb0', '0xbc', '0xc6', '0xca', '0xcb', '0xc6', '0xc4', '0xc3', '0xc4', '0xc5', '0xc3', '0xc3', '0xc2', '0xc5', '0xc8', '0xcb', '0xce', '0xce', '0xcd', '0xcb', '0xc8', '0xc1', '0xbc', '0xb6', '0xae', '0xa7', '0xa3', '0xa5', '0xa0', '0x8c', '0x85', '0x8f', '0x98', '0x9e', '0xa4', '0xac', '0xb6', '0xc0', '0xc7', '0xcd', '0xd1', '0xd0', '0xcd', '0xca', '0xc8', '0xc6', '0xc6', '0xc6', '0xc6', '0xc6', '0xc2', '0xbd', '0xb8', '0xb0', '0xa7', '0xa4', '0xa5', '0xac', '0xb3', '0xb7', '0xbb', '0xbf', '0xc2', '0xc3', '0xc4', '0xc4', '0xc3', '0xc0', '0xbf', '0xbe', '0xbd', '0xbf', '0xc2', '0xc4', '0xc6', '0xc9', '0xca', '0xc8', '0xc8', '0xc6', '0xc3', '0xbf', '0xbf', '0xc0', '0xc0', '0xc0', '0xc0', '0xbe', '0xb9', '0xb6', '0xb3', '0xb1', '0xb3', '0xb5', '0xb8', '0xbb', '0xbe', '0xbe', '0xba', '0xac', '0x9e', '0x9e', '0xa4', '0xa7', '0xa9', '0xa7', '0x9e', '0x96', '0x90', '0x8d', '0x86', '0x81', '0x86', '0x89', '0x91', '0x97', '0x9c', '0xa3', '0xa7', '0xa9', '0xac', '0xb1', '0xb5', '0xb8', '0xbb', '0xbc', '0xb8', '0xa7', '0x9a', '0x9c', '0x9d', '0x9d', '0x9d', '0x9c', '0x9f', '0xa5', '0xac', '0xb3', '0xb9', '0xbf', '0xc4', '0xc5', '0xc5', '0xc6', '0xc4', '0xc1', '0xc0', '0xbd', '0xbb', '0xb8', '0xb6', '0xb4', '0xb3', '0xb0', '0xac', '0xa4', '0xa2', '0xa5', '0xa8', '0xab', '0xab', '0xa8', '0xa4', '0x9f', '0x9e', '0x9d', '0x9c', '0x8f', '0x8a', '0x8d', '0x92', '0x93', '0x95', '0x93', '0x91', '0x92', '0x93', '0x93', '0x90', '0x8c', '0x90', '0x96', '0x9b', '0xa1', '0xa5', '0xa2', '0xa0', '0xa2', '0xa3', '0xa2', '0xa3', '0xa0', '0x9f', '0x9c', '0x99', '0x9b', '0x9d', '0xa0', '0xa5', '0xaa', '0xad', '0xaf', '0xaf', '0xad', '0xa5', '0x9c', '0x98', '0x92', '0x90', '0x8f', '0x8c', '0x8a', '0x90', '0x99', '0xa3', '0xab', '0xb1', '0xb7', '0xb8', '0xb9', '0xb8', '0xb5', '0xb1', '0xb0', '0xb0', '0xb1', '0xb3', '0xb4', '0xb4', '0xb1', '0xb0', '0xb0', '0xad', '0xa9', '0xa5', '0x9e', '0x98', '0x96', '0x94', '0x93', '0x95', '0x95', '0x95', '0x96', '0x94', '0x91', '0x8a', '0x8a', '0x91', '0x9b', '0xa6', '0xaf', '0xb4', '0xb8', '0xba', '0xb8', '0xb7', '0xb8', '0xba', '0xbe', '0xbf', '0xbf', '0xc0', '0xbe', '0xbc', '0xbc', '0xbb', '0xb9', '0xb9', '0xb6', '0xad', '0xa4', '0x97', '0x8e', '0x89', '0x83', '0x81', '0x81', '0x88', '0x8f', '0x98', '0xa1', '0xa6', '0xa8', '0xa9', '0xa9', '0xab', '0xae', '0xb0', '0xb5', '0xb9', '0xba', '0xbd', '0xbf', '0xbf', '0xbe', '0xbd', '0xb9', '0xb4', '0xb0', '0xac', '0xaa', '0xa9', '0xab', '0xae', '0xaf', '0xaf', '0xb0', '0xad', '0xab', '0xab', '0xa8', '0xa7', '0xa4', '0xa0', '0x96', '0x85', '0x86', '0x8e', '0x96', '0x9f', '0xa5', '0xa7', '0xa8', '0xa5', '0x9e', '0x95', '0x8a', '0x86', '0x89', '0x90', '0x99', '0xa0', '0xa6', '0xab', '0xae', '0xad', '0xac', '0xab', '0xa9', '0xa7', '0xa3', '0x9d', '0x97', '0x93', '0x95', '0x9a', '0xa0', '0xa6', '0xab', '0xac', '0xab', '0xa8', '0xa0', '0x97', '0x8f', '0x8b', '0x8f', '0x96', '0x9b', '0x9c', '0x9c', '0x98', '0x92', '0x8f', '0x8f', '0x8e', '0x91', '0x94', '0x96', '0x97', '0x99', '0x94', '0x8d', '0x7b', '0x75', '0x7b', '0x82', '0x89', '0x91', '0x99', '0x9e', '0xa1', '0xa2', '0xa0', '0x9f', '0x9c', '0x9b', '0x9a', '0x99', '0x98', '0x94', '0x8e', '0x8a', '0x80', '0x7d', '0x83', '0x8a', '0x91', '0x99', '0xa0', '0xa6', '0xaa', '0xad', '0xb0', '0xb2', '0xb0', '0xaf', '0xab', '0xa2', '0x98', '0x93', '0x93', '0x94', '0x95', '0x96', '0x96', '0x95', '0x97', '0x9b', '0x9d', '0xa3', '0xa7', '0xa7', '0xa7', '0xa6', '0xa3', '0xa3', '0xa3', '0xa4', '0xa5', '0xa4', '0xa2', '0x9d', '0x97', '0x92', '0x92', '0x93', '0x97', '0x9b', '0x9e', '0xa0', '0xa0', '0x9d', '0x99', '0x91', '0x8c', '0x8c', '0x8d', '0x92', '0x95', '0x96', '0x95', '0x90', '0x88', '0x7f', '0x7d', '0x7b', '0x7f', '0x87', '0x92', '0x9d', '0xa5', '0xaa', '0xaf', '0xb2', '0xb3', '0xb4', '0xb5', '0xb6', '0xb6', '0xb6', '0xb5', '0xb3', '0xae', '0xaa', '0xa5', '0xa0', '0x99', '0x93', '0x93', '0x98', '0x9e', '0xa3', '0xa7', '0xab', '0xad', '0xae', '0xaf', '0xb0', '0xb1', '0xb1', '0xb2', '0xb4', '0xb6', '0xb6', '0xb6', '0xb5', '0xb3', '0xad', '0xa5', '0x9f', '0x9f', '0xa0', '0xa0', '0xa3', '0xa2', '0xa1', '0xa1', '0x9f', '0x9b', '0x94', '0x8b', '0x89', '0x89', '0x8b', '0x8e', '0x90', '0x90', '0x90', '0x8f', '0x90', '0x92', '0x92', '0x93', '0x94', '0x93', '0x8f', '0x89', '0x7c', '0x70', '0x68', '0x66', '0x66', '0x6f', '0x76', '0x7d', '0x84', '0x8a', '0x8d', '0x90', '0x93', '0x98', '0x9e', '0xa1', '0xa4', '0xa5', '0xa5', '0xa4', '0xa4', '0xa3', '0xa0', '0x9d', '0x9a', '0x94', '0x8f', '0x89', '0x80', '0x76', '0x6d', '0x67', '0x5e', '0x5c', '0x61', '0x6a', '0x72', '0x78', '0x79', '0x7d', '0x82', '0x8a', '0x92', '0x96', '0x99', '0x9b', '0x98', '0x91', '0x8b', '0x7b', '0x75', '0x78', '0x7b', '0x81', '0x85', '0x88', '0x8a', '0x8b', '0x89', '0x8b', '0x8b', '0x8c', '0x8e', '0x91', '0x95', '0x96', '0x95', '0x95', '0x95', '0x93', '0x8f', '0x8b', '0x8b', '0x8c', '0x8f', '0x94', '0x99', '0x9a', '0x9e', '0xa3', '0xa5', '0xa7', '0xa8', '0xa9', '0xa6', '0xa3', '0x9d', '0x95', '0x90', '0x8d', '0x8d', '0x8e', '0x8d', '0x8e', '0x8d', '0x90', '0x94', '0x96', '0x9b', '0x9f', '0xa1', '0xa5', '0xa9', '0xa9', '0xaa', '0xac', '0xab', '0xaa', '0xa9', '0xa8', '0xa6', '0xa5', '0xa6', '0xa6', '0xa5', '0xa3', '0x9c', '0x93', '0x8d', '0x8b', '0x89', '0x8b', '0x8a', '0x8c', '0x90', '0x92', '0x92', '0x96', '0x99', '0x9b', '0x9d', '0x9d', '0x9a', '0x95', '0x8e', '0x8a', '0x88', '0x85', '0x82', '0x7e', '0x7f', '0x80', '0x80', '0x84', '0x87', '0x8a', '0x8c', '0x89', '0x86', '0x82', '0x84', '0x8b', '0x92', '0x99', '0xa0', '0xa5', '0xa7', '0xa6', '0xa5', '0xa4', '0x9f', '0x9a', '0x95', '0x8f', '0x8b', '0x8c', '0x8d', '0x90', '0x95', '0x96', '0x98', '0x9b', '0x9d', '0xa0', '0xa5', '0xa5', '0xa6', '0xa6', '0xa3', '0xa0', '0x9c', '0x95', '0x8a', '0x81', '0x80', '0x81', '0x85', '0x8a', '0x89', '0x87', '0x81', '0x78', '0x72', '0x70', '0x73', '0x73', '0x78', '0x7e', '0x85', '0x8a', '0x8f', '0x95', '0x97', '0x99', '0x9b', '0x9b', '0x9a', '0x9b', '0x9c', '0x9b', '0x9b', '0x99', '0x96', '0x93', '0x93', '0x94', '0x96', '0x98', '0x99', '0x98', '0x97', '0x96', '0x97', '0x96', '0x96', '0x95', '0x93', '0x92', '0x90', '0x8c', '0x8a', '0x84', '0x80', '0x7e', '0x7e', '0x82', '0x86', '0x89', '0x8b', '0x8d', '0x8f', '0x8e', '0x8e', '0x8f', '0x8e', '0x8e', '0x8f', '0x90', '0x8f', '0x88', '0x84', '0x7a', '0x7b', '0x79', '0x79', '0x79', '0x73', '0x75', '0x74', '0x79', '0x82', '0x8b', '0x91', '0x96', '0x99', '0x97', '0x95', '0x92', '0x92', '0x92', '0x93', '0x95', '0x95', '0x95', '0x97', '0x98', '0x97', '0x99', '0x9a', '0x98', '0x99', '0x9a', '0x98', '0x99', '0x99', '0x98', '0x98', '0x96', '0x97', '0x97', '0x96', '0x94', '0x94', '0x95', '0x98', '0x99', '0x9c', '0x9e', '0x9d', '0x9b', '0x9b', '0x9c', '0x9c', '0x9d', '0x9e', '0x9d', '0x9d', '0x9b', '0x99', '0x99', '0x99', '0x97', '0x92', '0x83', '0x7c', '0x7e', '0x87', '0x90', '0x95', '0x9b', '0x9d', '0x9c', '0x98', '0x93', '0x8b', '0x86', '0x88', '0x8b', '0x8e', '0x92', '0x96', '0x98', '0x9b', '0x9e', '0x9f', '0x9f', '0x9e', '0x9a', '0x8c', '0x84', '0x88', '0x8e', '0x92', '0x97', '0x9a', '0x99', '0x9a', '0x99', '0x95', '0x90', '0x8b', '0x87', '0x87', '0x8c', '0x90', '0x94', '0x97', '0x96', '0x91', '0x8b', '0x84', '0x7d', '0x7d', '0x7d', '0x83', '0x87', '0x89', '0x8b', '0x8d', '0x8f', '0x8f', '0x8f', '0x8f', '0x8e', '0x8d', '0x8d', '0x8a', '0x89', '0x88', '0x84', '0x7e', '0x75', '0x6b', '0x5f', '0x60', '0x69', '0x72', '0x79', '0x82', '0x89', '0x8e', '0x93', '0x96', '0x95', '0x93', '0x8e', '0x87', '0x83', '0x7e', '0x80', '0x80', '0x7d', '0x76', '0x68', '0x64', '0x62', '0x68', '0x6f', '0x75', '0x7d', '0x83', '0x85', '0x86', '0x84', '0x80', '0x75', '0x69', '0x69', '0x6e', '0x75', '0x7b', '0x81', '0x88', '0x8c', '0x8f', '0x90', '0x8e', '0x87', '0x82', '0x7b', '0x78', '0x77', '0x76', '0x78', '0x79', '0x7a', '0x7b', '0x7c', '0x7f', '0x82', '0x83', '0x85', '0x87', '0x88', '0x8a', '0x8c', '0x8c', '0x8b', '0x88', '0x7f', '0x73', '0x74', '0x7a', '0x80', '0x84', '0x87', '0x86', '0x7f', '0x73', '0x6a', '0x65', '0x68', '0x67', '0x64', '0x61', '0x5b', '0x5d', '0x5c', '0x5e', '0x67', '0x73', '0x7e', '0x86', '0x8e', '0x94', '0x98', '0x99', '0x99', '0x98', '0x94', '0x92', '0x90', '0x8f', '0x8e', '0x90', '0x91', '0x91', '0x91', '0x91', '0x91', '0x90', '0x8c', '0x89', '0x82', '0x76', '0x70', '0x72', '0x73', '0x70', '0x6b', '0x67', '0x6c', '0x71', '0x78', '0x7f', '0x84', '0x87', '0x8c', '0x8f', '0x90', '0x8f', '0x8d', '0x89', '0x87', '0x83', '0x7d', '0x76', '0x70', '0x75', '0x7c', '0x80', '0x85', '0x87', '0x83', '0x7e', '0x7c', '0x7e', '0x7f', '0x80', '0x81', '0x82', '0x83', '0x83', '0x86', '0x88', '0x88', '0x87', '0x85', '0x83', '0x81', '0x7f', '0x7f', '0x7e', '0x7f', '0x7e', '0x7e', '0x7f', '0x7f', '0x7c', '0x78', '0x70', '0x6f', '0x73', '0x7a', '0x81', '0x86', '0x8b']
Checksum: 60620 check: 60620 pass: True
timestamp: '\x000\x000\x00:\x000\x004\x00:\x004\x006\x00.\x001\x002\x009'

One more thing, when you run this code, my angle value is not updating and data[] is empty.

Hi @Sakthivelj,

Ping Viewer’s logging format is not part of the ping protocol, so it’s not included in the ping-python library. There’s an encoding example in the Ping Viewer repository (and a decoding one, if that’s of interest) :slight_smile:

I’m not certain what’s going on there, but it may help to initialize the connection.