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

Can not apply advertisment data #4288

Open
linycm opened this issue Nov 3, 2018 · 9 comments
Open

Can not apply advertisment data #4288

linycm opened this issue Nov 3, 2018 · 9 comments

Comments

@linycm
Copy link

linycm commented Nov 3, 2018

Hi @glennrub ,

I got a similar issue with #4179 .

I test bluetooth example on my NRF board PCA10040, then got error for cannot apply advertisment data. I put some in REPL as below:

from ubluepy import Service, Characteristic, UUID, Peripheral, constants
uuid_env_sense = UUID("6e400001-b5a3-f393-e0a9-e50e24dcca9e")
serv_env_sense = Service(uuid_env_sense)
periph = Peripheral()
periph.addService(serv_env_sense)
periph.advertise(device_name="micr_temp", services=[serv_env_sense])

And I got feedback:
Traceback (most recent call last):
File "", in
OSError: Can not apply advertisment data. status: 0x09

Rdgs,
Martin

@linycm
Copy link
Author

linycm commented Nov 11, 2018

Maybe my example something wrong, I used old firmware version (should be softdevice3.0) as below, that work for bluetooth connection.

MicroPython v1.8.1-3865-gd91c351-dirty on 2018-05-01; PCA10040 with NRF52832

from machine import RTCounter, Temp
from ubluepy import Service, Characteristic, UUID, Peripheral, constants
uuid_env_sense = UUID("0x181A")
serv_env_sense = Service(uuid_env_sense)
temp_props = Characteristic.PROP_NOTIFY | Characteristic.PROP_READ
temp_attrs = Characteristic.ATTR_CCCD
uuid_temp = UUID("0x2A6E")
char_temp = Characteristic(uuid_temp, props = temp_props, attrs = temp_attrs)
serv_env_sense.addCharacteristic(char_temp)
periph = Peripheral()
periph.addService(serv_env_sense)
periph.advertise(device_name="micr_temp", services=[serv_env_sense])

But when I changed to updated version firmware with softdevice 6.0, bluetooth signal can be advertised but cannot connect.

Rdgs,
Martin

@edwios
Copy link

edwios commented Nov 11, 2018

I have the same problem, using the stock example ubluepy_temp.py, advertising is ok, event_handler EVT_GAP_CONNECTED ok, but then that's all. Connection soon timeout after a while.

@glennrub
Copy link
Contributor

@linycm, are you running this from a build of master branch?

I'm not able to re-produce the error, as the code you posted advertise and connects for me. Do you have any log from the central that could hint on why the connection fails?

Alternatively, you could enable some logging from the ble_drv.c by toggling the BLE_DRIVER_VERBOSE to 1 to see why the connect might fail on the peripheral side.
https://github.com/micropython/micropython/blob/master/ports/nrf/drivers/bluetooth/ble_drv.c#L43

@linycm
Copy link
Author

linycm commented Nov 12, 2018

@glennrub,
I am running from the build of master branch:
MicroPython v1.9.4-674-g27ca9ab-dirty on 2018-11-12; PCA10040 with NRF52832

log from the central: Connection Alert:
Timeout interrogating the peripheral

I set BLE_DRIVER_VERBOSE to 1 in file ble_drv.c and compile again. I put the last code in REPL and got log as below:

Is enabled status: 0
SoftDevice enable status: 0
IRQ enable status: 0
BLE_CONN_CFG_GAP status: 0
BLE_GAP_CFG_ROLE_COUNT status: 0
BLE_CONN_CFG_GATTS status: 0
BLE ram size: 10640
BLE enable status: 0
adding service
Is enabled status: 0
Device name applied
encoded uuid for service 0: 1a 18
ADV: uuid size: 2, type: 1, uuid: 181a, vs_idx: 0
Set Adv data size: 18

after using mobile phone to connect the board by bluetooth, log as below:
GAP CONNECT
GAP CONN PARAM UPDATE
unhandled evt: 0x23
GAP DISCONNECT
Is enabled status: 0
Then the board reboot

@linycm
Copy link
Author

linycm commented Nov 14, 2018

@glennrub,
I recompiled with updated ARM 2018 compiler for MicroPython v1.9.4, then it works when runing ubluepy_temp.py and communicating with Android phone. But it does not work with IOS phone. Could you help to check whether is ok if we revise ubluepy_temp.py for IOS?

Thanks!
Rdgs,
Martin

@glennrub
Copy link
Contributor

@linycm , sorry for taking so long. Thanks a lot for your log!

Based on the log i do see an unhandled event, 0x23. This translates into BLE_GAP_EVT_DATA_LENGTH_UPDATE_REQUEST.

I do not have any way of provoking your error using iOS, so i have made a patch that you could try out:
glennrub@4b57af5

Could you try out the patch and see if this solves the issue?

@dhalbert
Copy link
Contributor

We saw the same error in the CircuitPython BLE code. iPhone 7 and later, and modern iPads apparently have extended-length BLE packet capability in the hardware. iPhone 6s and earlier don't. We just say we don't provide this:
https://github.com/adafruit/circuitpython/blob/master/ports/nrf/common-hal/bleio/Peripheral.c#L269

@linycm
Copy link
Author

linycm commented Feb 27, 2019

@glennrub , I compiled the new version again. Try again but I cannot connect BLE in iphone7 yet.

@silbo
Copy link

silbo commented Sep 4, 2019

@glennrub I tested it also on my nrf52840DK (PCA10056) board, it freezes when I try to connect to the device and the client device doesn't finish connecting to it (tested with Android, Mac and iOS)
it seems to get stuck at discovering services

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

No branches or pull requests

5 participants