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

Add ability to save LE Advertising Reports with bluer-tools #118

Closed
potto216 opened this issue Dec 26, 2023 · 6 comments
Closed

Add ability to save LE Advertising Reports with bluer-tools #118

potto216 opened this issue Dec 26, 2023 · 6 comments
Assignees
Labels
enhancement New feature or request

Comments

@potto216
Copy link
Contributor

It would be useful for one of the bluer-tools to have a command line option to save advertising reports for future analysis and comparisons. Currently I modified blumon to save the reports in a JSON array with an example given below:

[{
  "local_name": "",
  "address": "61:2E:6D:11:B5:82",
  "address_type": "random",
  "manufacturer_data": "",
  "service_data": "",
  "last_seen": 0,
  "RSSI": -76
},
{
  "local_name": "",
  "address": "56:04:B8:80:A5:AE",
  "address_type": "random",
  "manufacturer_data": "",
  "service_data": "",
  "last_seen": 0,
  "RSSI": -71
},

Is there interest in accepting a PR for either modifying an existing bluer-tools program or creating a new one to include this functionality? I think having bluer-tools that can run at the command line by users not familiar with Rust will increase the adoption of BlueR and fill a gap in BlueZ command line tool capability, especially since the hci tools are deprecated.

The requirements of the feature would be:

  1. Provide a command line feature to save received advertising reports. The minimum information to be included is the information from either the LE Advertising Report event or the LE Extended Advertising Report event.
  2. Provide a command line feature to either write the file as a JSON array or a CSV file without a column header
  3. Provide a command line feature to have extra information included with each advertising report such as the scanning adapter public address and the time the report was recorded.

@surban what are your thoughts?

@surban
Copy link
Collaborator

surban commented Feb 1, 2024

Yes, sounds good to me!

@surban surban added the enhancement New feature or request label Feb 1, 2024
@potto216
Copy link
Contributor Author

potto216 commented Feb 3, 2024

Great I'll fork the repo and make the changes on master unless the changes should be in a branch

@potto216
Copy link
Contributor Author

@surban here is a prototype to save advertisements to a file. The prototype does not yet have the command line switches. The basic idea is to call the append method to add a new json record of the advertisement when it is received. Recorded advertisments look like:

{
  "adv_name": {
    "RSSI": -47,
    "address": "5D:2D:65:3D:3B:66",
    "address_type": "random",
    "last_seen": 8,
    "local_name": "",
    "manufacturer_data": "0x004C: [0x16 0x08 0x00 0x54(T) 0xDD 0x5A(Z) 0xB5 0x9E 0xC2 0xE2]",
    "service_data": ""
  },
  "time_recorded": "2024-02-09T19:09:21.337408427+00:00"
},
{
  "adv_name": {
    "RSSI": -34,
    "address": "00:15:A3:00:3E:D3",
    "address_type": "public",
    "last_seen": 3,
    "local_name": "UM34C",
    "manufacturer_data": "0x050E: [0xD3 0x3E(>) 0x00 0xA3 0x15 0x00]",
    "service_data": ""
  },
  "time_recorded": "2024-02-09T19:09:21.353514634+00:00"
},

A couple issues to resolve.

  1. Is a JSON array the best choice? The common way to exit bluemon is with CTRL-C the program currently ends without writing the closing array bracket ]. Possible solutions I thought of around this are:
    • Don't use JSON, use a format that doesn't require end parameters such as CSV.
    • Always write the closing bracket and then before writing the next advertisement rewind the file pointer to erase that.
    • Add a handle to catch the CTRL-C event and then write out the ]. Also in this case the logger could write out the entire file or large chunks of the file so it doesn't slow down the I/O by flushing each advertisement to disk.
  2. Is the placement of the logger.append statement in the event loop appropriate? Is there a better design pattern to use.

Once the code changes are done I'll merge this branch into my master for the PR.

@surban
Copy link
Collaborator

surban commented Feb 27, 2024

Looks good to me in general.

However, due to the problems with invalid JSON, I would suggest using JSON lines instead. You will not always be able to catch process termination and thus might end up with invalid JSON data on disk.

Please send a PR. It's easier to review when a diff is available.

@potto216
Copy link
Contributor Author

potto216 commented Mar 9, 2024

Created PR #133 for review

@potto216
Copy link
Contributor Author

Merge complete, the issue can be closed.

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

No branches or pull requests

2 participants