aws / amazon-freertos-ble-android-sdk

Android SDK for FreeRTOS Bluetooth Devices.
Apache License 2.0
49 stars 41 forks source link

Issue with version 0.9.3 for Samsung S10e. #15

Closed jays95jp closed 2 years ago

jays95jp commented 4 years ago

I am trying to connect esp32 using my Samsung S10e device with freetos ble android sdk version 0.9.3

Esp32 firmware details is: AFR V1.4.7 released on 02/18/2019

I am able successfully connect/pair ble, After that I fire list command successfully get wifi list as well. but when i try to fire save command to esp32 it's not successfully execute command and network is not save in device.

This one also not work in AWS demo for 0.9.3 sdk.

Device info: Samsung s10e Os: Android 10 Android security patch: March 1, 2020

bxpan commented 4 years ago

@jays95jp What was the error message you saw on the sdk? Could you attach the adb log from your Samsung device?

0.9.3 is our pre-release version, and a few things have changed since then. Could you try using our latest sdk release version 1.1.0?

jays95jp commented 4 years ago

@bxpan Here i am attaching entire log file, Please refer for reference

logcat1586200964474.txt

And we understand there is a new version, but we are trying to determine a solution to support existing devices with this firmware. So can you please look into this and help us to figure out this issue.

jays95jp commented 4 years ago

@bxpan Here is log from esp32

I (83483) [Network]: callback from Network Manager: prvNetworkStateChangeCallback I (83483) [Network]: BLE connected 20 8317 [Btc_task] [INFO ][DEMO][8317] Connected to the BLE device 21 8317 [Btc_task] [INFO ][DEMO][8317] BLE Connected to remote device, connId = 0 E (84903) BT_GATT: GATT_INSUF_ENCRYPTION W (85403) BT_SMP: FOR LE SC LTK IS USED INSTEAD OF STK 22 8526 [main] HEAP Space left: 90536 23 8748 [Btc_task] WARN: Max Networks (20) exceeds configured Max networks (10). Caping max networks to 10 24 9026 [main] HEAP Space left: 84536 25 9526 [main] HEAP Space left: 90652 26 10026 [main] HEAP Space left: 90652 27 10526 [main] HEAP Space left: 90652 28 11026 [main] HEAP Space left: 90652 I (114433) [Network]: callback from Network Manager: prvNetworkStateChangeCallback I (114433) [Network]: BLE disconnected 29 11412 [Btc_task] [INFO ][DEMO][11411] Disconnected from BLE device. 30 11412 [Btc_task] [INFO ][DEMO][11412] BLE disconnected with remote device, connId = 0 31 11412 [Btc_task] Disconnect received for MQTT service instance 0

jigs611989 commented 4 years ago

@bxpan I am facing the same issue. We have implemented this SDK with the React Native app. We face the same issue as mentioned in Android s10. It did work fine in iOS and other android devices. We also try new firmware and its also not working.

It will be a great help as our app is in production ready mode.

bxpan commented 4 years ago

@jays95jp

Everything on the mobile side looks fine until it sent the save network command. After that it did not receive any response from the deivce, and BLE connection was disconnected. @ravibhagavandas could you check further from esp device side why no save network response was sent back?

More details:

From you adb log, after the save network command was sent from sdk to esp32, the sdk did not receive any response back from esp32, as indicated by the timeout, and subsequently, the ble connection changed to BLE_DISCONNECTED , since it was disconnected from the GATT server from esp32.

04-07 03:23:47.469  8327  8359 W AmazonFreeRTOSManager: Ble command has timeout since it has not received response from device after 3000ms. 
04-07 03:23:49.500  8327  8344 D AmazonFreeRTOSManager: onCharacteristicWrite for: SAVE_NETWORK; status: 133; value: a5616246b4750e9853286167. 
04-07 03:23:49.514  8327  8344 I AmazonFreeRTOSManager: Disconnected from GATT server. 
04-07 03:23:49.514  8327  8344 I DeviceScanFragment: BLE connection status changed to: BLE_DISCONNECTED

From esp32 log, it also showed that BLE connection was changed to disconnected.

I (114433) [Network]: BLE disconnected
29 11412 [Btc_task] [INFO ][DEMO][11411] Disconnected from BLE device.
bxpan commented 4 years ago

@bxpan I am facing the same issue. We have implemented this SDK with the React Native app. We face the same issue as mentioned in Android s10. It did work fine in iOS and other android devices. We also try new firmware and its also not working.

It will be a great help as our app is in production ready mode.

