Esempio n. 1
0
 public BeaconMessage(Beacon beacon)
 {
     BeaconName = GetBeaconName(beacon.BluetoothAddress.ToString());
     Distance = beacon.Distance;
     ProximityRange = beacon.ProximityRange.ToString();
     Temperature = beacon.GetTemperature();
     Time = DateTime.Now;
 }
        /// <summary>
        /// Analyze the received Bluetooth LE advertisement, and either add a new unique
        /// beacon to the list of known beacons, or update a previously known beacon
        /// with the new information.
        /// </summary>
        /// <param name="btAdv">Bluetooth advertisement to parse, as received from
        /// the Windows Bluetooth LE API.</param>
        public void ReceivedAdvertisement(BluetoothLEAdvertisementReceivedEventArgs btAdv)
        {
            // Check if we already know this bluetooth address
            foreach (var bluetoothBeacon in BluetoothBeacons)
            {
                if (bluetoothBeacon.BluetoothAddress == btAdv.BluetoothAddress)
                {
                    // We already know this beacon
                    // Update / Add info to existing beacon
                    bluetoothBeacon.UpdateBeacon(btAdv);
                    return;
                }
            }

            // Beacon was not yet known - add it to the list.
            var newBeacon = new Beacon(btAdv);
            BluetoothBeacons.Add(newBeacon);
        }
Esempio n. 3
0
        /// <summary>
        /// Analyze the received Bluetooth LE advertisement, and either add a new unique
        /// beacon to the list of known beacons, or update a previously known beacon
        /// with the new information.
        /// </summary>
        /// <param name="btAdv">Bluetooth advertisement to parse, as received from
        /// the Windows Bluetooth LE API.</param>
        public void ReceivedAdvertisement(BluetoothLEAdvertisementReceivedEventArgs btAdv)
        {
            // Check if we already know this bluetooth address
            foreach (var bluetoothBeacon in BluetoothBeacons)
            {
                if (bluetoothBeacon.BluetoothAddress == btAdv.BluetoothAddress)
                {
                    // We already know this beacon
                    // Update / Add info to existing beacon
                    bluetoothBeacon.UpdateBeacon(btAdv);
                    return;
                }
            }

            // Beacon was not yet known - add it to the list.
            var newBeacon = new Beacon(btAdv);

            BluetoothBeacons.Add(newBeacon);
        }
Esempio n. 4
0
        /// <summary>
        /// Analyze the received Bluetooth LE advertisement, and either add a new unique
        /// beacon to the list of known beacons, or update a previously known beacon
        /// with the new information.
        /// </summary>
        /// <param name="btAdv">Bluetooth advertisement to parse, as received from
        /// the Windows Bluetooth LE API.</param>
        public void ReceivedAdvertisement(BluetoothLEAdvertisementReceivedEventArgs btAdv)
        {
            if (btAdv == null)
            {
                return;
            }

            // Check if we already know this bluetooth address
            foreach (var bluetoothBeacon in BluetoothBeacons)
            {
                if (bluetoothBeacon.CheckAddress(btAdv))
                {
                    // We already know this beacon
                    // Update / Add info to existing beacon
                    bluetoothBeacon.UpdateBeacon(btAdv);
                    return;
                }
            }

            for (int i = BluetoothBeacons.Count - 1; i >= 0; i--)
            {
                if ((DateTimeOffset.Now - BluetoothBeacons[i].Timestamp).Seconds > 10)
                {
                    BluetoothBeacons.Remove(BluetoothBeacons[i]);
                }
            }

            // Beacon was not yet known - add it to the list.
            var newBeacon = new Beacon(btAdv);

            Beacon.BeaconTypeEnum[] filter = { Beacon.BeaconTypeEnum.EstimoteStone, Beacon.BeaconTypeEnum.EstimoteNearable };
            if (Array.IndexOf(filter, newBeacon.BeaconType) > -1)
            {
                BluetoothBeacons.Add(newBeacon);
                if (newBeacon.BluetoothAddressAsString == "60202cd8293ba3d9")
                {
                    newBeacon.PropertyChanged += NewBeacon_PropertyChanged;
                }
            }
        }
        public void SetAdvertisingPayload(Beacon.BeaconTypeEnum protocol)
        {
            if (protocol == Beacon.BeaconTypeEnum.iBeacon)
            {
                var writer = new DataWriter();
                var payload = new byte[] { 0x02, 0x15, 0x02, 0x15, 0x0A, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0xC2 };
                foreach (byte b in payload)
                    writer.WriteByte(b);

                var manufacturerData = new BluetoothLEManufacturerData();
                manufacturerData.CompanyId = 0x004C; // iBeacon
                manufacturerData.Data = writer.DetachBuffer();

                _publisher.Advertisement.ManufacturerData.Clear();
                _publisher.Advertisement.ManufacturerData.Add(manufacturerData); 
            }
        }
 private void SetNotificationContent(Beacon beacon)
 {
     if (beacon.BeaconType == Beacon.BeaconTypeEnum.Eddystone)
     {
         if (beacon.GetUrlEddystoneFrame() != null)
         {
             NotificationTitle = "Welcome home!";
             NotificationBody = "Which TV-show would you wanna watch today?";
             NotificationParameter = beacon.GetUrlEddystoneFrame().CompleteUrl;
         }
         else if (beacon.GetTlmEddystoneFrame() != null)
         {
             NotificationTitle = "You have been out for a while!";
             NotificationBody = "The temperature at the house is {0} ºC";
             NotificationParameter = beacon.GetTlmEddystoneFrame().TemperatureInC;
         }
     }
     else if (beacon.BeaconType == Beacon.BeaconTypeEnum.iBeacon)
     {
         NotificationTitle = "Have a nice day!";
         NotificationBody = "Hope to see you again :)";
         NotificationParameter = beacon.Distance;
     }
     else {
         NotificationTitle = "N/A";
         NotificationBody = "N/A";
         NotificationParameter = "N/A";
     }
 }