0

I have a test application that has two buttons one is to start Wifi Tracking and one to to stop. When I start the Wifi tracking, if there is an access point in range and entry event is not fired so I am not aware of being in the fence. Is there a way that when tracking starts that I can be notified that I am within a fence?

function startWifiTracking() {
    //create the geofences and triggers 
    var triggers = {
        Wifi : {
                fc_entry : {    type : 'Enter', 
                                areaAccessPoints : [{SSID: 'test', MAC: '12:12:12:12:12:12'}], 
                                callback : entry1, 
                                otherAccessPointsAllowed : true},
                fc_exit : {     type : 'Exit', 
                                areaAccessPoints : [{SSID: 'test', MAC: '12:12:12:12:12:12'}], 
                                callback : exited1, 
                                otherAccessPointsAllowed : true}
        }};

    //create the wifi policy for the wifi access points to be monitored
    var policy = {
        Wifi : {
            interval : 3000,
            signalStrengthThreshold : 15,
            accessPointFilters : [{SSID: 'test', MAC: '*'}]
        }};
    WL.Device.startAcquisition(policy, triggers, acquisitionFailure);
}

//trigger callbacks for each wifi fence
function entry1() { alert('entered'); }
function exited1() { alert('exited'); }
function acquisitionFailure() {alert('failed');}

$(function() {
    $('#btnStart').click( function(){
        startWifiTracking();
    });
});

$(function() {
    $('#btnStop').click( function(){
       WL.Device.stopAcquisition();
    });
});
Idan Adar
  • 44,156
  • 13
  • 50
  • 89
Ken Nelson
  • 49
  • 4
  • What platform are you testing this code on? Please note the differences in [platform support](http://www-01.ibm.com/support/knowledgecenter/SSZH4A_6.2.0/com.ibm.worklight.dev.doc/devref/c_location_platform_support.html?lang=en) – MotiNK Aug 08 '14 at 11:19
  • Android. The issue is not that the methods do not work, they just don't work correctly. I can turn on and off access points and I get the message for either entering or exiting a location. The issue is if I am currently in a location and turn on tracking, no method gets fired to say that I am in that location. – Ken Nelson Aug 11 '14 at 18:10

1 Answers1

0

I think there are a couple of different things that you could try here.

1) Use a DwellInside trigger with a dwellingTime parameter of 0.

2) Use WL.Device.Wifi.acquireVisibleAccessPoints API and check if the received array of access points is non-empty in the onSuccess callback.

MotiNK
  • 421
  • 2
  • 12
  • So that is an interesting workaround but does not support the use case. If I start tracking and I am in range of a wifi access point then an event should be fired that says I have entered the fence. If I am using dwellInside for other purposes, for instance to track the time in a fence, than I am dual purposing the event and have to trap for things like "Was I already in the fence". Which means that I have to create a state machine. – Ken Nelson Aug 29 '14 at 17:04
  • Similar issue with WL.Device.Wifi. I could, when I start tracking, fire off that message than cycle through the list of returned access points and then fire off whatever method the enter event was going to do. And so this is the best of the two work arounds in my opinion. – Ken Nelson Aug 29 '14 at 17:05
  • However wouldn't it be nice if when I fire the startTracking method it would recognize that I am in a fence and simply fire off the right events? – Ken Nelson Aug 29 '14 at 17:06
  • I think that it shouldn't impact you in terms of timings; just replace the Enter trigger with the DwellInside with dwellingTime 0 and you should be fine there. Note that you can have additional DwellInside triggers with larger times (and with different callbacks/events). But it does seem like there is a bit of a confusing distinction there between the DwellInside behavior and the Enter behavior that should, at the very least, be better called out in the documentation. – MotiNK Sep 01 '14 at 06:28