Пример #1
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            if (this.Frame.CanGoBack)
            {
                SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;
                SystemNavigationManager.GetForCurrentView().BackRequested += Publish_BackRequested;
            }

            this.publisher = new BluetoothLEAdvertisementPublisher();

            ushort id = 0x1234;
            var    manufacturerDataWriter = new DataWriter();

            manufacturerDataWriter.WriteUInt16(id);

            var manufacturerData = new BluetoothLEManufacturerData
            {
                CompanyId = 0xFFFE,
                Data      = manufacturerDataWriter.DetachBuffer()
            };

            publisher.Advertisement.ManufacturerData.Add(manufacturerData);

            this.Manufacturer = "12-34";

            publisher.Start();
        }
Пример #2
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            if (this.Frame.CanGoBack)
            {
                SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;
                SystemNavigationManager.GetForCurrentView().BackRequested += Publish_BackRequested;
            }

            this.publisher = new BluetoothLEAdvertisementPublisher();

            ushort id = 0x1234;
            var manufacturerDataWriter = new DataWriter();
            manufacturerDataWriter.WriteUInt16(id);

            var manufacturerData = new BluetoothLEManufacturerData
            {
                CompanyId = 0xFFFE,
                Data = manufacturerDataWriter.DetachBuffer()
            };

            publisher.Advertisement.ManufacturerData.Add(manufacturerData);

            this.Manufacturer = "12-34";

            publisher.Start();
        }
        /// <summary>
        /// Invoked as an event handler when the Run button is pressed.
        /// </summary>
        /// <param name="sender">Instance that triggered the event.</param>
        /// <param name="e">Event data describing the conditions that led to the event.</param>
        private void RunButton_Click(object sender, RoutedEventArgs e)
        {
            // Calling publisher start will start the advertising if resources are available to do so
            publisher.Start();

            rootPage.NotifyUser("Publisher started.", NotifyType.StatusMessage);
        }
Пример #4
0
    /// <summary>
    /// Start to broadcast a Bluetooth advertisement.
    /// </summary>
    /// <returns></returns>
    public async Task SetupBluetoothAdvertisement()
    {
        var myIpAddress = GetMyIPAddress();

        OutputBluetoothConnectionMessage("Broadcasting from " + myIpAddress);

        this._connectionMadeTask = new TaskCompletionSource <bool>();

        this._socketListener = new StreamSocketListener();
        await this._socketListener.BindEndpointAsync(
            new HostName(myIpAddress), "8000");

        this._socketListener.ConnectionReceived += OnConnectionReceived;

        _publisher = new BluetoothLEAdvertisementPublisher();

        var manufactureData = new BluetoothLEManufacturerData();

        manufactureData.CompanyId = 0xFFFE;

        manufactureData.Data = WriteToBuffer(
            IPAddress.Parse(myIpAddress),
            8000);

        _publisher.Advertisement.ManufacturerData.Add(manufactureData);
        _publisher.Start();

        await Task.WhenAny(this._connectionMadeTask.Task, Task.Delay(-1));
    }
Пример #5
0
        public void PublishInfo()
        {
            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("HeyDude");

            manufacturerData.Data = writer.DetachBuffer();
            publisher.Advertisement.ManufacturerData.Add(manufacturerData);

            // Display the information about the published payload

            myTextBox.Text = string.Format("Published payload information: CompanyId=0x{0}, ManufacturerData=0x{1}",
                                           manufacturerData.CompanyId.ToString("X"),
                                           uuidData.ToString("X"));

            // Display the current status of the publisher
            tbStatus.Text = string.Format("Published Status: {0}, Error: {1}", publisher.Status, BluetoothError.Success);

            publisher.Start();
        }
Пример #6
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);
        }
