Xamarin.forms ACR plugin.Bluetoothle notify issue

harsha87harsha87 Member

Hi,

I am using Xamarin.forms to develop Bluetooth peripheral application which should support both iOS and Android platforms. In that when I try to test the notify property, it is continuously notifying same data. How can I notify only when the data is different ? If anyone has sample code to implement the same please share. Below is the code I am using.

Thanks in advance,

reg_notifyCharacteristic = reg_service.AddCharacteristic(Guid.Parse(REGISTER_CHARACTERISTIC_UUID), CharacteristicProperties.Notify, GattPermissions.Read);

reg_notifyCharacteristic.WhenDeviceSubscriptionChanged().Subscribe(d =>
                            {
                                var @event = d.IsSubscribed ? "Subscribed" : "Unsubcribed";
                                this.OnEvent($"Device {d.Device.Uuid} {@event}");
                                this.OnEvent($"Charcteristic Subcribers: {reg_notifyCharacteristic.SubscribedDevices.Count}");
                                var isSubscribed = d.IsSubscribed ? "Subscribed" : "Unsubcribed";
                                if (notifyBroadcast == null)
                                {
                                    notifyBroadcast = Observable
                                                    .Interval(TimeSpan.FromSeconds(1))
                                                    .Where(x => reg_notifyCharacteristic.SubscribedDevices.Count > 0)
                                                    .Subscribe(a =>
                                                    {
                                                        if (true)
                                                        {
                                                            var isSubscribed = d.IsSubscribed ? "Subscribed" : "Unsubcribed";

                                                            Debug.WriteLine("Sending Broadcast");

                                                            var bytes = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };

                                                            reg_notifyCharacteristic.Broadcast(bytes);
                                                        }

                                                    });
                                }
                          });
Sign In or Register to comment.