ogabrielinacio / esp_provisioning_ble

A Flutter plugin for provisioning ESP32 modules with Ble
MIT License
10 stars 3 forks source link

not getting response #8

Open Manaf-A opened 7 months ago

Manaf-A commented 7 months ago

when clicking start provisioing button the spinkit ripple is only showing ..not other response .again quting appp and again clicking the button loads the available ble devices.some times its working some times its not working ..i tested it in android .i cant find the exact problem .is any one help me

Manaf-A commented 7 months ago

if devices not found some time its changeing ui no device found scan again .but some time loading spinkit ripple ...with out showing any other thing .how can i solve that

ogabrielinacio commented 7 months ago

I'll take a look into this and let you know. It's true, things are a bit hectic with the end of the year coming up, so working on the package might be tricky in the near future. But rest assured, I'll prioritize it as soon as I can and get that fix out to you. This seems to be more of a problem with the "example" project than the package itself. I'll take a look and get back to you.

Manaf-A commented 7 months ago

thankyou so much for the response.i tried to fix it but i failed.so kindly request you to do some magic for that .other wise everything perfect.i know to took a lot of effort for this example ...kindly requesting you to do some tricks ....

On Sun, 17 Dec, 2023, 4:48 pm Gabriel Inácio, @.***> wrote:

I'll take a look into this and let you know. It's true, things are a bit hectic with the end of the year coming up, so working on the package might be tricky in the near future. But rest assured, I'll prioritize it as soon as I can and get that fix out to you. This seems to be more of a problem with the "example" project than the package itself. I'll take a look and get back to you.

— Reply to this email directly, view it on GitHub https://github.com/ogabrielinacio/esp_provisioning_ble/issues/8#issuecomment-1859142344, or unsubscribe https://github.com/notifications/unsubscribe-auth/A6WVQYZT4BFBXXMAKBJN3WDYJ3IKFAVCNFSM6AAAAABAU3BHOKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNJZGE2DEMZUGQ . You are receiving this because you authored the thread.Message ID: @.***>

ogabrielinacio commented 6 months ago

Hey @Manaf-A

I believe I've resolved the issue! commit : https://github.com/ogabrielinacio/esp_provisioning_ble/commit/097b36a3e2427f5b3cf5c24bdbb2c76fa26763bc

I realized that stopping the timer within the stream wasn't the best approach. My apologies for that!

Please let me know if you have any further feedback or if you encounter any other issues.

nirmalvora commented 6 months ago