Пример #7
0
        /// custom advertisements according to:
        /// https://docs.microsoft.com/en-us/uwp/api/windows.devices.bluetooth.advertisement.bluetoothleadvertisementpublisher

        public bool StartAdvertisingCustom(ushort companyid, IBuffer data)
        {
            isCurrentlyStarting = true;
            // Add custom data to the advertisement
            var manufacturerData = new BluetoothLEManufacturerData();

            manufacturerData.CompanyId = companyid; // Apple
            manufacturerData.Data      = data;

            // Clear previous values just in case
            publisher.Advertisement.ManufacturerData.Clear();
            publisher.Advertisement.DataSections.Clear();

            // Add the manufacturer data to the advertisement publisher:
            publisher.Advertisement.ManufacturerData.Add(manufacturerData);
            try
            {
                publisher.Start();
                isCurrentlyStarting = false;
                return(true);
            }
            catch
            {
                System.Diagnostics.Debug.WriteLine("ADVERTISING PUBLISHER EXCEPTION!");
                isCurrentlyStarting = false;
                return(false);
            }
        }
Пример #8
0
        protected void startPublisher(byte[] data)
        {
            BluetoothLEAdvertisement advertisement = new BluetoothLEAdvertisement();

            advertisement.ManufacturerData.Add(new BluetoothLEManufacturerData(COMPANY_ID, CryptographicBuffer.CreateFromByteArray(data)));
            m_publisher = new BluetoothLEAdvertisementPublisher(advertisement);
            m_publisher.StatusChanged += publisherStatusChangeHandler;
            m_publisher.Start();
        }
        //---------------------------------------------------------------------
        // Method to handle if/when the publisher's status changes
        //---------------------------------------------------------------------

        // Event callback for when the status of the publisher changes. This
        // helps keep the publisher going if it is aborted by the system.
        private void OnPublisherStatusChanged(
            BluetoothLEAdvertisementPublisher publisher,
            BluetoothLEAdvertisementPublisherStatusChangedEventArgs eventArgs
            )
        {
            if (eventArgs.Status == BluetoothLEAdvertisementPublisherStatus.Aborted)
            {
                Debug.WriteLine("Advertisemen publisher aborted. Restarting.");
                publisher.Start();
            }
        }
Пример #10
0
        private void PublishiBeacon(byte[] dataArray)
        {
            var manufactureData = new BluetoothLEManufacturerData();

            //0x004C	Apple, Inc.
            manufactureData.CompanyId = 0x004c;
            manufactureData.Data      = dataArray.AsBuffer();
            _blePublisher.Advertisement.ManufacturerData.Add(manufactureData);
            //開始發佈
            _blePublisher.Start();
        }
Пример #11
0
        private void PublishiBeacon(byte[] dataArray)
        {
            var manufactureData = new BluetoothLEManufacturerData();

            //0x004C	Apple, Inc.
            manufactureData.CompanyId = 0x004c;
            //using System.Runtime.InteropServices.WindowsRuntime;
            manufactureData.Data = dataArray.AsBuffer();
            _blePublisher        = new BluetoothLEAdvertisementPublisher();
            _blePublisher.Advertisement.ManufacturerData.Add(manufactureData);
            //開始發佈
            _blePublisher.Start();
        }
Пример #12
0
        public void Emit()
        {
            publisher = new BluetoothLEAdvertisementPublisher();
            var manufacturerData = new BluetoothLEManufacturerData();
            manufacturerData.CompanyId = 0xFFFE;
            var writer = new DataWriter();
            UInt16 uuidData = 0x1234;
            writer.WriteUInt16(uuidData);
            manufacturerData.Data = writer.DetachBuffer();
            publisher.Advertisement.ManufacturerData.Add(manufacturerData);
            publisher.Start();

        }
