OWM - delete data? deleteTemporalEvent()?

Hello,

   how to create a function that, for example, when Bluetooth is disconnected in 10 seconds, all weather data will be deleted and the values on the display will be empty?

Thanks

  • How often are you requesting data?  If you want it to "go stale" after 10 seconds, that's far too often.  With OWM, I only request data every 15 minutes (by default).  Understand that a weather station may only update OWM every hour.

    What you can do is if in the callback for the makeWebRequest it shows an error, mark your data "stale", but that can happen if you lose the connection for a short time (you see a -104).

    What I do, is use the "dt" field in the data.  It's the time stamp for the data.  If the data is more than say 3 hours old, that's when I mark it as stale.

    When I display the data, I also display the time stamp so I can see how old the data is.

  • I will try to explain it:

    they update the weather at regular intervals like 15, 30, 60 minutes.

    I want to make it so that when the watch is disconnected from the bluetooth device, the request: Communications.makeWebRequest will not be fired and the data on the display will be deleted, I don't want to mark it as old, but delete it and the data area on the display will be empty.

    Is it possible to achieve this somehow?

    I've seen it somewhere before, but I can't remember where...

  • As I said, you'll see the error in the callback for the makeWebRequest.   What I do in a background, is with BackGround.exit() I return the dictionary if all is OK, or the error code if not

    Then in onBackgroundData(data). I use

    if(data instanceof Number) {}

    to see if there was an error.  That can be as simple ad displaying an error message, or in your case, setting the data you have to null so you don't display it

  • As far as I understand, the OP is looking for something like onPhoneDisconnected() function to handle this event, to clean up data ASAP, not to wait until the next scheduled onBackgroundData(data) call occurs

  • Exactly, that's what I need.

    any ideas or pointers?

    Thanks

  • In your view's onUpdate() function, you could call System.getDeviceSettings(), check the phoneConnected field, and take appropriate action. The only potential problem is that phoneConnected will be false if bluetooth is connected, but the Connect app isn't open. I'm guessing that won't be a problem for you assuming that Connect needs to be open for your use case anyway.

    If you're worried about battery life, you could set a recurring timer for something like 5 to 30 seconds, and only check when the timer expires.

    As far as I know, there's no event / callback for this scenario tho. (i.e. there's nothing like onPhoneDisconnected or onDeviceSettingsChanged.)

    EDIT: as Jim pointed out, for this use case it makes more sense to look at connectionAvailable rather than phoneConnected.

  • As you are talking about deleteTemporalEvent, it sounds like you are using a background service

    In the callback for the makeWebRequest, do something like this:

    		function receiveWeather(responseCode, data) {
    			if(responseCode==200) {
                    Background.exit(data);
    			} else {
                    Background.exit(responseCode);
    	    }

    Then in your onBackgroundData(), this:

        function onBackgroundData(data) {
        	if(data instanceof Number) {
                //clear the data you have, and save the error if you want
        	} else {
                //save data to be displayed  
            }
        }

    The background will run at most every 5 minutes, so you shouldn't be burning much extra battery at all.

    Checking phoneConnected isn't realy ideal, as on devices like an edge, Wifi can be connected but the phone isn't, and your request should work with wifi.  Look at using connectionAvailable instead.

    If you just do the makeWebRequest in the background without checking for a connectiom, the callback will be called right away with an error.  Save the hassle (and code) of checking for either a phone or wifi connection.