언어 설정

Menu
Sites
Language
Weather Watch sample bind events not working

Hello,

I've been having trouble in building a watch face that gathers battery info.  I even tried running the sample Weather Watch and even that sample did not work.   Through trial and error, I finally discovered that the following lines of code in the sample's bind events are causing my problem...but I don't know why.  This is from the Weather Watch sample wearable 2.3.2 code:

//        tizen.time.setTimezoneChangeListener(function() {

//            updateWatch();
//            updateInformation();
//        });

        // Adds event listeners to update battery state when the battery is changed.
//        battery.addEventListener("chargingchange", updateBattery);
//        battery.addEventListener("chargingtimechange", updateBattery);
//        battery.addEventListener("dischargingtimechange", updateBattery);
//        battery.addEventListener("levelchange", updateBattery);

As you can see, I commented out the above lines and ran the WeatherWatch code, unchanged from the sample code, and it worked fine (except of course due to my comments it doesn't update the watch when the timezone has changed and doesn't update the battery level due to my having commented out the code.)  The rest of the sample Weather watch works beautifully.   But uncommenting these lines causes an error in the javascript.  Any idea what's happening?

By the way, other samples, like the Digital Watch sample 2.3.2 has the same exact code as above and it works fine!  

Edited by: Alan Buch on 01 3월, 2018

Responses

4 댓글
André Reus

Are you trying to run the app on Emulator? Or any Device which has Tizen OS 3.0 ? 

Alan Buch

I hadn't tried the emulator since it wasn't even working in the "web simulator". But since you asked, i went ahead and tried it - and to my surprise, it worked!  That is, the very same code that does not run in the simulator did run in the emulator.  That kind of deepens the mystery for me on one hand, but on the other it makes me feel better about the prospects of completing my watch face.  Its just that doing so will be much more cumbersome b/c the emulator is so dang slow.

Alan Buch

What's happening is this... despite appearances, both samples are failing on the bind events.  The reason the "DigitalWatch" sample appeared to work is because the bindevents function is the last thing called in process every 1/2 second.  Being last, everything else up to that point (updating the digital display with the current time and date) worked fine and the watch appeared to work great.  But in fact it was failing, just like the weather watch.  Its just that the bindevents in the weatherwatch sample happened earlier in the process and it was abundantly clear that it was failing.

The issue is that the battery information is unavailable to the Web Simulator.

             var battery = navigator.battery || navigator.webkitBattery || navigator.mozBattery;

results in "battery" being "null".  So the subsequent code that uses the battery object is failing. And there's no error handling in the sample code.

André Reus

hi Alan Buch, the purposes of web simulator should be limited to just UI test i think ... Did you find any warning regarding battery api in real device ... 

if you find, you may use   var battery = navigator.getBattery || navigator.webkitBattery || navigator.mozBattery;

And your you upgraded your device from 2.3.2 to 3.0 recently .... you may reset your device using gear manager and try again ..