I have a photon 2 acting as a peripheral to my iPhone which is acting as the central. The photon 2 is meant to advertise, and when connected to my the iPhone, receive a timestamp from the phone, and then the p2 should disconnect. Basically stop advertising and move on. Unfortunately as soon as the disconnect occurs a new connection is made. The iPhone is constantly scanning for the p2 and will attempt connection when it receives it advertisement but the P2 says it is no longer advertising but for some reason the connection continues to be made. Is this a bug in the BLE stack? Here is my simplified code.
Disconnecting...
not advertising!
Connected to phone with address 46:B4:79:D6:1A:04
got time
Disconnecting...
not advertising!
Connected to phone with address 46:B4:79:D6:1A:04
got time
Disconnecting...
not advertising!
Connected to phone with address 46:B4:79:D6:1A:04
got time
Disconnecting...
not advertising!
Connected to phone with address 46:B4:79:D6:1A:04
got time
Disconnecting...
not advertising!
Connected to phone with address 46:B4:79:D6:1A:04
got time
This is being investigated. It appears that it may be a threading-related bug in Device OS. [This is being investigated, but the threading-related issue was a different bug report.]
On a potentially related note, I have also determined that if the Photon 2 connects to the iPhone first as a peripheral it can no longer connect to another peripheral as a central. It discovers the device but then fails on the connect. However, if it connects to the advertising peripheral first it can then connect to the phone as a peripheral without issue. Not sure if this is related. Essentially my use case is this:
---> <Photon 2> ---> iPhone. (all over BLE)
Medical device is always a peripheral UART
Photon 2 is a central to the Medical Device and a Peripheral to the Phone
Phone is a central
This may be related, however I can post a new topic on this if necessary along with code to duplicate.
Hey I see a 6.2 pre-release for the Photon 2 in VSCode this morning! @gusgonnet Going to see how my reconnection situation works out with the new device OS.
Hi @iitgrad, all of the BLE.stopAdvertising(); in your source code is actually a no-op, since BLE is not advertising at the time the API is called and this API simply returns. If you want to stop advertising after disconnected, you are supposed to call this API after the disconnected callback is invoked.
In DVOS, BLE will restart advertising automatically after disconnected from BLE central device. There is no wiring API to disable this feature as of right now.
BTW, what is the mobile app that you were using to send the time to Photon2? Does it keep scanning for your specific Photon2s and connect to it once scanned?
Glad to hear it worked for you! We'll discuss internally to see whether we should expose a wiring API to disable the "disconnect to restart advertising" feautre.
Regarding your question of the iPhone app. Yes, it is always scanning for this peripheral as I need it to to get a connection when the peripheral needs the connection, however, I need the peripheral to make that decision on its own which is why the ability for it to get its time and then disconnect on its own was important.
I guess my only thought on this is that there was a perception on my part that
during a connection there is no advertising
if advertising is enabled, as soon as there is a disconnect, the advertising would be immediately reinitiated before I could turn it off
which is why I just wanted to disable advertising such that whenever the device was not connected it would choose not to advertise until directed to do so.