protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
        {
            if (watcher != null)
            {
                watcher.Stop();
            }

            if (publisher != null)
            {
                publisher.Stop();
            }
        }
        /// <summary>
        /// Invoked immediately before the Page is unloaded and is no longer the current source of a parent Frame.
        /// </summary>
        /// <param name="e">
        /// Event data that can be examined by overriding code. The event data is representative
        /// of the navigation that will unload the current Page unless canceled. The
        /// navigation can potentially be canceled by setting Cancel.
        /// </param>
        protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
        {
            // Remove local suspension handlers from the App since this page is no longer active.
            App.Current.Suspending -= App_Suspending;
            App.Current.Resuming   -= App_Resuming;

            // Make sure to stop the publisher when leaving the context. Even if the publisher is not stopped,
            // advertising will be stopped automatically if the publisher is destroyed.
            publisher.Stop();
            // Always unregister the handlers to release the resources to prevent leaks.
            publisher.StatusChanged -= OnPublisherStatusChanged;

            rootPage.NotifyUser("Navigating away. Publisher stopped.", NotifyType.StatusMessage);
            base.OnNavigatingFrom(e);
        }
Beispiel #3
0
        private async Task <bool> SendCustomizedMessage(int msec, string message)
        {
            BluetoothLEAdvertisementPublisher publisher = new BluetoothLEAdvertisementPublisher();
            var manufacturerData = new BluetoothLEManufacturerData();

            // Then, set the company ID for the manufacturer data. Here we picked an unused value: 0xFFFE
            manufacturerData.CompanyId = 0xFFFF;

            // Finally set the data payload within the manufacturer-specific section
            // Here, use a 16-bit UUID: 0x1234 -> {0x34, 0x12} (little-endian)
            var writer = new DataWriter();
            //UInt16 uuidData = 0x1234;
            //writer.WriteUInt16(uuidData);
            string deviceData = message;

            writer.UnicodeEncoding = UnicodeEncoding.Utf8;
            writer.WriteString(deviceData);

            // Make sure that the buffer length can fit within an advertisement payload. Otherwise you will get an exception.
            manufacturerData.Data = writer.DetachBuffer();

            // Add the manufacturer data to the advertisement publisher:
            publisher.Advertisement.ManufacturerData.Add(manufacturerData);

            publisher.Start();
            await Task.Delay(msec);

            publisher.Stop();
            return(true);
        }
        // Stops publishing advertisements
        public void Stop()
        {
            // Stop the publisher
            publisher.Stop();

            // Unregister the event handler to prevent resource leaks
            publisher.StatusChanged -= OnPublisherStatusChanged;
        }
Beispiel #5
0
 public void stopMeting()
 {
     if (publisher.Status != BluetoothLEAdvertisementPublisherStatus.Stopped)
     {
         publisher.Stop();
         Debug.WriteLine("Publisher status: " + publisher.Status);
     }
 }
Beispiel #6
0
        protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
        {
            if (this.Frame.CanGoBack)
            {
                SystemNavigationManager.GetForCurrentView().BackRequested -= Publish_BackRequested;
            }

            publisher.Stop();
        }
Beispiel #7
0
        public bool StopAdvertisingCustom()
        {
            if (publisher.Status != BluetoothLEAdvertisementPublisherStatus.Stopped)
            {
                publisher.Stop();
                return(true);
            }

            return(false);
        }
Beispiel #8
0
 public void Stop()
 {
     if (IsStarted)
     {
         _advertisementPublisher.Stop();
         _advertisementPublisher = null;
         IsStarted = false;
     }
     Logger.Debug("Advertiser.Stoped");
 }
Beispiel #9
0
        private void App_Suspending(object sender, Windows.ApplicationModel.SuspendingEventArgs e)
        {
            watcher.Stop();
            publisher.Stop();

            watcher.Received -= Watcher_Received;
            watcher.Stopped  -= Watcher_Stopped;

            publisher.StatusChanged -= Publisher_StatusChanged;
        }
