bluetooth state

Former Member
Former Member
Hello,
How to get the bluetooth connection state ? in the API there is new options since the SDK 3.0.0 with the object ConnectionInfo but when I try this in my Simulator the ConnectionInfo.state value is null. So How can I get the bluetooth statue (off, on but not connected, connected)

Thanks
  • Former Member
    Former Member over 6 years ago
    I got it :

    var settings = Toybox.System.getDeviceSettings();
    if (settings has : phoneConnected)
    {
    // Check the connection state v3.0.0
    var state = settings.connectionInfo[:bluetooth].state;

    the state value will be : CONNECTION_STATE_NOT_INITIALIZED, CONNECTION_STATE_NOT_CONNECTED or
    CONNECTION_STATE_CONNECTED
  • If you're just looking for the bt state, phoneConnected is all you need. True, it's connected, false it's not.
    Using connection state limits you to 3.0 devices, while phoneConnected works back to ciq1 devices - it's what's currently used on every watchface that shows it today is my bet.

    var isBTConnected= Sys.getDeviceSettings().phoneConnected;
  • Former Member
    Former Member over 6 years ago
    Yes , I'm using it before. But Now with the 3.0.0 it's possible to know if the bluetooth is active but not connected, I think this information is very important for those who want to know if their whatch try to find any bluetooth smartphone... and use the battery of the watch.
  • The way I understand it, NOT_INITIALIZED would be if you'd never paired to a phone. After it's paired the first time, you just see CONNECTED/NOT CONNECTED. Same as with phoneConnected.

    connectionInfo likely came about for Wifi as it relates to music provider apps. There, NOT_INITIALIZED would be if you never configured a wifi network on the watch, but after you do, it's again connected or not connected.
  • Former Member
    Former Member over 6 years ago
    ok thanks for your answer. But, It s not possible to know if the watch try to connect a bluetooh for exemple qith a parie phone on wich the bluetooth is not activated. I think this information could be interesting.
  • Not possible. You can just see if the phone is connected or not, so phoneConnected is all you need. Something like "is BT trumed on on the watch" is what you are looking for, but that's not exposed in CIQ.

    update: I sideloaded a test app I have (I was thinking about adding a wifi icon to things) on a couple watches, and turning off BT on the watch results in CONNECTION_STATE_NOT_CONNECTED, as I suspected.
  • Any idea how often the phoneConnected status is checked? I'm thinking about incorporating this in a watch face and showing an alert during the update every minute. Hoping doing so wouldn't affect battery usage.
  • It changes as the state changes, so when you check it, it's valid.
    Since this thread started, in another thread, it was posted that if wifi is connected, it will use that for makeWebRequest, but in general that will be uncommon as it's generally not connected.
  • Good stuff! Thanks for the info.
  • I tried both 

    isBTConnected= Sys.getDeviceSettings().phoneConnected;

    and

    settings.connectionInfo[:bluetooth].state;

    They work in the simulator but not on the actual watch, mine is  CIQ 3.2.5

    On the watch both always show that BT is connected.  I tried both turning the phone connection off in the watch Controls menu and also turning off bluetooth on the phone.

    What's up with this?  I check 2 other watch faces and they also show the BT is connected despite what I tried above.