Languages

Menu
Sites
Language
Retrieving battery status of paired mobile device

I'd like to display the battery level of my paired mobile device on my widget/watch face.  Has anyone done this and can provide some sample javascript?  Thanks!!

Responses

7 Replies
K Johnson

You may try using Accessory SDK. It'll provide you the facility to send battery status data from your paired mobile device via provider android app to consumer tizen web app. Please go through the samples attached with sdk.

Alan Buch

KJ - thanks for your response and your suggestion for the Accessory SDK.  I did read through the Accessory SDK materials including the API reference and programming guide.  I have to admit, its still not all that clear to me... but it sounds like this SDK would be useful if I want to create my own service to run, say, on the smartphone and then consume that service by the smartwatch and have both the service and consuming app exchange data as needed.  Further, its sounds like (although I didn't see it explicitly stated) that this SDK is based on the BLE and GATT - both of which I think i need to use for retrieving the paired and connected device's battery level.

However, i don't really want to require users of my watchface to download and install a companion app to the phone in order to get that phone's batterylevel.  Isn't that what the Accessory SDK would lead to or am I misunderstanding the Accessory SDK?  And am I right that this SDK uses BLE rather than "classic" bluetooth methods?

I've been somewhat successful in using classic bluetooth, but not BLE.  And unfortunately for me, every example I've found on the net uses BLE and UUIDs 180F and characteristic 2A19... but when I try using BLE and "startScan()"  i don't seem to get a response from any devices.  Yes, my samsung galaxy S3 is ancient, but still, its running android 4.3 which I understand supports BLE...yet nothing.  On the other hand, using getDefaultAdapter, "classic" bluetooth finds my devices, including my galaxy, including my pc, including an iphone5s.  Unfortunately, 180F doesn't show as one of the 16 services I discovered through this classic method.  Here's the basic code that I'm using - as you'll see, I've commented out the BLE methods b/c the onGotBTKnownDevices was never called (presuming that the startScan() never found any BLE devices...)

                try {
                    if (!bluetoothAdapter) {
            			bluetoothAdapter = tizen.bluetooth.getDefaultAdapter();
//                        bluetoothAdapter = tizen.bluetooth.getLEAdapter();
	        			
                    }
                    if (bluetoothAdapter)
	  				{
//                    	bluetoothAdapter.stopScan();
//                        bluetoothAdapter.startScan(onGotBTKnownDevices, onErrorBTKnownDevices);
                    	bluetoothAdapter.getKnownDevices(onGotBTKnownDevices, onErrorBTKnownDevices);
	  				}
                } catch (err) {
                    showMessage("ERROR: "+err, "Back", "Abort", "bluetooth");
                    writeLog("bluetooth-button click: " + err, "ERROR");
                }

...

    function onGotBTKnownDevices(devices) {
    	try 
        {
		var msg = "Bluetooth Devices found (" + devices.length + ") ",
	            devicesInfo = "";
	        bluetoothAdapter.stopDiscovery();
//	        bluetoothAdapter.stopScan();
	
            if (devices[1].isBonded && devices[1].isConnected)
	        	{	
	        	devicesInfo = getMajorDeviceClass(devices[1].deviceClass.major)+": "+devices[1].name;
        		devices[i].connectToServiceByUUID("00001101-0000-1000-8000-00805F9B34FB",
                	function (socket)
                        {
                	    try 
                            {
                		socket.onMessage = 
                                function() 
                                {
                    		    try 
                                    {
                    				var uuid = socket.uuid,
                    				   data = socket.readData();
                    	        		showMessage("Msg (1101)"+data, "Back", "Abort", "bluetooth");
                    	        		socket.close();
                    				}
                    				catch(err)
                    				{showMessage("ERROR<1101>:"+err, "Back", "Abort", "bluetooth");}
                			    };	
                			}
                			catch (err)
                			{showMessage("ERROR[1101]:"+err,"Back","Abort","bluetooth");}
    					});
	        	})
    	}
        catch....

 

Alan Buch

BTW, I realize 1101 is not a battery service...I was just trying to figure out how to connect to any service - this one seemed as good as any.  there are 16 services available to me (at least through the classic bluetooth method) - i tried them all and none of them ever call the onMessage function which I take to mean that none of them are sending any messages.

K Johnson

Hi Alan Buch,

"However, i don't really want to require users of my watchface to download and install a companion app to the phone in order to get that phone's batterylevel." this line from your previous reply is making me confused. If you don't want to keep a companion app than what's the way of sending data from your phone to gear. Would you please make it clear that how battery status data will be transferred without an app in android part?

SAP provides you the facility to transfer data from android to tizen then what's the reason behind using classic bluettoth or ble instead of SAP?

Moreover, you may try this link to scan BLE devices. 

Alan Buch

I see the confusion - let me explain....   My understanding is that most smartphones (including my Samsung Galaxy S3 running Android 4.3) already broadcast the battery information over bluetooth.  I believe this because when I get in to my car, the radio (which I've paired and connected to that phone) is able to display the battery level...I never downloaded any Mazda app to my phone - the car's radio just "knows" how much battery life my phone battery has after I've connected over bluetooth.

I hope to do the very same thing with my watchface - retrieve the battery level of the paired and connected phone via some bluetooth channel.

K Johnson

How about using UUID used for battery level in this link?

Alan Buch

The short answer is that my phone, like many other older devices, apparently doesn't broadcast over Bluetooth Low Energy - so it seems I'm stuck with "classic" bluetooth (at least until I upgrade).  Again, my car's radio is able to display the battery level from my phone and i'm convinced it does so using the Hands Free Profile.  One of the 16 services I found on my phone is 0000111F-0000-1000-8000-00805F9B34FB, the UUID for HFP.  And according to the HFP specification, section 4.7, "the AG [Audio Gateway, i.e. SmartPhone] shall send the [...] result code with the corresponding battery level indicator and value whenever the AG's battery level changes." It goes on to say that the battery charge indicator, "battchg", is sent with values ranging from 0-5.  This is what I need to tap into...but so far I am unable to connect to the Hands-free service of the phone. 

4.7
Transfer of Battery Level Indication of AG
The AT+CMER comm
and, as described in Section enables the “Battery Level Indication”
function in the AG.
The AT+BIA command, as described in Section
4.33, allows the HF to deactivate/reactivate
individual indicators.
When the C
MER function is enabled and the indicator has not been deactivated by the AT+BIA
command, the AG shall send the +CIEV unsolicited result code with the corresponding battery
level indicator and value whenever the AG's battery level changes. The HF shall be capable of
interpreting the information provided by the +CIEV result code to determine the battery level as
listed in Section 4.32.2
.