title: Bluetooth connection between Universal app and medical device - UUID and CODFilter
body: <p>I'm implementing an Universal app on both Windows 8.1 and Windows Phone 8.1 platforms, which should connect with devices like <a href="http://www.andonline.com/medical/products/details.php?%20%20catname=&amp;product_num=UC-351PBT-Ci" rel="nofollow noreferrer">scale</a> or blood pressure monitor by bluetooth technology. Unfortunatelly, I have difficulty in the discovering process and according to that I've no chance to pair and connect to the device.</p>
  
  <p>I've found the <a href="https://stackoverflow.com/questions/5263144/bluetooth-spp-between-android-and-other-device-uuid-and-pin-questions">thread</a> about this issue, but unfortunatelly it's associated with Android.</p>
  
  <p>From the post above: </p>
  
  <blockquote>
    <p><strong>Describing the medical device:</strong> The device is using Service Discovery
    Protocol (SDP) and Serial Port Profile (SPP). It starts an inquiry
    procedure to discover (up to 10) surrounding access points with
    matched COD Filter and Service Name. Then it sequentially establishes
    a connection (using Page Procedure) with the access point by checking
    the PIN. Once the PIN is matched, the data is uploaded. Upon uploading
    data the device waits for an acknowledge. The decice is the master and
    initiates the communication.</p>
  </blockquote>
  
  <p>I've also started from the <a href="http://code.msdn.microsoft.com/wpapps/Bluetooth-Rfcomm-Chat-afcee559" rel="nofollow noreferrer">Microsoft Bluetooth Rfcomm Sample</a>.</p>
  
  <p><strong>My questions:</strong></p>
  
  <ol>
  <li><p>I'm dobious about my standard <strong>UUID</strong> number 00001101-0000-1000-8000-00805F9B34FB. Is it appropriate in this circumstances?</p>
  
  <pre><code>// The Id of the Service Name SDP attribute
  protected const UInt16 SdpServiceNameAttributeId = 0x100;
  
  // The SDP Type of the Service Name SDP attribute.
  // The first byte in the SDP Attribute encodes the SDP Attribute Type as follows :
  //    -  the Attribute Type size in the least significant 3 bits,
  //    -  the SDP Attribute Type value in the most significant 5 bits.
  protected const byte SdpServiceNameAttributeType = (4 &lt;&lt; 3) | 5;
  
  public async Task Start()
  {
      try
      {
          if (rfcommProvider == null)
              rfcommProvider = await RfcommServiceProvider.CreateAsync(
                  RfcommServiceId.FromUuid(BluetoothServiceUuid));
  
          if (rfcommProvider != null)
          {
              if (socketListener != null)
              {
                  socketListener.Dispose();
                  socketListener = null;
              }
  
              // Create a listener for this service and start listening
              socketListener = new StreamSocketListener();
              socketListener.ConnectionReceived += OnConnectionReceived;
  
              await socketListener.BindServiceNameAsync(rfcommProvider.ServiceId.AsString(),
                  SocketProtectionLevel.BluetoothEncryptionAllowNullAuthentication);
  
              // Set the SDP attributes and start Bluetooth advertising
              DataWriter sdpWriter = new DataWriter();
  
              // Write the Service Name Attribute.
              sdpWriter.WriteByte(SdpServiceNameAttributeType);
  
              // The length of the UTF-8 encoded Service Name SDP Attribute.
              sdpWriter.WriteByte((byte)BluetoothServiceDisplayName.Length);
  
              // The UTF-8 encoded Service Name value.
              sdpWriter.UnicodeEncoding = Windows.Storage.Streams.UnicodeEncoding.Utf8;
              sdpWriter.WriteString(BluetoothServiceDisplayName);
  
              // Set the SDP Attribute on the RFCOMM Service Provider.
              if (rfcommProvider.SdpRawAttributes.ContainsKey(SdpServiceNameAttributeId))
                  rfcommProvider.SdpRawAttributes.Remove(SdpServiceNameAttributeId);
              rfcommProvider.SdpRawAttributes.Add(SdpServiceNameAttributeId, sdpWriter.DetachBuffer());
              // Start Bluetooth advertising
              //SetState(BluetoothServerState.Started);
              rfcommProvider.StartAdvertising(socketListener);
          }
      }
      catch (Exception e)
      {
          System.Diagnostics.Debug.WriteLine( "ERROR: " + e.Message);
      }
  }
  </code></pre></li>
  <li><p>I'm not sure if there is a better method to set <strong>Service Name</strong>? Maybe I do this wrong? I think it's a main  problem.</p></li>
  <li><p>What about <strong>COD Filter</strong> (in the specification there is a note that it should equals [00000000] for proper communication? Is there any method to set it using RfcommServiceProvider? Maybe I should also manually set PIN number or if it's required only in the pairing process?</p></li>
  <li><p>I've noticed, in the microsoft samples - Server is only supported for the Windows platform. <strong>It is possible to implement server functionality also for the WP?</strong> - device which will receive data from the medical device should be a slave.</p></li>
  </ol>
  
  <p>I've also read about Gatt protocol but it doesn't provide profiles for all devices which I need.</p>
  
  <p>Thanks in advance for your help.</p>