/* Check whether the beacon was registred or now * If not, it will create a new one otherwise updated last RSSI * and timestamp */ private void CheckBeacon(string beaconMac, int rssi) { /* Check the beacon */ BeaconDao dao = new BeaconDao(); Beacon beacon = dao.GetBeacon(beaconMac); if (beacon == null) { /* There is no definition for this beacon. * Create a new beacon record */ beacon = new Beacon() { MACAddress = beaconMac, LastRssi = rssi, Name = "Unknown", }; /* save new beacon */ dao.NewBeacon(beacon); } else { /* Update beacon */ beacon.LastSignalTimestamp = DateTime.Now; beacon.LastRssi = rssi; dao.UpdateBeacon(beacon); } }
/* Updates the beacon that is provided as json */ private void UpdateBeacon(string data) { /* we are triming data below, splitting it by blank chars is not a valid way. * because blank char can become in the json object as well */ string command = "update beacon "; string json = data.Substring(command.Length); Beacon beacon = JsonConvert.DeserializeObject <Beacon>(json); BeaconDao beaconDao = new BeaconDao(); beaconDao.UpdateBeacon(beacon); ServiceClient.Send(OK); }