Пример #13
0
        /// <summary>
        /// Invoked as an event handler when the Run button is pressed.
        /// </summary>
        /// <param name="sender">Instance that triggered the event.</param>
        /// <param name="e">Event data describing the conditions that led to the event.</param>
        private void RunButton_Click(object sender, RoutedEventArgs e)
        {
            // Calling publisher start will start the advertising if resources are available to do so
            string beaconId = listBeacons.SelectedItem as string;

            if (beaconId == "(User-Define)")
            {
                beaconId = txtUserDefinedBeacon.Text;
            }
            publisher_Setup(0xFFFF, beaconId);
            publisher.Start();

            rootPage.NotifyUser("Publisher started.", NotifyType.StatusMessage);
        }
        //---------------------------------------------------------------------
        // Init and ShutDown
        //---------------------------------------------------------------------

        // Initializes the publisher and begins publishing advertisements
        public void Start()
        {
            //
            // Step 1
            // Create the publisher
            //
            publisher = new BluetoothLEAdvertisementPublisher();

            //
            // Step 2
            // Add a payload to the advertisement. It must be less than 20
            // bytes or an exception will occur.
            //
            BluetoothLEManufacturerData manufacturerData = new BluetoothLEManufacturerData();

            // Add a manufacturer ID
            manufacturerData.CompanyId = 0xDEDE;    // Another reference to King DeDeDe

            // Add a string
            DataWriter writer = new DataWriter();

            writer.WriteString("IPv6ToBle");

            manufacturerData.Data = writer.DetachBuffer();

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

            // Register a status changed handler in case something happens to
            // the publisher
            publisher.StatusChanged += OnPublisherStatusChanged;

            // Start the publisher if resources are available to do so. It may
            // take a second to get started. This cannot run if other code is
            // using the Bluetooth radio, such as the GATT server.
            publisher.Start();

            if (publisher.Status == BluetoothLEAdvertisementPublisherStatus.Started)
            {
                Debug.WriteLine("Packet receiver advertisement publisher started.");
            }
            else
            {
                Debug.WriteLine("An error occurred when starting the advertisement" +
                                "publisher. Status: " + publisher.Status.ToString()
                                );
            }
        }
        public void publish()
        {
            // Add custom data to the advertisement
            var manufacturerData = new BluetoothLEManufacturerData();
            manufacturerData.CompanyId = 0xFFFE;

            var writer = new DataWriter();
            writer.WriteString("Hello World");

            // Make sure that the buffer length can fit within an advertisement payload (~20 bytes). 
            // 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();
            Debug.WriteLine("Publisher started");
        }
Пример #16
0
        static void Main(string[] args)
        {
            BluetoothLEAdvertisementPublisher publisher = new BluetoothLEAdvertisementPublisher();

            var manufacturerData = new BluetoothLEManufacturerData();

            manufacturerData.CompanyId = 0xFFFE;

            var writer = new DataWriter();

            writer.WriteString("f**k you blair");

            manufacturerData.Data = writer.DetachBuffer();

            publisher.Advertisement.ManufacturerData.Add(manufacturerData);

            publisher.Start();

            BluetoothLEAdvertisementWatcher xwatcher = new BluetoothLEAdvertisementWatcher();
            var filter = new BluetoothLEManufacturerData();

            filter.CompanyId = 0xFFFE;
            xwatcher.AdvertisementFilter.Advertisement.ManufacturerData.Add(filter);
            xwatcher.Received += OnAdvertisementReceived;
            xwatcher.Start();

            async void OnAdvertisementReceived(BluetoothLEAdvertisementWatcher watcher, BluetoothLEAdvertisementReceivedEventArgs eventArgs)
            {
                foreach (var arg in eventArgs.Advertisement.ManufacturerData)
                {
                    var data = new byte[arg.Data.Length];
                    using (var reader = DataReader.FromBuffer(arg.Data))
                    {
                        reader.ReadBytes(data);
                    }
                    var str = Encoding.ASCII.GetString(data);
                    Console.WriteLine(str);
                }
            }

            Console.ReadLine();
        }