@jigs611989 Could you be more specific on what same issue you're seeing on s10? Which version of new firmware you have tried, and which version of sdk release did you use? Also, if you could include logs, it will be helpful to debug the issue.

jigs611989 commented 4 years ago

@bxpan

Summary

Android Device s10e running on Android 10 Android SDK 1.1.0 Demo app esp32 based device with AFR version 202002.00 Feb 19

List network response -> Status: 0 ssid: Mahogany bssid: 48:e2:44:e9:dc:0c security: 3 hidden: false rssi: -83 connected: false index: -1 04-08 03:28:41.801 26893 26893 D InputTransport: Input channel destroyed: 'ClientS', fd=84 04-08 03:28:42.173 26893 26921 D OpenGLRenderer: SurfaceChanged : 0x7abe6cfb80 -> 0x0 04-08 03:28:42.173 26893 26921 I mali_egl: eglDestroySurface() in 04-08 03:28:42.174 26893 26921 I mali_winsys: delete_surface() [1080x2280] return 04-08 03:28:42.174 26893 26921 I mali_egl: eglDestroySurface() out 04-08 03:28:42.175 26893 26921 W libEGL : EGLNativeWindowType 0x7a3c8c78d0 disconnect failed 04-08 03:28:42.181 26893 26893 D ViewRootImpl@2190f9c[WifiProvisionActivity]: Relayout returned: old=[0,0][1080,2280] new=[0,0][1080,2280] req=(1080,2280)8 dur=6 res=0x5 s={false 0} ch=true 04-08 03:28:42.209 26893 26893 D ViewRootImpl@2190f9c[WifiProvisionActivity]: stopped(true) old=false 04-08 03:28:42.228 26893 26893 D ViewRootImpl@2190f9c[WifiProvisionActivity]: Relayout returned: old=[0,0][1080,2280] new=[0,0][1080,2280] req=(1080,2280)8 dur=6 res=0x5 s={false 0} ch=false

saracmelo commented 4 years ago

@bxpan @ravibhagavandas

We are collaborating with @jays95jp.

We have determined 2 root causes of the issues and are hoping we can find a workaround as we have devices live in the field and customers we need to support.

Issues:

  1. Mobile device-specific issue: Any attempt to write data to any characteristic with a MTU setting other than 23 will cause the connection to fail.
  2. ESP32 issue: The ESP32 processes any data that is sent to the "save network" characteristic immediately upon receiving 1st chunk of data (despite the fact that more data is coming). An example is the smallest packet we could make for a wi-fi name "1 character" and an open-network is 26 bytes. This results in multiple transmissions needing to occur(with a MTU setting of 23) to send all the data, but the ESP32 starts the Add Network Request after the 1st chunk of data...It doesn't wait to receive the entire payload before processing...therefore the data is bad and the ESP32 doesn't join the network.

Other Findings:

ravibhagavandas commented 4 years ago

@jays95jp

Could you specify the exact commit ID of the Amazon FreeRTOS version you are using? I couldn't find BLE code from the head of release v1.4.7 commit tag you are referring to: https://github.com/aws/amazon-freertos/tree/4d52fdb0e85c14d88c895ae6c144668ced8409af

saracmelo commented 4 years ago

@ravibhagavandas

BLE Code:

bluetooth_low_energy.zip

jays95jp commented 4 years ago

@jays95jp

Could you specify the exact commit ID of the Amazon FreeRTOS version you are using? I couldn't find BLE code from the head of release v1.4.7 commit tag you are referring to: https://github.com/aws/amazon-freertos/tree/4d52fdb0e85c14d88c895ae6c144668ced8409af

@ravibhagavandas
You can refer zip code which share by @saracmelo me and @saracmelo is in one team :)

ravibhagavandas commented 4 years ago

@jays95jp @saracmelo The code posted above does not contain large object transfer support for WiFi provisioning GATT service. This is required to transfer any payload which is larger than the MTU size set for the connection.

WiFi provisioning with Large Object transfer support is available along with BLE library released in FreeRTOS version 201906.00 Major on 06/17/2019

saracmelo commented 4 years ago

@ravibhagavandas

We are not trying to send a payload bigger than the MTU size. The WIFI provisioning fits well within the 512 MTU limit of the ESP32.

This issue is we can't send any payload above 20 characters without a disconnect happening regardless of any MTU setting above 23.

To our knowledge, this is only an issue with S10e. Other Android and iPhone devices do not have this issue.

Why we cant select a higher MTU is the issue.

saracmelo commented 4 years ago

