noble / bleno

A Node.js module for implementing BLE (Bluetooth Low Energy) peripherals
MIT License
2.12k stars 447 forks source link

Peripheral returns 0 services until startup is finished #402

Open jeremyabannister opened 6 years ago

jeremyabannister commented 6 years ago

Here's my setup:

  1. I'm using a raspberry pi zero w, with the latest Raspbian release, node version 9.7.1.
  2. I have run sudo systemctl disable bluetooth and then sudo hciconfig hci0 up.
  3. My script is at /home/pi/bluetooth/bluetoothCore.js. This script imports bleno and begins advertising.
  4. In /etc/rc.local I have a line node /home/pi/bluetooth/bluetoothCore.js &.

Here's my problem:

After a certain number of seconds rc.local gets run and therefore my script gets run. The iPhone app I'm developing detects the device (because it has started advertising), but when it connects and tries to discover services it sees 0 services. After another 30-40 seconds of startup my app can see the services. What I want is to not run my script (not start advertising) until all necessary system services have been initialized so that I do not have this period of apparent broken functionality upon startup. Unfortunately, I do not have any clue which component is missing at that early startup phase that causes the services to be non-discoverable. Furthermore, even if I knew the moment which would be the right moment to run my script, I have a very limited understanding of the phases of startup and how to run code at different parts of it. What can I do to ensure that my bleno js code only runs when the system is actually ready to begin partaking in bluetooth interaction?

guanghw commented 6 years ago

same problem ,waiting answer