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

How to show Txpower in advertisement data #409

Closed
21317389 opened this issue May 5, 2024 · 12 comments · Fixed by #410
Closed

How to show Txpower in advertisement data #409

21317389 opened this issue May 5, 2024 · 12 comments · Fixed by #410

Comments

@21317389
Copy link

21317389 commented May 5, 2024

HELLO,
I can't set the TXPOWER in advertisement.
How to solve it, and I think maybe #333 can solve me problem.
But I can't understand how to fix.

Sincerely.

@ukBaz
Copy link
Owner

ukBaz commented May 5, 2024

As discussed in #333, Bluezero does not support the inclusion of tx_power in advertisement since the change to the BlueZ API.

There was no PR created at the end of that issue so this library does not have the update.
What #333 does do is document how how to locally patch your code.

What are you trying to do?
What is your code?
What error messages are you getting?

@21317389
Copy link
Author

21317389 commented May 6, 2024

Thank you for your prompt reply.
I run my code in jetson nano, and jetson nano will publish signal to provide the phone connect.
I want to generate the TX power Level in my advertisement data , just like this red circle at the photo.
IMG_4455

And my code is modified from the ble_uart.py.
I just create the local name and service UUID.

And, I didn't get the error messages.

@ukBaz
Copy link
Owner

ukBaz commented May 6, 2024

And my code is modified from the ble_uart.py.

And how have you modified it to include the TX power?

@21317389
Copy link
Author

21317389 commented May 6, 2024

Oh, not yet.
It is just the example.
This is my goal, but I have no idea how to finish this part.

@ukBaz
Copy link
Owner

ukBaz commented May 7, 2024

Can you check that tx-power is supported on your setup. If you do the following:

busctl get-property org.bluez /org/bluez/hci0 org.bluez.LEAdvertisingManager1 SupportedIncludes

Do you get:

as 3 "tx-power" "appearance" "local-name"

@21317389
Copy link
Author

21317389 commented May 8, 2024

YES!
I actually get those item!
But those item just means I can advert them, right?

And, I also reference this #323. I thought this proble is similar with mine.

However, I add ble_uart.advert.IncludeTxPower = 'True' in my code, the operation did not result in any action.

@ukBaz
Copy link
Owner

ukBaz commented May 9, 2024

Do you get:
as 3 "tx-power" "appearance" "local-name"

YES!
I actually get those item!
But those item just means I can advert them, right?

You are correct, it only means that those values can be added to the advert.

What #333 is discussing is that the BlueZ API was changed and that Bluezero hasn't been updated to reflect that. So the change you made to your code won't work unless the library is updated.
I started to look at doing the update when you opened this issue but ran out of time and it might be a while before I can get back to this. It's not helped by the fact that my normal development machine doesn't support tx-power so I need to move to a different machine.

@ukBaz
Copy link
Owner

ukBaz commented May 10, 2024

To include some information here on how the BlueZ API has changed. In the 5.45 release TX power was included with the boolean property IncludeTxPower on interface org.bluez.LEAdvertisement1

This is documented at: https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/advertising-api.txt?h=5.45#n64

		bool IncludeTxPower

			Includes the Tx Power in the advertising packet.
			If missing, the Tx Power is not included.

In more recent versions of the API how TX power is included has changed. They removed the previous IncludeTxPower property. The API now requires the string tx-power in the array property of Includes

This is documented at: https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/org.bluez.LEAdvertisement.rst?h=5.73#n123

array{string} Includes

	List of features to be included in the advertising packet.

	Possible values:

	See **org.bluez.LEAdvertisingManager(5)** **SupportedIncludes**
	property.

For reference, SupportedIncludes is documented at:
https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/org.bluez.LEAdvertisingManager.rst?h=5.73#n80

array{string} SupportedIncludes [readonly]

	List of supported system includes.

	Possible values:

	:"tx-power":
	:"appearance":
	:"local-name":
	:"rsi":

This is the change that needs to be reflected in Bluezero.

@ukBaz
Copy link
Owner

ukBaz commented May 12, 2024

I've created a feature branch where I've made the code changes:
https://github.com/ukBaz/python-bluezero/tree/tx_pwr_ad

The code I used to test this was:

from bluezero import advertisement
from bluezero import constants
advert_id = 1
ad_type = 'broadcast'
ad_mngr_options = {}
beacon = advertisement.Advertisement(advert_id, ad_type)
beacon.include_tx_power = True
print(beacon.GetAll(constants.LE_ADVERTISEMENT_IFACE))
beacon.local_name = "MyBeacon"
beacon.service_UUIDs = ['FEAA']
beacon.service_data = {'FEAA': [0x10, 0x08, 0x03, 0x75, 0x6B, 0x42, 0x61, 0x7A, 0x2e, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2E, 0x69, 0x6F]}
ad_manager = advertisement.AdvertisingManager()
ad_manager.register_advertisement(beacon, ad_mngr_options)
beacon.start()

In nRF Connect app on the phone I scanned for the beacon.

With the include_tx_power being set to False I got:
image

With the include_tx_power being set to True I got:
image

This looks to be what you are expecting @21317389 ?
Can you test the tx_pwr_ad branch and let me know if it works for you. If it appears to be working I'll merge it in to main and do a release.

@21317389
Copy link
Author

21317389 commented May 12, 2024

II'm really grateful for your help, and I think I'll run some tests after I finish my work . Thank you so much for your assistance.
Sincerely!!!!

@21317389
Copy link
Author

YA!
Thank you very much for your help!
After using the tx_pwr_ad branch, the TX power is successfully presented on the advertisement data!
S__177438725

Finally, I will close this issue. Thank You!!!!

@ukBaz
Copy link
Owner

ukBaz commented May 18, 2024

Added the 0.9.0 release to PyPI that contains this fix
https://pypi.org/project/bluezero/

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

Successfully merging a pull request may close this issue.

2 participants