Пример #17
0
        private void BeaconPublishButton_Click(object sender, RoutedEventArgs e)
        {
            _publisher = new BluetoothLEAdvertisementPublisher();

            // Manufacturer specific data to customize
            var          writer   = new DataWriter();
            const ushort uuidData = 0x1234; // Custom payload

            writer.WriteUInt16(uuidData);
            var manufacturerData = new BluetoothLEManufacturerData
            {
                CompanyId = 0xFFFE,         // Custom manufacturer
                Data      = writer.DetachBuffer()
            };

            _publisher.Advertisement.ManufacturerData.Add(manufacturerData);

            // Start publishing
            _publisher.Start();
            SetStatusOutput("Publishing Bluetooth Beacon");
        }
Пример #18
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            var manufacturerData =
                new BluetoothLEManufacturerData();

            var writer = new DataWriter();

            writer.WriteString("Buy our socks for a dollar");
            manufacturerData.CompanyId = 0xFFFE;
            manufacturerData.Data      = writer.DetachBuffer();

            publisher =
                new BluetoothLEAdvertisementPublisher();

            publisher.Advertisement.ManufacturerData.Add(manufacturerData);
            publisher.StatusChanged += Publisher_StatusChanged;

            publisher.Start();

            base.OnNavigatedTo(e);
        }
Пример #19
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();
            }
        }
Пример #20
0
        /// <summary>
        /// Starts advertizing based on the set values (beacon ID 1, ID 2 and ID 3).
        /// Note that this method does not validate the values and will throw exception, if the
        /// values are invalid.
        /// </summary>
        public void Start()
        {
            if (!IsStarted)
            {
                _beacon                = new Beacon();
                _beacon.Id1            = BeaconId1;
                _beacon.ManufacturerId = ManufacturerId;
                _beacon.Code           = BeaconCode;
                _beacon.Id2            = BeaconId2;
                _beacon.Id3            = BeaconId3;
                _beacon.MeasuredPower  = DefaultMeasuredPower;

                _advertisementPublisher = new BluetoothLEAdvertisementPublisher();

                BluetoothLEAdvertisementDataSection dataSection = BeaconFactory.BeaconToSecondDataSection(_beacon);
                Logger.Debug("Advertiser.Start(): " + BeaconFactory.DataSectionToRawString(dataSection));
                _advertisementPublisher.Advertisement.DataSections.Add(dataSection);
                _advertisementPublisher.Start();

                IsStarted = true;
            }
        }
Пример #21
0
        static void Main(string[] args)
        {
            var waiter = new EventWaitHandle(false, EventResetMode.ManualReset);

            var writer = new DataWriter();

            writer.WriteInt32(Constants.PAYLOAD.Length);
            writer.WriteString(Constants.PAYLOAD);

            var manufacturerData = new BluetoothLEManufacturerData();

            manufacturerData.CompanyId = Constants.MS_ID;
            manufacturerData.Data      = writer.DetachBuffer();

            var publisher = new BluetoothLEAdvertisementPublisher();

            publisher.Advertisement.ManufacturerData.Add(manufacturerData);
            publisher.StatusChanged += Publisher_StatusChanged;
            publisher.Start();

            waiter.WaitOne();
        }
