adafruit / Adafruit_nRF52_Arduino

Adafruit code for the Nordic nRF52 BLE SoC on Arduino
Other
629 stars 501 forks source link

bleuart.ino example not working w iOS app #285

Closed CollinCunningham closed 5 years ago

CollinCunningham commented 5 years ago

Describe the bug When running the bleuart.ino example sketch, UART appears busy/unavailable to the Bluefruit LE Connect app. Commenting out line 55 fixes the issue.

Set up (please complete the following information)

To Reproduce

  1. Run examples/Peripheral/bleuart/bleuart.ino
  2. Connect via Bluefruit LE Connect
  3. Open UART module
  4. Bottom text field is disabled & data sent from Arduino serial monitor is not displayed

Expected behavior Ability to send receive data over UART

Additional context @hathach can you reproduce this bug? If it it's an issue on the iOS side, we can roll a fix into the next update.

hathach commented 5 years ago

@CollinCunningham hmm, this is strange, I couldn't reproduce this with my iphone 6 on iOS 11.3 with Bluefruit 3.4.0. I am upgrading it to ios 12.3.1 and try again.

Update: just borrow my wife's iphone 12.31. to test with. There is no issue at all hmmm :thinking: :thinking:

hathach commented 5 years ago

@CollinCunningham do you have other iphone to test with, just make sure it is not something specific with your iphone.

CollinCunningham commented 5 years ago

@hathach weird - I'll locate another iphone to test. Thanks for checking.

dhalbert commented 5 years ago

Try iPhone 6 or 6s vs 7 or later. 6 and 6s don't have extended-length packet support in hardware.

dhalbert commented 5 years ago

I noticed this on my iPhone 6S vs a newer iPad, I think.

CollinCunningham commented 5 years ago

I'm on an iphone 7+, fwiw

dhalbert commented 5 years ago

See https://github.com/adafruit/circuitpython/pull/1491 for a fix I had to put into CircuitPython. We weren't handling BLE_GAP_EVT_DATA_LENGTH_UPDATE_REQUEST. Also was failing to handle BLE_GATTS_EVT_SYS_ATTR_MISSING, sent by Android devices.

hathach commented 5 years ago

@CollinCunningham please also enable Debug Level to 2 to see if there is any abnormal activity. Thanks @dhalbert my wife's phone is iphoneX, we also already handle both events you mentioned (used to got issue with LUN UPDATE REQEUST as well) https://github.com/adafruit/Adafruit_nRF52_Arduino/blob/master/libraries/Bluefruit52Lib/src/bluefruit.cpp#L865

CollinCunningham commented 5 years ago

@hathach just getting back to this - tested and working on an iPhone X I tried yesterday. How do I enable debug level 2? I tried adding #define CFG_DEBUG 2 to the sketch, but I'm not seeing any logs/etc.

CollinCunningham commented 5 years ago

@hathach Ah - nevermind. Just found it in the IDE. Here's the output after connecting:

Bluefruit52 BLEUART Example
---------------------------

[CFG   ] SoftDevice's RAM requires: 0x20002FA0
Please use Adafruit's Bluefruit LE app to connect in UART mode
Once connected, enter character(s) that you wish to send

BSP Library : 0.11.0
Bootloader  : s132 6.1.1
Serial No   : 4ABDDEBF7F2E176B

--------- SoftDevice Config ---------
Max UUID128     : 10
ATTR Table Size : 2048
Service Changed : 1
Peripheral Connect Setting
  - Max MTU         : 247
  - Event Length    : 6
  - HVN Queue Size  : 3
  - WrCmd Queue Size: 1

--------- BLE Settings ---------
Name            : Bluefruit52
Max Connections : Peripheral = 1, Central = 0 
Address         : FB:85:8A:88:EA:62 (Static)
TX Power        : 4 dBm
Conn Intervals  : min = 20.00 ms, max = 30.00 ms
Conn Timeout    : 2000.00 ms
Peripheral Paired Devices: 
  81a1 : CollinMBP (2) (117 bytes)
  9923 : Collin's iPhone 7+ (128 bytes)
  9b4f : Nexus 7 (111 bytes)
  47dc : Nexus 7 (111 bytes)

[BLE   ] BLE_GAP_EVT_CONNECTED : Conn Handle = 0
[BLE   ] BLE_GAP_EVT_SEC_INFO_REQUEST : Conn Handle = 0
[BOND  ] Loaded keys from file /adafruit/bond_prph/9923
[BLE   ] BLE_GAP_EVT_CONN_SEC_UPDATE : Conn Handle = 0
[BOND  ] CCCD setting not found
[BLE   ] BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP : Conn Handle = 0
Connected to Collin's iPhone 7+
[BLE   ] BLE_GAP_EVT_DATA_LENGTH_UPDATE_REQUEST : Conn Handle = 0
[GAP   ] Data Length Req is (tx, rx) octets = (251, 251), (tx, rx) time = (2120, 2120) us
[BLE   ] BLE_GAP_EVT_DATA_LENGTH_UPDATE : Conn Handle = 0
[GAP   ] Data Length is (tx, rx) octets = (251, 251), (tx, rx) time = (2120, 2120) us
[BLE   ] BLE_GATTS_EVT_EXCHANGE_MTU_REQUEST : Conn Handle = 0
[GAP   ] ATT MTU is changed to 247
[BLE   ] BLE_GATTS_EVT_WRITE : Conn Handle = 0
hathach commented 5 years ago

@CollinCunningham your iPhone 7+ is bonded with the device, probably running blehid/midi/ancs previously. This can prevent iPhone to re-discover service when switching to normal sketch. Can you go into iOS bluetooth setting and Forget nrf52 device then refresh/off-then-on bluetooth and try again.

CollinCunningham commented 5 years ago

@hathach thanks much - that was it 🎉 Strange that I've never encountered this before. I'll update the learn guide accordingly.

hathach commented 5 years ago

@CollinCunningham I am glad that help. The iOS behavior changes as well, it is very tricky :)

CollinCunningham commented 5 years ago

@hathach ya - there's been more than a few updates since I wrote iOS BLE code ;)