public void Start(TracingInformation tracingInformation) { if (tracingInformation == null || _enabled) { return; } _tracingInformation = tracingInformation; _peripheralManager.RemoveAllServices(); CBUUID uuidService = CBUUID.FromString(tracingInformation.ServiceId); CBUUID uuidCharacteristic = CBUUID.FromString(tracingInformation.CharacteristicId); var data = NSData.FromArray(PayloadFormatter.GetBytesToSend(new PackageData(tracingInformation.DeviceId))); var characteristic = new CBMutableCharacteristic(uuidCharacteristic, CBCharacteristicProperties.Read, data, CBAttributePermissions.Readable); var service = new CBMutableService(uuidService, true); service.Characteristics = new CBCharacteristic[] { characteristic }; _peripheralManager.AddService(service); StartAdvertisingOptions advData = new StartAdvertisingOptions { ServicesUUID = new CBUUID[] { uuidService } }; _peripheralManager.StartAdvertising(advData); TracingState.Instance.SetAdvertisingState(true); _enabled = true; _logger.LogDebug("Advertising starting. DeviceId: " + _tracingInformation.DeviceId); }
public void Start(BleDevice device, BleCharacteristic[] characteristics) { string dataServiceUUIDsKey = "71DA3FD1-7E10-41C1-B16F-4430B5060000"; string customBeaconServiceUUIDsKey = "71DA3FD1-7E10-41C1-B16F-4430B5060001"; string customBeaconCharacteristicUUIDKey = "71DA3FD1-7E10-41C1-B16F-4430B5060002"; string identifier = "71DA3FD1-7E10-41C1-B16F-4430B5060003"; peripheralManager = new CBPeripheralManager(this, DispatchQueue.DefaultGlobalQueue); peripheralManager.AdvertisingStarted += (sender, e) => { if (e.Error != null) { System.Diagnostics.Debug.WriteLine(string.Format("*** BleServer -> Advertising error: {0}", e.Error.Description)); } else { System.Diagnostics.Debug.WriteLine("*** BleServer -> We are advertising."); } }; var customBeaconServiceUUID = CBUUID.FromString(customBeaconServiceUUIDsKey); var customBeaconCharacteristicUUID = CBUUID.FromString(customBeaconCharacteristicUUIDKey); var service = new CBMutableService(customBeaconServiceUUID, true); var dataUUID = NSData.FromString(identifier, NSStringEncoding.UTF8); var characteristic = new CBMutableCharacteristic( customBeaconCharacteristicUUID, CBCharacteristicProperties.Read, dataUUID, CBAttributePermissions.Readable); service.Characteristics = new CBCharacteristic[] { characteristic }; peripheralManager.AddService(service); var localName = new NSString("CustomBeacon"); //var advertisingData = new NSDictionary( CBAdvertisement.DataLocalNameKey, localName, // CBAdvertisement.IsConnectable, false, // CBAdvertisement.DataManufacturerDataKey, CBUUID.FromString(dataServiceUUIDsKey), // CBAdvertisement.DataServiceUUIDsKey, CBUUID.FromString(dataServiceUUIDsKey)); //peripheralManager.StartAdvertising(advertisingData); var UUI = new CBUUID[] { CBUUID.FromString("71DA3FD1-7E10-41C1-B16F-4430B5060000") }; NSArray arry = NSArray.FromObjects(UUI); var test = NSObject.FromObject(arry); var ad = new NSDictionary(CBAdvertisement.DataServiceUUIDsKey, test); peripheralManager.StartAdvertising(ad); }
public RemoteXServerForIos() { CBUUID[] cBUUIDs = new CBUUID[1]; CBUUID cBUUID = CBUUID.FromString("AD86E9A5-AB95-4D75-A4BC-2A969F26E028"); cBPeripheralManager = new CBPeripheralManager(); remoteService = new CBMutableService(cBUUID, true); cBPeripheralManager.AddService(remoteService); cBUUIDs.Append(cBUUID); var advertisingOption = new StartAdvertisingOptions { LocalName = "RemoteX Controller" }; advertisingOption.ServicesUUID = cBUUIDs; cBPeripheralManager.StartAdvertising(advertisingOption); }
public void Start_old(BleDevice device, BleCharacteristic[] characteristics) { try { if (device == null) { throw new Exception("Could not initialize server without a service description."); } if ((characteristics == null) || (characteristics.Length == 0)) { throw new Exception("Could not initialize server without characteristic descriptions."); } // setup a peripheral manager _PeripheralManager = new CBPeripheralManager(); var uuid = CBUUID.FromPartial(device.GuidValue); System.Diagnostics.Debug.WriteLine(string.Format("*** BleServer.Start - Device Guid: {0}", uuid.Uuid)); _Service = new CBMutableService(uuid, true); _Characteristics = characteristics.Select(ch => new CBMutableCharacteristic(CBUUID.FromPartial(ch.GuidValue), CBCharacteristicProperties.Read, null, CBAttributePermissions.Readable)).ToList(); _Service.Characteristics = _Characteristics.ToArray(); // register services _PeripheralManager.AddService(_Service); _PeripheralManager.AdvertisingStarted += (sender, e) => { if (e.Error != null) { System.Diagnostics.Debug.WriteLine(string.Format("*** BleServer -> Advertising error: {0}", e.Error.Description)); } else { System.Diagnostics.Debug.WriteLine("*** BleServer -> We are advertising."); } }; // advertise services var opt = new StartAdvertisingOptions(); opt.ServicesUUID = new CBUUID[] { _Service.UUID }; _PeripheralManager.StartAdvertising(opt); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(string.Format("*** BleServer.Start - Exception: {0}", ex)); } }
public override void StateUpdated(CBPeripheralManager peripheral) { if (peripheral.State == CBPeripheralManagerState.PoweredOn && _probe.Running) { try { // if the user powered BLE off/on, the peripheral will already have the service from before (exception will be thrown // on the next line and caught), and the peripheral will already be advertising the service. note that the // CBPeripheralManager.Advertising property will still show false after the user's off/on setting because we haven't // called StartAdvertising ourselves: https://developer.apple.com/documentation/corebluetooth/cbperipheralmanager/1393291-isadvertising peripheral.AddService(_probe.DeviceIdService); } catch (Exception ex) { SensusServiceHelper.Get().Logger.Log("Exception while adding service: " + ex, LoggingLevel.Normal, GetType()); } } }
public void PublishServices(CBPeripheralManager peripheralManager, CBMutableService service) { peripheralManager.AddService(service); }