Esempio n. 1
0
        protected override void StartListening()
        {
            _observer = new EPXProximityObserver(new EPXCloudCredentials(EstimoteCloudAppId, EstimoteCloudAppToken), error =>
            {
                SensusServiceHelper.Get().Logger.Log("Error while initializing proximiy observer:  " + error, LoggingLevel.Normal, GetType());
            });

            List <EPXProximityZone> zones = new List <EPXProximityZone>();

            foreach (EstimoteBeacon beacon in Beacons)
            {
                EPXProximityZone zone = new EPXProximityZone(new EPXProximityRange(beacon.ProximityMeters), "sensus", beacon.Name);

                zone.OnEnterAction = async(triggeringDeviceAttachment) =>
                {
                    await StoreDatumAsync(new EstimoteBeaconDatum(DateTimeOffset.UtcNow, beacon, EstimoteBeaconProximityEvent.Entered));
                };

                zone.OnExitAction = async(triggeringDeviceAttachment) =>
                {
                    await StoreDatumAsync(new EstimoteBeaconDatum(DateTimeOffset.UtcNow, beacon, EstimoteBeaconProximityEvent.Exited));
                };

                zones.Add(zone);
            }

            SensusContext.Current.MainThreadSynchronizer.ExecuteThreadSafe(() =>
            {
                _observer.StartObservingZones(zones.ToArray());
            });
        }
Esempio n. 2
0
        public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
        {
            // get your app ID and token on:
            // https://cloud.estimote.com/#/apps/add/your-own-app
            var creds = new EPXCloudCredentials("app ID", "app token");

            observer = new EPXProximityObserver(creds, (error) => {
                Debug.WriteLine($"error = {error}");
            });

            var range = new EPXProximityRange(1.0);

            var zone1 = new EPXProximityZone(range, "beacon", "beetroot");

            zone1.OnEnterAction = (triggeringDeviceAttachment) => {
                Debug.WriteLine("zone1 enter");
            };
            zone1.OnExitAction = (triggeringDeviceAttachment) => {
                Debug.WriteLine("zone1 exit");
            };

            var zone2 = new EPXProximityZone(range, "beacon", "lemon");

            zone2.OnEnterAction = (triggeringDeviceAttachment) => {
                Debug.WriteLine("zone2 enter");
            };
            zone2.OnExitAction = (triggeringDeviceAttachment) => {
                Debug.WriteLine("zone2 exit");
            };

            observer.StartObservingZones(new EPXProximityZone[] { zone1, zone2 });

            Debug.WriteLine("Proximity all ready to go!");

            return(true);
        }