BluetoothLE extension can't reconnect to ble device after using RegisterForString

Dear, I hope to find someone that can help me to solve this issue.
I have investigate so much but I'm in a dead end.
I think that can be replicated in easy way

this strange issue and it's a little bit difficult from explain:
i have very simple app with BluettothLE extension that connect to ESP32 device for read some parameter.

the procedure in the app that I follow is:

  • scan BLE device, found a device in a ListView
  • connect to a BLE device (with pin authentication)
  • use RegisterForString and the event StringsReceived to read from device via BLE and write them in a textbox
  • all works fine.

after a disconnection, i repeat the procedure above:

  • scan BLE device, found a device in a ListView
  • try to connect ... but the the app don't ask the pin and the property isDeviceConnected become to true, but the device are not really connect.

to restore the connection I must disconnect the device and repeat the procedure above and then works again..

I have tryed with different version of BluettothLE (same problem)
I have tryed with different smartphone (samsung S10, A72, S7, motorola and other)
the problem occurs both in develope with companion and in the build apk version.

I have tryed the same app but using the ReadString function in a timer event and the reconnection works fine (at the first temtative). But in this case i can't read all value from BLE device because of the time schedule.

from my tests it seems that if you use the RegisterForString function something is left hanging that does not allow the connection to the same or a different device. Maybe it's just a question of timeout.

I have tryed to use the UnregisterForValue function, but not resolve the issue.

in attach the aia code for both application one with RegisterForString and the other with ReadString

test_ble_connecting_RegisterForString.aia (205.3 KB)
test_ble_connecting_ReadString.aia (205.3 KB)

First of all, can anyone try these two app and verify if my issue is replicate?

I have the exact same problem, since 2.72 App Companion, the RegisterForString crashes the BLE app. If I disable that block, the app doesn't crash but I can't receive and data from the BLE device. Samsung OS 14. App worked previous day before the upgrade to 2.72

I'm using companion 2.66 on android 14 and 2.72 on android 12 for the display issue.
But the issue described: you must reconnect 2 times to have a successfully connection is the same from a lot of year. I have this issue from almost 3 year ago, I have thinked there is a problem in my code, but today I have investigate so much.

Dears
Can anyone test my project to confirm my issue?

Thanks

Check both the Companion and BLE FAQs for more recent versions:

Dear ABG
Many thanks for suggest

I have already check, but without result

I would like to ask you: can you try my 2 app above for confirm the issue? (only with that use RegisterForString have issue)

thanks

I have no BLE hardware, can only read source code against board posts

I have no time to set up my esp32, but I am wondering about some things here:
In this block,


I think you do not need to call for the location status, because the newest BLE extension does that for you.
Then, I do not think it is a good idea to both ScanForService and StartScanning. I never used ScanForService, to be on the safe side, do ony StartScanning, until it works. Then experiment.

Further:


If you first disconnect, then it seems to me that it is useless to unregister for values
and also, you ask to disconnect when your device is already disconnected. Seems strange to me.
The only thing you should do in that block is setting some message in a label, your labelStatus for example, indicating that the device is disconnected.

1 Like

You might check out the Designer attributes for the BLE component, and their help (?) links:
image

image

I would imagine that if you don't try to determine the user's location, you don't need to worry about permission to do that.

Yes, i know, i have tryed with and without

I use scan for service to filter only my device inside of a lot of ble device

I have tryed to execute UnregisterForValues before disconnection but not work yet

thanks.
i have used an old source code that need location.
but the issue on reconnection there is always even without the use of locations

Then do not call for the location status, It is not useful to do things that are not needed.

I use scan for service to filter only my device inside of a lot of ble device
Either scan for service or do the scanning, both is useless.

I have tryed to execute UnregisterForValues before disconnection but not work yet
Why, again, why, would you unregister for values if you are disconnecting anyway? After that your values are not registered anymore, so do not do it!
Only if you would want to resister other values and not disconnect, that may be useful. Again and again, do not code things that are not necessary.

Since the problem only occurs if you use the RegisterForString function, I thought that this function was leaving something hanging and tried to use the unregister function hoping that it would solve the problem. Now regardless of the useless code that is the result of attempts to solve, which however does not change the functionality, the problem remains that if you use the RegisterForString function after disconnecting, to reconnect you have to do the operation twice.

Yes, but you cannot use the registerforstrings function AFTER you have disconnected. Of course that does not work. You cannot communicate with a device that you are not connected to.

Dear.
I don't use registerforstring after disconnection.
the sequence is:

  • connect
  • registerfor string
  • disconnect

after that a new registration doesn't work (dont' ask pin for connection), you need to disconnect and reconnect again (2 time to have a functional connection)

is there anyone that can try my 2 simple code and confirm the issue?
thanks

Sorry, I cannot try your code because you did not provide an .ino file.
And frankly, I do not want to. I really tried to explain to you what is wrong with your code, but you do not believe me.

And, do away with that Timer stuff, it may help to make trouble:


You can set LabelStatus in the When.BluetoothLe connected block, you set the scanning status allready at the place where it should be, and you could set the connected status in the When,BLE connected block.
Timers always severely mess up things, especially if you let them interfere with your BLE processing.

Good luck.

Dear
I think you can use the standard .ino sample of ESP32 BLE dstribuited with the device ESP32
(Example-DOIT ESP32 DEVKit V1->BLE->Server)

now i'm trying to connect to a BLE device different from esp32
an arduino with hm06 module

An hm06 is classic Bluetooth. You cannot use BLE for that. Try hm10 or change your code to use classic BT.

Hi Marco

See my website for all things Bluetooth. There is a chart that identifies Bluetooth Modules:

ProfessorCad: Tips & Tricks Bluetooth Modules for Microcontrollers

The HM06 modules are Classic Bluetooth (v2.1) - They do not support BLE.

of course
i have wron write, HM10 module.
i'm testing now