Beispiel #10
0
        protected void stopPublisher()
        {
            if (null == m_publisher)
            {
                m_logger.WriteLine("Publisher is not active");
                return;
            }

            m_publisher.Stop();
            m_publisher.StatusChanged -= publisherStatusChangeHandler; // unregister handler
            m_publisher = null;
        }
Beispiel #11
0
        private async void OnTogglePublisherButtonClickedAsync(object sender, RoutedEventArgs e)
        {
            if (_bluetoothLEAdvertisementPublisher.Status != BluetoothLEAdvertisementPublisherStatus.Started)
            {
                Beacon beacon = new Beacon();
                beacon.ManufacturerId = ManufacturerId;
                beacon.Code           = BeaconCode;
                beacon.Id1            = BeaconId1;

                try
                {
                    beacon.Id2 = UInt16.Parse(BeaconId2);
                    beacon.Id3 = UInt16.Parse(BeaconId3);
                }
                catch (Exception)
                {
                }

                beacon.MeasuredPower = -58;

                System.Diagnostics.Debug.WriteLine("Will try to advertise as beacon " + beacon.ToString());

                BluetoothLEAdvertisementDataSection dataSection = BeaconFactory.BeaconToSecondDataSection(beacon);
                _bluetoothLEAdvertisementPublisher.Advertisement.DataSections.Add(dataSection);

                try
                {
                    _bluetoothLEAdvertisementPublisher.Start();
                }
                catch (Exception ex)
                {
                    MessageDialog messageDialog = new MessageDialog("Failed to start Bluetooth LE Advertisement Publisher: " + ex.Message);
                    await messageDialog.ShowAsync();
                }
            }
            else
            {
                _bluetoothLEAdvertisementPublisher.Stop();
            }
        }
        private async Task DoBTStuff(string t)
        {
            BluetoothLEAdvertisementPublisher publisher = new BluetoothLEAdvertisementPublisher();
            //var manufacturerData = new BluetoothLEManufacturerData();
            //manufacturerData.CompanyId = 0xFFFE;
            //var writer = new DataWriter();
            //writer.WriteString($"Message sent: {t} ");
            //manufacturerData.Data = writer.DetachBuffer();
            //publisher.Advertisement.ManufacturerData.Add(manufacturerData);
            //publisher.Start();
            //await Task.Delay(500);
            //await SendProgressState(3);
            //publisher.Stop();


            var manufacturerData = new BluetoothLEManufacturerData();

            manufacturerData.CompanyId = 0xFFFE;

            // Finally set the data payload within the manufacturer-specific section
            // Here, use a 16-bit UUID: 0x1234 -> {0x34, 0x12} (little-endian)
            var    writer   = new DataWriter();
            UInt16 uuidData = 0x1234;

            writer.WriteUInt16(uuidData);
            writer.WriteString("Beacon from Cortana");

            manufacturerData.Data = writer.DetachBuffer();
            publisher.Advertisement.ManufacturerData.Add(manufacturerData);
            publisher.Start();
            await Task.Delay(3000);

            await SendProgressState(3);

            publisher.Stop();
        }
 public void StopAdvertising()
 {
     _publisher.Stop();
 }
 /// <summary>
 /// iBeaconの発信を停止する処理
 /// </summary>
 public void StopTransmission()
 {
     blePublisher.Stop();
 }
Beispiel #15
0
 private void StopBroadcasting()
 {
     publisher.Stop();
 }
Beispiel #16
0
 protected override void OnNavigatedFrom(NavigationEventArgs e)
 {
     publisher.StatusChanged -= Publisher_StatusChanged;
     publisher.Stop();
     base.OnNavigatedFrom(e);
 }
Beispiel #17
0
 public void Stop()
 {
     IsReady = false;
     publisher.Stop();
 }