How to detect if LTE is connected for a watch face icon

With the va3 Music LTE, I put together a small function see if LTE is connected, as you can do with phoneCommetect for a Bluetooth connection.

Here is is:
function lteState() {
var state=null;
var ci=System.getDeviceSettings().connectionInfo[:lte];
if(ci!=null) {state=(ci.state==Sys.CONNECTION_STATE_CONNECTED) ? true:false;}
return state;
}

before using it, you do want to do a "has" similar to this. (I do it in initialize, and check the boolean before calling this function)

if(lSystem.getDeviceSettings() has :connectionInfo) {hasLTE=(lteState()!=null);}

It checks if connectionInfo is available, and if so calls lteState(). If that returns null, there's no LTE on the device;

I've only tested this in the sim, but I'm using it in watch faces today. The real test will be a user with a va3 Music LTE.
  • jim_m_58 fair enough. To be honest, in my own apps, I've gotten rid of simple functions (manual inlining), transformed classes into static functions and used horrible global variables, all in the name of saving memory (code space), so I know where you're coming from. I actually hate inefficient / redundant code, but there's always a balance. For example, if lteState() were only ever called once, we could make it even more efficient by simply replacing the function call with the code itself (manual inlining). Of course the initialization code would have to change a bit. Of course, I'm not suggesting that at all - I think that would look terrible. But it could be slightly more efficient.

    Anyway, thanks again for all the information! :)

    I've already submitted a pull request to the Crystal watchface github repo to add tri-state support for bluetooth, and if I ever write my own watchface, I'll be sure to take advantage of connectionInfo.
  • before spending too much time, you may want to throw together something really simple to see how CONNECTION_STATE_NOT_INITIALIZED works on a device. It may be when the watch hasn't been paired to a phone vs when you just turn off BT on the watch for example. With wifi, if you've not set up any wifi nets, etc.
  • Thanks for the advice. Yep, I'm usually one to put the cart before the horse.

    You're right, it doesn't work the way I expected :/. I tried it on the 935 and disabling bluetooth still produces no different results then enabling bluetooth and not being connected to a phone.

    I guess "not initialized" really means "not initialized" and not "disabled" as I (wishfully) thought. I sure wish there was a way to detect whether bluetooth is disabled in a CIQ watchface, since the native watchfaces can do so.

    Well, sorry for wasting everyone's time. I edited my earlier posts to correct misinformation / speculation.

    Having said that, I think the docs are misleading:
    CONNECTION_STATE_NOT_INITIALIZED = 0
    Indicates that the connection is not setup or is inactive.


    I would assume that if you disable bluetooth, then the connection would be inactive.
  • This is why a simple test case can come in handy!