Пример #22
0
        /// <summary>
        /// Starts advertizing based on the set values (beacon ID 1, ID 2 and ID 3).
        /// Note that this method does not validate the values and will throw exception, if the
        /// values are invalid.
        /// </summary>
        public void Start()
        {
            if (!IsStarted)
            {
                _beacon = new Beacon();
                _beacon.Id1 = BeaconId1;
                _beacon.ManufacturerId = ManufacturerId;
                _beacon.Code = BeaconCode;
                _beacon.Id2 = BeaconId2;
                _beacon.Id3 = BeaconId3;
                _beacon.MeasuredPower = DefaultMeasuredPower;

                _advertisementPublisher = new BluetoothLEAdvertisementPublisher();

                BluetoothLEAdvertisementDataSection dataSection = BeaconFactory.BeaconToSecondDataSection(_beacon);
                Logger.Debug("Advertiser.Start(): " + BeaconFactory.DataSectionToRawString(dataSection));
                _advertisementPublisher.Advertisement.DataSections.Add(dataSection);
                _advertisementPublisher.Start();

                IsStarted = true;
            }
        }
        /// <summary>
        /// iBeacon発信開始処理(UUID、Major、Minorを直指定して発信)
        /// </summary>
        /// <param name="uuid">UUID</param>
        /// <param name="major">Major</param>
        /// <param name="minor">Minor</param>
        public void StartTransmission(Guid uuid, ushort major, ushort minor, sbyte txPower)
        {
            // BLE発信用のデータを格納する箱を作成
            BluetoothLEManufacturerData bleManufacturerData = new BluetoothLEManufacturerData()
            {
                CompanyId = Const.COMPANY_CODE_APPLE
            };

            // データを格納できるようにするため、UUID、Major、Minor、TxPowerをbyteに変換する。
            // TxPowerはオフセットをかけてから変換する。
            byte[] uuidByteArray  = uuid.ToByteArray();
            byte[] majorByteArray = BitConverter.GetBytes(major);
            byte[] minorByteArray = BitConverter.GetBytes(minor);
            byte   txPowerByte    = (byte)((int)txPower + 256);

            // UUID、Major、Minorを、iBeaconのフォーマットに準拠する形に梱包する。
            byte[] ibeaconAdvertisementDataArray = new byte[]
            {
                // iBeaconと識別するための固定値
                0x02, 0x15,
                // UUID
                uuidByteArray[0], uuidByteArray[1], uuidByteArray[2], uuidByteArray[3],
                uuidByteArray[4], uuidByteArray[5], uuidByteArray[6], uuidByteArray[7],
                uuidByteArray[8], uuidByteArray[9], uuidByteArray[10], uuidByteArray[11],
                uuidByteArray[12], uuidByteArray[13], uuidByteArray[14], uuidByteArray[15],
                // Major
                majorByteArray[0], majorByteArray[1],
                // Minor
                minorByteArray[0], minorByteArray[1],
                // TxPower
                txPowerByte
            };

            // データをBLEで発信する。
            bleManufacturerData.Data = ibeaconAdvertisementDataArray.AsBuffer();
            blePublisher.Advertisement.ManufacturerData.Add(bleManufacturerData);
            blePublisher.Start();
        }
Пример #24
0
        private void StartBroadcasting()
        {
            // Setup publisher
            publisher = new BluetoothLEAdvertisementPublisher();
            publisher.StatusChanged += Publisher_StatusChanged;

            // Get the payload
            byte[] payload = CreatePayload();

            // Format the payload and add a company id (must be set to Apple's id for iBeacons)
            var data = new BluetoothLEManufacturerData();

            data.CompanyId = 0x004c; // This is Apple's company id. It must be set for all iBeacons.
            data.Data      = payload.AsBuffer();

            // Send the data to the publisher and start publishing.
            publisher.Advertisement.ManufacturerData.Add(data);
            publisher.Start();

            // Display in UI
            UUID.Text  = $"UUID: {UUID_Val.ToString()}";
            Major.Text = $"Major: {MajorKey}";
            Minor.Text = $"Minor: {MinorKey}";
        }
        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();
        }
Пример #26
0
 public void Start()
 {
     IsReady = false;
     publisher.Start();
 }
