How to Interface with Windows Universal App ?

Posted on
  • Hi ,
    I 'm going to need some information and want to know if it is feasible to do some extra things.
    I have successfully paired the puck.js with my windows 10 laptop , able to send commands through the Web IDE ...Everything is working fine.
    I have tested also an example from Microsoft with bluetooth devices and Microsoft's example returns the device . some characteristics , gatt etc. All these using C# and universal apps.
    I want to know if it is possible to get readings from puck.js inside a Universal App and displays them there.
    Is it something that it can be done ?
    What code(javascript) do I need to send to the puck device in order to get the readings ? Meaning that I need to check the temperature , if the light is flashing , if the button is pressed ?
    Can I display those reading inside a Universal App using C# ?

    I found the below link
    https://github.com/Microsoft/Windows-uni­versal-samples/tree/master/Samples/Devic­eEnumerationAndPairing
    and some other examples
    https://github.com/Microsoft/Windows-uni­versal-samples/tree/master/Samples/Bluet­oothRfcommChat
    were I can see the Device but I don't know what else do I need to do in the puck.js to transmit all the readings.

    Are this device compatible with the above examples?

    Appreciate your assistance on this.

  • Hi,

    I'd look at this: https://github.com/Microsoft/Windows-uni­versal-samples/tree/master/Samples/Bluet­oothAdvertisement

    Specifically the Advertisement 'watcher'.

    The question then is how you advertise your information for the 'watcher' to see. To start, on your Puck you can run:

    setInterval(function() {
      NRF.setAdvertising({
        0x1809 : [Math.round(E.getTemperature())]
      });
    }, 30000);
    

    Once you disconnect from it, the Puck will start advertising the temperature - which you should be able to read with your app.

    You're quite limited by the amount of data you can send in advertising packets, so I'd consider packing it all together. For example if you upload this:

    var alarm = 0;
    
    
    function updateAdvertising() {
      NRF.setAdvertising({
        0xFFFF : [Math.round(E.getTemperature()), // first byte is temp
                  alarm] // second byte is whether an alarm or not
      });
    }
    
    setWatch(function(e) {
      var t = e.time - e.lastTime;
      if (t>5) {
        // >5 seconds - turn LED off
        LED1.reset();
        digitalPulse(LED2,1,500); // blink green LED to say all ok
        alarm = 0;
      } else {
        // flash red LED
        analogWrite(LED1, 0.01, { freq:0.5, forceSoft:true });
        alarm = 1; 
      }
      updateAdvertising();
    }, BTN, { debounce: 50, edge:"falling", repeat:true});
    
    
    setInterval(function() {
      // update temperature every 30 seconds
      updateAdvertising();
    }, 30000);
    

    Then it'll advertise 2 bytes - the temperature and the 'alarm' - with Bluetooth UUID 0xFFFF.

    When you press the button the alarm will turn to 1 and the red LED will start blinking, or if you hold it for >5 seconds and release the alarm will turn off.

  • Hi Gordon ,
    I will take a look at it and revert .
    Thank you

  • Hi Gordon ,
    I was able to get all the data from puck using the advertising example of Microsoft.
    Microsoft provides a class BluetoothLEManufacturerData were you can get the CompanyId and the data. To make Microsoft's example to work I had to comment all the filters(this class takes filters to limit the bluetooth devices) and that resulted to return me everything..

    https://msdn.microsoft.com/en-us/library­/windows/apps/windows.devices.bluetooth.­advertisement.bluetoothlemanufacturerdat­a?f=255&MSPPError=-2147217396

    The thing is that I want to limit (add filter) the number of devices and read only the puck devices.
    I was wondering how to do that.

    The class has a CompanyID property and the Data. When you put the CompanyID as a filter the watcher reads only this device. Take a look at the below code .

            // Begin of watcher configuration. Configure the advertisement filter to look for the data advertised by the publisher 
            // in Scenario 2 or 4. You need to run Scenario 2 on another Windows platform within proximity of this one for Scenario 1 to 
            // take effect. The APIs shown in this Scenario are designed to operate only if the App is in the foreground. For background
            // watcher operation, please refer to Scenario 3.
    
            // Please comment out this following section (watcher configuration) if you want to remove all filters. By not specifying
            // any filters, all advertisements received will be notified to the App through the event handler. You should comment out the following
            // section if you do not have another Windows platform to run Scenario 2 alongside Scenario 1 or if you want to scan for 
            // all LE advertisements around you.
    
            // For determining the filter restrictions programatically across APIs, use the following properties:
            //      MinSamplingInterval, MaxSamplingInterval, MinOutOfRangeTimeout, MaxOutOfRangeTimeout
    
            // Part 1A: Configuring the advertisement filter to watch for a particular advertisement payload
    
            // First, let create a manufacturer data section we wanted to match for. These are the same as the one 
            // created in Scenario 2 and 4.
            var manufacturerData = new BluetoothLEManufacturerData();
    
            // Then, set the company ID for the manufacturer data. Here we picked an unused value: 0xFFFE
            **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();
            writer.WriteUInt16(0x1234);
    
            // 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 filter on the watcher:
            watcher.AdvertisementFilter.Advertisemen­t.ManufacturerData.Add(manufacturerData)­;
    
    
            // Part 1B: Configuring the signal strength filter for proximity scenarios
    
            // Configure the signal strength filter to only propagate events when in-range
            // Please adjust these values if you cannot receive any advertisement 
            // Set the in-range threshold to -70dBm. This means advertisements with RSSI >= -70dBm 
            // will start to be considered "in-range".
            watcher.SignalStrengthFilter.InRangeThre­sholdInDBm = -70;
    
            // Set the out-of-range threshold to -75dBm (give some buffer). Used in conjunction with OutOfRangeTimeout
            // to determine when an advertisement is no longer considered "in-range"
            watcher.SignalStrengthFilter.OutOfRangeT­hresholdInDBm = -75;
    
            // Set the out-of-range timeout to be 2 seconds. Used in conjunction with OutOfRangeThresholdInDBm
            // to determine when an advertisement is no longer considered "in-range"
            watcher.SignalStrengthFilter.OutOfRangeT­imeout = TimeSpan.FromMilliseconds(2000);
    
            // By default, the sampling interval is set to zero, which means there is no sampling and all
            // the advertisement received is returned in the Received event
    
            // End of watcher configuration. There is no need to comment out any code beyond this point.
    

    The example puts a value manufacturerData.CompanyId = 0xFFFE;
    In our case with the Puck device what should I put in order to tell the watcher to read only the puck.js?
    Is this value changes everytime ?

    Appreciate your guidance on this.

    thank you

  • Can you please point me from the Below list which value should I place ?

    https://www.bluetooth.com/specifications­/assigned-numbers/company-identifiers

  • Hi - as I understand it, no Company ID is specified in the Puck's advertising data. I don't have a unique ID either, as that costs a lot of money.

    Can you not filter advertisements based on advertisement.localName? Just check if the first few characters say 'Puck.js'

  • I wanted to limit the search but if it cannot be done... There is a property which says if it is paired so I can check that .

  • Hi Gordon ,
    From my example app I'm getting this as Data. When I don't press the button
    42-04-01-80-2C-78-BD-BC-0B-BE-66-7A-BD-B­C-0B-BE-65-01-00-00-00-00-00-00

    But if I press it I don't see any change in the transmission.
    I used your Jscript exactly as you send me.
    What "string" should I expect or what will be the exact type of format that I should expect ?
    Remember I'm using C#.
    Please assist.
    thank you

  • And the Puck is flashing the red LED when this is happening?

    I just tried this and if you scan using the nRF Connect app and look at the raw advertising data it says:

    // without alarm
    0x0201050516FFFF10000D095075636B2E6A7320­6333333811079ECADC240EE5A9E093F3A3B50100­406E
    // With alarm
    0x0201050516FFFF10010D095075636B2E6A7320­6333333811079ECADC240EE5A9E093F3A3B50100­406E
    

    So I'm not quite sure what you're seeing in the UWP app, but it doesn't appear to be the advertising data that the Puck is sending (or even some part of it).

    I'd focus on getting your UWP app so that it can report the exact same advertising data that nRF Connect reports.

  • Hi Gordon,
    I have sent you Microsoft's example with some changes I 'm trying to do in order to get the data. It is the UWP and run the First Scenario. When you run the UWP press the run button and you will see the changes I have made in the Scenario1_Watcher.cs file
    This is what I have in UWP.
    Can you please assist to parse puck's data ?
    thank you


    1 Attachment

  • I'm afraid I can't - I spend an awful lot of time supporting Puck.js and developing the firmware and tools for it. I have to draw the line at helping you develop an application on a completely different platform that I have never used before, when I've already written code for you on Puck.js that is working fine.

    Perhaps someone else on here might be able to help? Otherwise stackoverflow.com would probably be a good place to ask. There's already this question and answer that might help: http://stackoverflow.com/questions/41425­293/uwp-ble-advertising-read-data

  • Hi Gordon ,
    I will take a look at it . Thank you

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

How to Interface with Windows Universal App ?

Posted by Avatar for user71866 @user71866

Actions