Unhandled Exception: BleError (Error code: 401, ATT error code: 4, iOS error code: null, Android error code: null, reason: GATT exception from MAC='XX:XX:XX:XX:XX:XX', status 4 (GATT_INVALID_PDU), type BleGattOperation{description='CHARACTERISTIC_WRITE'}. (Look up status 0x04 here https://cs.android.com/android/platform/superproject/+/master:packages/modules/Bluetooth/system/stack/include/gatt_api.h), internal message: null, device ID: D4:F9:8D:3D:BD:76, service UUID: 021a9004-0382-4aea-bff4-6b3f1c5adfb4, characteristic UUID: 021aff54-0382-4aea-bff4-6b3f1c5adfb4, descriptor UUID: null)

ogabrielinacio commented 5 months ago

@Nirmalvora, Can you give more information, please? Which device are you testing? Are you using the Espressif firmware into your ESP32? Is this error occurs when connecting with the device?

ivanhercaz commented 4 months ago

@nirmalvora, it is necessary more information as the requested by @ogabrielinacio to help you with your error. However, I found something that maybe useful although it isn't directly related to this package nor ESP, it is related with Bluetooth and Android, check https://github.com/JuulLabs/kable/issues/92. There the reporting user tells "I have found that I was connecting multiple times so that is the cause of the exception".

Could you provide the parts of the code in which you are connecting to the device and the context of this code (I mean the related code that surround it)? Because it seems this exception is related with a connection issue and it is possible be related with the MTU (Maximum Transmission Unit).

P.S. And that comment should be another issue, because it doesn't seems to be related with this one.

ivanhercaz commented 4 months ago

@Manaf-A, check @ogabrielinacio's comment (https://github.com/ogabrielinacio/esp_provisioning_ble/issues/8#issuecomment-1868366801), it is possible your issue may be solved thanks to his fix! If it is solved, the issue should be closed ❤️ .

Thanks for your continuous work, Gabriel!

vic-pic commented 4 months ago

Hi @ivanhercaz, hi @ogabrielinacio, I'm testing the example app and I have the same issue as reported in comment https://github.com/ogabrielinacio/esp_provisioning_ble/issues/8#issuecomment-1901748933 also applying the changes reported in the commit https://github.com/ogabrielinacio/esp_provisioning_ble/commit/097b36a3e2427f5b3cf5c24bdbb2c76fa26763bc

Could you help me find the issue, please?

vic-pic commented 4 months ago

Hi @ivanhercaz, hi @ogabrielinacio, I have some updates: I found that the cause was this code

var customAnswerBytes = await prov.sendReceiveCustomData(
  Uint8List.fromList(
    utf8.encode(event.customSendMessage),
  ),
);
var customAnswer = utf8.decode(customAnswerBytes);
log.i("Custom data answer: $customAnswer");

placed in file example/lib/src/features/ble_wifi_screen/bloc/ble_wifi_bloc.dart on line 75 immediately before the prov.sendWifiConfig function

Follow the log after the operation has been completed

I/flutter (15198): ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
I/flutter (15198): │ #0   new BleWifiBloc.<anonymous closure>.<anonymous closure> (package:example/src/features/ble_wifi_screen/bloc/ble_wifi_bloc.dart:100:19)
I/flutter (15198): │ #1   <asynchronous suspension>
I/flutter (15198): ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
I/flutter (15198): │ 🐛 Device IP: 
I/flutter (15198): └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
E/flutter (15198): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: BleError (Error code: 401, ATT error code: 4, iOS error code: null, Android error code: null, reason: GATT exception from MAC='XX:XX:XX:XX:XX:XX', status 4 (GATT_INVALID_PDU), type BleGattOperation{description='CHARACTERISTIC_WRITE'}. (Look up status 0x04 here https://cs.android.com/android/platform/superproject/+/master:packages/modules/Bluetooth/system/stack/include/gatt_api.h), internal message: null, device ID: 48:31:B7:34:2B:3E, service UUID: 021a9004-0382-4aea-bff4-6b3f1c5adfb4, characteristic UUID: 021aff52-0382-4aea-bff4-6b3f1c5adfb4, descriptor UUID: null)
E/flutter (15198): 
D/com.polidea.flutter_ble_lib.FlutterBleLibPlugin(15198): on native side observed method: writeCharacteristicForDevice
D/com.polidea.flutter_ble_lib.FlutterBleLibPlugin(15198): on native side observed method: readCharacteristicForDevice
D/com.polidea.flutter_ble_lib.FlutterBleLibPlugin(15198): on native side observed method: writeCharacteristicForDevice
D/com.polidea.flutter_ble_lib.FlutterBleLibPlugin(15198): on native side observed method: readCharacteristicForDevice
D/com.polidea.flutter_ble_lib.FlutterBleLibPlugin(15198): on native side observed method: writeCharacteristicForDevice
D/com.polidea.flutter_ble_lib.FlutterBleLibPlugin(15198): on native side observed method: readCharacteristicForDevice
D/com.polidea.flutter_ble_lib.FlutterBleLibPlugin(15198): on native side observed method: writeCharacteristicForDevice
D/com.polidea.flutter_ble_lib.FlutterBleLibPlugin(15198): on native side observed method: readCharacteristicForDevice
I/flutter (15198): ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
I/flutter (15198): │ #0   new BleWifiBloc.<anonymous closure>.<anonymous closure> (package:example/src/features/ble_wifi_screen/bloc/ble_wifi_bloc.dart:100:19)
I/flutter (15198): │ #1   <asynchronous suspension>
I/flutter (15198): ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
I/flutter (15198): │ 🐛 Device IP: 192.168.2.3
I/flutter (15198): └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
D/com.polidea.flutter_ble_lib.FlutterBleLibPlugin(15198): on native side observed method: writeCharacteristicForDevice
D/com.polidea.flutter_ble_lib.FlutterBleLibPlugin(15198): on native side observed method: readCharacteristicForDevice
I/flutter (15198): ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
I/flutter (15198): │ #0   new BleWifiBloc.<anonymous closure>.<anonymous closure> (package:example/src/features/ble_wifi_screen/bloc/ble_wifi_bloc.dart:100:19)
I/flutter (15198): │ #1   <asynchronous suspension>
I/flutter (15198): ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
I/flutter (15198): │ 🐛 Device IP: 192.168.2.3
I/flutter (15198): └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
D/com.polidea.flutter_ble_lib.FlutterBleLibPlugin(15198): on native side observed method: writeCharacteristicForDevice
D/com.polidea.flutter_ble_lib.FlutterBleLibPlugin(15198): on native side observed method: readCharacteristicForDevice
I/flutter (15198): ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
I/flutter (15198): │ #0   new BleWifiBloc.<anonymous closure>.<anonymous closure> (package:example/src/features/ble_wifi_screen/bloc/ble_wifi_bloc.dart:100:19)
I/flutter (15198): │ #1   <asynchronous suspension>
I/flutter (15198): ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
I/flutter (15198): │ 🐛 Device IP: 192.168.2.3
I/flutter (15198): └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
D/com.polidea.flutter_ble_lib.FlutterBleLibPlugin(15198): on native side observed method: writeCharacteristicForDevice
D/BluetoothGatt(15198): onClientConnectionState() - status=19 clientIf=10 device=48:31:B7:34:2B:3E
E/flutter (15198): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: BleError (Error code: 201, ATT error code: 19, iOS error code: null, Android error code: null, reason: Disconnected from MAC='XX:XX:XX:XX:XX:XX' with status 19 (GATT_CONN_TERMINATE_PEER_USER), internal message: null, device ID: 48:31:B7:34:2B:3E, service UUID: null, characteristic UUID: null, descriptor UUID: null)
E/flutter (15198): 
D/BluetoothGatt(15198): close()
D/BluetoothGatt(15198): unregisterApp() - mClientIf=10
D/com.polidea.flutter_ble_lib.FlutterBleLibPlugin(15198): on native side observed method: writeCharacteristicForDevice
E/flutter (15198): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: BleError (Error code: 205, ATT error code: null, iOS error code: null, Android error code: null, reason: Reason not provided, internal message: null, device ID: 48:31:B7:34:2B:3E, service UUID: null, characteristic UUID: null, descriptor UUID: null)

Is it correct that there are other error messages from BLE?

Thanks, Vincenzo

ogabrielinacio commented 4 months ago

Hello @vic-pic This errors occurs because a bad implementation on the error handler of the package, me and @ivanhercaz we are working on that, to find the best solution for this error

vic-pic commented 4 months ago

Thanks, @ogabrielinacio @ivanhercaz for your work. This means that the error is a different one and not GATT_INVALID_PDU?

Thanks, Vincenzo

vic-pic commented 3 months ago

Hi @ogabrielinacio, I have found another issue that maybe related: after I send a custom message, I receive only a part of the response

I/flutter ( 4985): ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
I/flutter ( 4985): │ #0   new BleWifiBloc.<anonymous closure> (package:example/src/features/ble_wifi_screen/bloc/ble_wifi_bloc.dart:194:13)
I/flutter ( 4985): │ #1   <asynchronous suspension>
I/flutter ( 4985): ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
I/flutter ( 4985): │ 💡 Custom data scanAp answer 2: {
I/flutter ( 4985): │ 💡         "type": "wizardConfig",
I/flutter ( 4985): │ 💡         "command":      "scanAp",
I/flutter ( 4985): │ 💡         "status":       0,
I/flutter ( 4985): │ 💡         "description":  "scan ap success",
I/flutter ( 4985): │ 💡         "sequence":     1002,
I/flutter ( 4985): │ 💡         "response":     {
I/flutter ( 4985): │ 💡                 "total":        33,
I/flutter ( 4985): │ 💡                 "ApList":       [{
I/flutter ( 4985): │ 💡                                 "ssid": "Beep Beep",
I/flutter ( 4985): │ 💡                                 "rssi": -47
I/flutter ( 4985): │ 💡                         }, {
I/flutter ( 4985): │ 💡                                 "ssid": "iliadbox-780A94",
I/flutter ( 4985): │ 💡                                 "rssi": -61
I/flutter ( 4985): │ 💡                         }, {
I/flutter ( 4985): │ 💡                                 "ssid": "ioGiant_6A97B0",
I/flutter ( 4985): │ 💡                                 "rssi": -67
I/flutter ( 4985): │ 💡                         }, {
I/flutter ( 4985): │ 💡                                 "ssid": "GUEST-FASTWEB-2XGE29",
I/flutter ( 4985): │ 💡                                 "rssi": -68
I/flutter ( 4985): │ 💡                         }, {
I/flutter ( 4985): │ 💡                                 "ssid": "FASTWEB-2XGE29",
I/flutter ( 4985): │ 💡                                 "rssi": -70
I/flutter ( 4985): │ 💡                         }, {
I/flutter ( 4985): │ 💡                                 "ssid": "TIM-38325975",
I/flutter ( 4985): │ 💡                                 "rssi": -74
I/flutter ( 4985): │ 💡                         }, {
I/flutter ( 4985): │ 💡                                 "ssid": "Wind3 HUB-56F871",
I/flutter ( 4985): │ 💡                                 "rssi": -74
I/flutter ( 4985): │ 💡                         }, {
I/flutter ( 4985): │ 💡                                 "ssid": "H3140-75642949",
I/flutter ( 4985): │ 💡                                 "rssi": -74
I/flutter ( 4985): │ 💡                         }, {
I/flutter ( 4985): │ 💡 
I/flutter ( 4985): └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

and then, for every custom message I send I receive the GATT_INVALID_PDU error. Is there anything that I can do to read the entire response? This is the code I used:

var data = {
  "type": "wizardConfig",
  "command": "scanAp",
  "sequence": 1002
};
var customMessage = jsonEncode(data);
log.i("sendReceiveCustomData: $customMessage");
var needToSend = Uint8List.fromList(
  utf8.encode(customMessage),
);
var encrypted = await prov.security.encrypt(needToSend);
var newData = await prov.transport.sendReceive('custom-data', encrypted);
var customAnswerBytes = await prov.security.decrypt(newData);
var customAnswer = utf8.decode(customAnswerBytes);
log.i("Custom data scanAp answer 2: $customAnswer");

The same thing happens using the sendReceiveCustomData function.

Thanks, Vincenzo

ivanhercaz commented 3 months ago

This is the code I used:

var data = {
  "type": "wizardConfig",
  "command": "scanAp",
  "sequence": 1002
};
var customMessage = jsonEncode(data);
log.i("sendReceiveCustomData: $customMessage");
var needToSend = Uint8List.fromList(
  utf8.encode(customMessage),
);
var encrypted = await prov.security.encrypt(needToSend);
var newData = await prov.transport.sendReceive('custom-data', encrypted);
var customAnswerBytes = await prov.security.decrypt(newData);
var customAnswer = utf8.decode(customAnswerBytes);
log.i("Custom data scanAp answer 2: $customAnswer");

I am curious about, why are you using the package in that way? The idea of the package is to implement a ProvTransport that then it'll be used with EspProv(transport, security) and what you use it is the EspProv methods. So it is possible that maybe something isn't working because it isn't the expected way it needs to work.

Then, looking at your code, I don't see the part in which you connect and then establish a session, so I imagine there are more lines. A possible problem, given that the error is a GATT_INVALID_PDU it is that you are connecting to device more than one at the same time or even the MTU is wrong by some reason. Take a look to this comment I wrote above https://github.com/ogabrielinacio/esp_provisioning_ble/issues/8#issuecomment-1953952812.


@ogabrielinacio this issue is being mixed a lot, so I don't know if the best option is just close it because the original issuer have not replied in months or enable the discussions in the repository and transfer it there, full or even split into several threads inside the same topic.

vic-pic commented 3 months ago

@ivanhercaz the code I posted above was just another try to make it working. But now I solved the problem: I use the startScanWiFi method to get the list of available WiFi networks and a custom message specific to the device to make it to connect to the WiFi and everything works correctly, I don't receive the GATT_INVALID_PDU error anymore.

Thanks for your help, Vincenzo

ivanhercaz commented 3 months ago

@ivanhercaz the code I posted above was just another try to make it working. But now I solved the problem: I use the startScanWiFi method to get the list of available WiFi networks and a custom message specific to the device to make it to connect to the WiFi and everything works correctly, I don't receive the GATT_INVALID_PDU error anymore.

Oh, it is really great to know you already solve the solution! Thanks for letting us know ❤️

I recommend you to read and follow the README of the repository from zero to practice. If you have more question, as this repository doesn't have "Discussions" enabled, you can open another issue. In case "Discussions" would be enabled in the future, questions may be moved there to keep "Issues" section just for bugs, feature requests, etc.

Thanks for your help, Vincenzo

Your welcome!