Пример #27
0
        public void execute_Click(object sender, EventArgs e) //it's time.
        {
            //begin construction for advert
            BluetoothLEAdvertisementPublisher publisher = new BluetoothLEAdvertisementPublisher();

            //create/set manufacturer ID
            var manufacturerData = new BluetoothLEManufacturerData();

            manufacturerData.CompanyId = 0x004c; //apple inc's company data

            if (major.Text == string.Empty || minor.Text == string.Empty || uuid.Text == string.Empty)
            {
                MessageBox.Show("ur autistic, put some values in.");
                return;
            }

            //process our user input data
            var    majorhex = Convert.ToInt32(major.Text).ToString("X").PadLeft(4, '0');
            var    minorhex = Convert.ToInt32(minor.Text).ToString("X").PadLeft(4, '0');
            string maj1     = Convert.ToString(majorhex[0]) + majorhex[1];
            string maj2     = Convert.ToString(majorhex[2]) + majorhex[3];
            string min1     = Convert.ToString(minorhex[0]) + minorhex[1];
            string min2     = Convert.ToString(minorhex[2]) + minorhex[3];

            string[] hold = uuid.Text.Split(' ');

            // Create the payload
            //harrison004: f0207da6-4fa2-4e98-8024-bc5b71e0893e  |  6  |  11
            // f0 20 7d a6 4f a2 4e 98 80 24 bc 5b 71 e0 89 3e

            //harrison 209
            // f0 20 7d a6 4f a2 4e 98 80 24 bc 5b 71 e0 89 3e  |  6  |  179
            var writer = new DataWriter();

            byte[] dataArray = new byte[23];
            int    i         = 2;

            dataArray[0] = byte.Parse("02", System.Globalization.NumberStyles.AllowHexSpecifier);
            dataArray[1] = byte.Parse("15", System.Globalization.NumberStyles.AllowHexSpecifier);
            foreach (string item in hold)
            {
                dataArray[i++] = byte.Parse(item, System.Globalization.NumberStyles.AllowHexSpecifier);
            }
            dataArray[18] = byte.Parse(maj1, System.Globalization.NumberStyles.AllowHexSpecifier);
            dataArray[19] = byte.Parse(maj2, System.Globalization.NumberStyles.AllowHexSpecifier);
            dataArray[20] = byte.Parse(min1, System.Globalization.NumberStyles.AllowHexSpecifier);
            dataArray[21] = byte.Parse(min2, System.Globalization.NumberStyles.AllowHexSpecifier);
            dataArray[22] = byte.Parse("B3", System.Globalization.NumberStyles.AllowHexSpecifier);

            /*
             * byte[] dataArray = new byte[] {
             *  // last 2 bytes of Apple's iBeacon
             *  0x02, 0x15,
             *  // UUID e2 c5 6d b5 df fb 48 d2 b0 60 d0 f5 a7 10 96 e0
             *  0xf0, 0x20, 0x7d, 0xa6,
             *  0x4f, 0xa2, 0x4e, 0x98,
             *  0x80, 0x24, 0xbc, 0x5b,
             *  0x71, 0xe0, 0x89, 0x3e,
             *  // Major
             *  0x00, 0x06,
             *  // Minor
             *  0x00, 0x0B,
             *  // TX power
             *  0xc5
             * };
             */

            writer.WriteBytes(dataArray);

            manufacturerData.Data = writer.DetachBuffer();
            publisher.Advertisement.ManufacturerData.Add(manufacturerData);


            publisher.Start(); //begin the spoof ;)

            indicator.ForeColor = Color.Green;
        }
 public void StartAdvertising()
 {
     _publisher.Start();
 }
Пример #29
0
        private void BeaconPublishButton_Click(object sender, RoutedEventArgs e)
        {
            _publisher = new BluetoothLEAdvertisementPublisher();

            // Manufacturer specific data to customize
            var writer = new DataWriter();
            const ushort uuidData = 0x1234; // Custom payload
            writer.WriteUInt16(uuidData);
            var manufacturerData = new BluetoothLEManufacturerData
            {
                CompanyId = 0xFFFE,         // Custom manufacturer
                Data = writer.DetachBuffer()
            };
            _publisher.Advertisement.ManufacturerData.Add(manufacturerData);

            // Start publishing
            _publisher.Start();
            SetStatusOutput("Publishing Bluetooth Beacon");
        }