/// <summary>
        /// Called by the native plugin when beacons are detected.
        /// </summary>
        /// <param name="beacons">A string representation of the detected beacons</param>
        private void DidRangeBeaconsCallback(string beacons)
        {
            if (!string.IsNullOrEmpty(beacons))
            {
                List <EstimoteUnityBeacon> estimoteBeacons = new List <EstimoteUnityBeacon> ();

                var beaconsJsonList = MiniJSON.Json.Deserialize(beacons) as List <object>;
                foreach (object o in beaconsJsonList)
                {
                    Dictionary <string, object> beaconJson = o as Dictionary <string, object>;

                    string uuid     = (string)beaconJson ["UUID"];
                    int    major    = (int)((long)beaconJson ["Major"]);
                    int    minor    = (int)((long)beaconJson ["Minor"]);
                    int    range    = (int)((long)beaconJson ["BeaconRange"]);
                    int    strength = (int)((long)beaconJson ["RSSI"]);
                    double accuracy = GetDouble(beaconJson ["Accuracy"]);

                    EstimoteUnityBeacon estimoteUnityBeacon = new EstimoteUnityBeacon(uuid, major, minor, range, strength, accuracy);
                    estimoteBeacons.Add(estimoteUnityBeacon);
                }

                if (OnDidRangeBeacons != null)
                {
                    OnDidRangeBeacons.Invoke(estimoteBeacons);
                }
            }
            else
            {
                if (OnDidRangeBeacons != null)
                {
                    OnDidRangeBeacons.Invoke(null);
                }
            }
        }
Exemple #2
0
        void FindClosestBeacon()
        {
            EstimoteUnityBeacon clo;        //closest estimote beacon
            double minVal;                  //min value

            if (estimoteBeacons != null && estimoteBeacons.Count > 0)
            {
                clo    = estimoteBeacons[0];
                minVal = clo.RSSI;
                for (int i = 1; i < estimoteBeacons.Count; i++)
                {
                    if (estimoteBeacons[i].RSSI > minVal)
                    {
                        clo    = estimoteBeacons[i];
                        minVal = clo.RSSI;
                    }
                }
                closestBeacon = clo;
                return;
            }
            else
            {
                closestBeacon = null;
            }
        }
Exemple #3
0
        Vector2 Trilateration(EstimoteUnityBeacon b1, EstimoteUnityBeacon b2, EstimoteUnityBeacon b3)
        {
            Vector2 position = new Vector2();

            //get the custom beacons to get data from Unity
            CustomBeacon c1 = FindCustomBeacon(b1);
            CustomBeacon c2 = FindCustomBeacon(b2);
            CustomBeacon c3 = FindCustomBeacon(b3);

            //get estimated distances from each estimoteBeacon
            float d1 = GetBeaconDistance(b1.RSSI);
            float d2 = GetBeaconDistance(b2.RSSI);
            float d3 = GetBeaconDistance(b3.RSSI);

            //temp variables set 1
            float A = (c1.transform.position.x * c1.transform.position.x) + (c1.transform.position.y * c1.transform.position.y) - (d1 * d1);
            float B = (c2.transform.position.x * c2.transform.position.x) + (c2.transform.position.y * c2.transform.position.y) - (d2 * d2);
            float C = (c3.transform.position.x * c3.transform.position.x) + (c3.transform.position.y * c3.transform.position.y) - (d3 * d3);

            //temp variable set 2
            float x32 = c3.transform.position.x - c2.transform.position.x;
            float x13 = c1.transform.position.x - c3.transform.position.x;
            float x21 = c2.transform.position.x - c1.transform.position.x;
            float y32 = c3.transform.position.y - c2.transform.position.y;
            float y13 = c1.transform.position.y - c3.transform.position.y;
            float y21 = c2.transform.position.y - c1.transform.position.y;

            //use temp variabales in trilateration equation to get position
            position.x  = (A * y32) + (B * y13) + (C * y21);
            position.x /= (2 * ((c1.transform.position.x * y32) + (c2.transform.position.x * y13) + (c3.transform.position.x * y21)));
            position.y  = (A * x32) + (B * x13) + (C * x21);
            position.y /= (2 * ((c1.transform.position.y * y32) + (c2.transform.position.y * y13) + (c3.transform.position.y * y21)));
            return(position);
        }
 /// <summary>
 /// Gets cloud beacon details for the specified beacon.
 /// </summary>
 /// <param name="beacon">The beacon</param>
 public void GetBeaconCloudDetails(EstimoteUnityBeacon beacon)
 {
     if (!EnableEstimoteCloud)
     {
         return;
     }
     GetBeaconCloudDetails(beacon.UUID, beacon.Major, beacon.Minor);
 }
Exemple #5
0
 //Find the Unite representation of each beacon if it exists
 CustomBeacon FindCustomBeacon(EstimoteUnityBeacon estimoteBeacon)
 {
     for (int i = 0; i < customBeacons.Length; i++)
     {
         if (customBeacons[i].major == estimoteBeacon.Major && customBeacons[i].minor == estimoteBeacon.Minor)
         {
             return(customBeacons[i]);
         }
     }
     //none of the custom beacons have the estimote beacon major/minor
     Debug.LogError("Found an estimote beacon that didnt have corresponding CustomBeacon... " + estimoteBeacon.Major + ": " + estimoteBeacon.Minor);
     return(null);
 }
Exemple #6
0
 //return true if found
 public bool SelectBeacon(CustomBeacon _beacon)
 {
     DeselectBeacon();
     for (int i = 0; i < estimoteBeacons.Count; i++)
     {
         if (estimoteBeacons[i].Major == _beacon.major && estimoteBeacons[i].Minor == _beacon.minor)
         {
             selectedBeacon = estimoteBeacons[i];
             _beacon.SelectBeacon();
             return(true);
         }
     }
     return(false);
     //selectedBeacon = null;
 }