The HM-10 has three modes of connection.
Here is what says the datasheet (quite poor) :
AT+TYPE[para1] Para1: 0~2
0:Not need PIN Code
1:Auth not need PIN
2:Auth with PIN
3:Auth and bond
Default: 0
Important: If your module version is less than V515, please don’t use
this command. Under android 4.3 AT+TYPE1 is same to AT+TYPE2.
Note1: Value 3 is added in V524.
So I tried successfully the "No PIN code" mode and it works (see
my iBeacon App)
The _connected event is trapped to launch the services discovery of the beacon :
Sub Manager_Connected (Services As List)
manager.ReadData2(TheServiceId, TheCharacteristic)
End Sub
When I am in mode 1, 2 or 3, I can't see any difference between them. And the PIN code windows pops up after the Connected event.
The consequence is that I launch the service discovery and get these results in the log (BLE2 logs) :
Discovering services.
Setting descriptor. Success = true
writing descriptor: true
As the discovery is Ok, my code goes on its stuff and finally completely freezes the connection even if I enter the pin code.
I did try to modify the Manager_Connected sub to add a manual condition "if the beacon is locked by the user". My idea was to only automatically connect when in mode 0 and and to manually discover services when in password protected mode : it almost works but it is very cumbersome and not reliable :
Sub Manager_Connected (Services As List)
If Not(TheBeacon.Locked) Then manager.ReadData2(TheServiceId, TheCharacteristic)
'manager.ReadData2(TheServiceId, TheCharacteristic)
End Sub
Sub Subscribe
manager.ReadData2(TheServiceId, TheCharacteristic)
End Sub
So the best way would be to have the "system" PIN_code_Connected event to do things more properly.
Thanks for your help