New learning today: Any MTU setting between 24 & 512 results in only allowing for a payload of 20 characters. You can set the MTU to 24 and send 20 characters all day. You can set the MTU to 512 and send 20 characters all day…but if you try 21 characters in either example the phone will “NOT” send the payload, but it think it does send it…then the timeout happens and the connection is closed.

ravibhagavandas commented 4 years ago

Thanks for your findings.

I am able to reproduce the issue with ESP32 bluedroid stack and Samsung Galaxy S10 device. I am not able to reproduce the same issue with ESP32 Nimble stack which is the default ESP32 BLE stack in recent FreeRTOS releases. Also I cant reproduce the issue with other Android device or IOS device.

I found related threads in Samsung and ESP forums: https://forum.developer.samsung.com/t/samsung-android-10-ble-connectivity-regression/509

https://github.com/espressif/esp-idf/issues/4689

Could you wait for the fix from Samsung or use latest ESP IDF 3.3 version as suggested in forums?

Alternatively you can try switching to latest FreeRTOS version which uses Nimble stack by default.

saracmelo commented 4 years ago

@ravibhagavandas We have already changed the BLE stack over for new devices., but we are still hoping to be able to support existing clients where we can not change the BLE stack.

Do you think this is a ble stack or Samsung issue? I think there's an assumption that this is a Samsung issue because it doesn't happen on other devices, but I'd like to understand where the issue is so we can help advocate for a fix.

The Samsung link has a response from support saying "According to the Bluetooth specification, the link loss occurs because the packet is not received from the data channel for a specific time between the BT chipsets of both terminals. Therefore, it should be checked from your side why BT chipset did not send ACK packet to the data channel."

So, yes it's not responding, but my hunch(and the reason I think its a Samsung issue) is because on the ESP32 I don't even see a packet received.

The fact that the recent FreeRTOS changed the BLE stack though may mean they know something I don't.

Any additional info would be great! Thanks!

ravibhagavandas commented 4 years ago

@saracmelo

We are working with Espressif partner team on merging the fixes into esp idf in FreeRTOS master branch. We will update you once its merged.

Meanwhile if you are using ESP IDF release/v3.3 you can get the fixes from commit ID a4144318 along with commit ID ab175f88.

pentair-mywater-residentail commented 4 years ago

@ravibhagavandas : Espressif suggested a rebase of the v3.1 ESP-IDF code base. This cannot be done as we are using AFR. We tried cherry picking the fix from the Espressif branch but there is a library (libbtdm_app.a) which is giving build errors. The build errors are as below. Could you suggest solution to resolve this.

/code/lib/third_party/mcu_vendor/espressif/esp-idf/components/bt/lib/libbtdm_app.a(ld_fm.o): In function `r_ld_fm_sket_isr':
ld_fm.c:(.iram1.text+0x134): undefined reference to `ld_inq_frm_cbk'
/code/lib/third_party/mcu_vendor/espressif/esp-idf/components/bt/lib/libbtdm_app.a(ld_inq.o):(.iram1.text+0x40): undefined reference to `ld_inq_end'
/code/lib/third_party/mcu_vendor/espressif/esp-idf/components/bt/lib/libbtdm_app.a(ld_inq.o):(.iram1.text+0x44): undefined reference to `ld_inq_sched'
/code/lib/third_party/mcu_vendor/espressif/esp-idf/components/bt/lib/libbtdm_app.a(ld_inq.o): In function `ld_inq_frm_isr_wrapper':
ld_inq.c:(.iram1.text+0x3b3): undefined reference to `ld_inq_end'
ld_inq.c:(.iram1.text+0x3d4): undefined reference to `ld_inq_sched'
/code/lib/third_party/mcu_vendor/espressif/esp-idf/components/bt/lib/libbtdm_app.a(dbg_task.o): In function `hci_vendor_ble_init_adv_flow_control_cmd_handler':
dbg_task.c:(.text+0x104): undefined reference to `dbg_default_state'
/code/lib/third_party/mcu_vendor/espressif/esp-idf/components/bt/lib/libbtdm_app.a(lc_sco.o):(.text+0x0): undefined reference to `lc_sco_env'
collect2: error: ld returned 1 exit status
/code/app/make/../../lib/third_party/mcu_vendor/espressif/esp-idf/make/project.mk:406: recipe for target '/code/app/make/build/afr_app.elf' failed
make: *** [/code/app/make/build/afr_app.elf] Error 1
abhidixi11 commented 2 years ago

I'm closing this issue, please feel free to open a new one.