2

I have been working with BLE devices for IoT solutions. I have a issue with reconnecting the BLE node to my SBC after disconnecting the BLE node.

case: I always have to scan using $sudo hcitool lescan and then run my bluepy python app to request data over BLE. At this point of time I can disconnect the BLE node and reconnect it within say 15 seconds. but if I wait any longer, I again have to run lescan cmd and then run my bluepy app to connect and communicate. I just want to eliminate the scanning part everytime before i run blupy app. May I know what exactly happens when I execute lescan cmd after which the bluepy app starts communicating with my ble node?

I presumed that the lescan cmd will switch the dongle to ble mode and tried to keep ble mode as default by setting flags using
sudo hcitool -i hci0 cmd 0x08 0x0008 1e 02 01 16 1a (changing 1a to 16 as per thread How to set bluez mode?)

All I want is to run the blupy app with the ble device mac ID and start communicating without the need to lescan.

Thanks in advance

Community
  • 1
  • 1
Vik
  • 23
  • 7
  • StackOverflow is **strictly** available for **software programming** problems, not hardware. I suggest migrating to anther platform in StackExchange – Daniel Cheung Aug 27 '15 at 14:32

1 Answers1

0

I found a solution to what i was searching with little R&D efforts. The below script is to simulate the hcitool lescan command. Note the last cmd must be commented so that the hci0(BT 4.0 device) doesnt get exit the le mode.

===============================================================

echo "hci0 up"

sudo hciconfig hci0 up

echo "***** setting hci0 as master *****"

sudo hciconfig hci0 lm MASTER

echo "***** setting lescan state *****"

sudo hcitool -i hci0 cmd 0x08 0x000b 01 10 00 10 00 00 00

sudo hcitool -i hci0 cmd 0x08 0x000c 01 01

echo "***** Disabling lescan *****" sudo hcitool -i hci0 cmd 0x08 0x000c 00 00

(you may comment the above command to stay in LE mode hence disabling classic BT mode)

============================================================

you may verify the above cmd vales using hcidump -R for issued lescan command for scanning in 2 different terminals.

Vik
  • 23
  • 7