title: bluetooth error no advertisable device
body: <pre><code>#! /usr/bin/python
  
  import bluetooth
  import uuid
  
  server_socket = bluetooth.BluetoothSocket( bluetooth.RFCOMM )
  
  port = 1
  server_socket.bind(("",port))
  server_socket.listen(1)
  
  uuID = ##generated uuid
  
  bluetooth.advertise_service( server_socket, "test", service_id=uuID )
  
  client_socket, client_address = server_socket.accept()
  print(client_socket)
  print(client_address)
  </code></pre>
  
  <p>If anyone could help with this, that would be great.  I've tried going through the instructions listed here about 5 times: <a href="https://stackoverflow.com/questions/33110992/python-code-for-bluetooth-throws-error-after-i-had-to-reset-the-adapter">Python code for Bluetooth throws error after I had to reset the adapter</a></p>
  
  <p>I keep getting an error saying "bluetooth.btcommon.BluetoothError: error no advertisable device"  The line number points to the advertise_service line, and it does so whether or not I add the additional parameters as shown in the example in the pybluez github page, or bind the port to bluetooth.PORT_ANY
  The method being called is here:</p>
  
  <pre><code>def advertise_service (sock, name, service_id = "", service_classes = [], \
          profiles = [], provider = "", description = "", protocols = []):
      if service_id != "" and not is_valid_uuid (service_id):
           raise ValueError ("invalid UUID specified for service_id")
      for uuid in service_classes:
          if not is_valid_uuid (uuid):
              raise ValueError ("invalid UUID specified in service_classes")
      for uuid, version in profiles:
          if not is_valid_uuid (uuid) or  version &lt; 0 or  version &gt; 0xFFFF:
              raise ValueError ("Invalid Profile Descriptor")
      for uuid in protocols:
          if not is_valid_uuid (uuid):
              raise ValueError ("invalid UUID specified in protocols")        
  
      try:
          _bt.sdp_advertise_service (sock._sock, name, service_id, \
                  service_classes, profiles, provider, description, \
                  protocols)
      except _bt.error as e:
          raise BluetoothError (str (e))
  </code></pre>
  
  <p>I'm can't print off the client information if I don't advertise, and get a null pointer exception on the android side, so I figure it's necessary, but can't get past this error if I do advertise.
  This is the smallest amount of code I can have to get this error.  Like I mentioned, not advertising results in no error, but I can't print off client information on the connect (the android side can't find the pi).</p>
  
  <p>If you do know of a way to do this without that portion, here's the android code:</p>
  
  <pre><code>    Set&lt;BluetoothDevice&gt; pairedDevices = BTAdapter.getBondedDevices();
              TextView textShowConnected = (TextView) findViewById(R.id.textShowConnected);
              if (pairedDevices.size() &gt; 0) 
              {
                  for (BluetoothDevice device : pairedDevices) 
                  {
                      if(device.getName().toString().equals("Pi"))
                      {
                          textShowConnected.setText("Found the Pi.  Address is "+device.getAddress());
                          TextView textShowConnectedSocket = (TextView) findViewById(R.id.textShowConnectedSocket);
                          //textShowConnectedSocket.setText("uuid is: "+device.getUuids()[0].getUuid().toString());
                          try 
                          {
                              BluetoothSocket connection = device.createRfcommSocketToServiceRecord(device.getUuids()[0].getUuid());
                              //BluetoothSocket connection = device.createInsecureRfcommSocketToServiceRecord(device.getUuids()[0].getUuid());
                              connection.connect();
                              if(connection.isConnected())
                              {
                                  textShowConnected.setText("Is connected from second.");
                                  textShowConnectedSocket.setText("Is conencted to: "+connection.getRemoteDevice().getName().toString());
                                  textShowPlace.setText("Is connected to: "+connection.getRemoteDevice().getAddress().toString());
                              }
                              else
                              {
                                  textShowConnected.setText("No connection.");
                                  textShowConnectedSocket.setText("No connection.");
                                  textShowPlace.setText("No connection.");
                              }
                          } 
                          catch (IOException e) 
                          {
                              e.printStackTrace();
                          }
                      }
                      //DeviceItem newDevice = new DeviceItem(device.getName(), device.getAddress(), "false");
                      //deviceItemList.add(newDevice);
                  }
              }
          }
  </code></pre>
  
  <p>My most recent Java side attempt (just in case the pi side was fine):</p>
  
  <pre><code>for (BluetoothDevice device : pairedDevices) 
  {
      if(device.getName().toString().equals("Pi"))
      {
          textShowConnected.setText("Found the Pi.  Address is "+device.getAddress());
          TextView textShowConnectedSocket = (TextView) findViewById(R.id.textShowConnectedSocket);
          TextView textShowPlace = (TextView) findViewById(R.id.textShowPlace);
          //textShowConnectedSocket.setText("uuid is: "+device.getUuids()[0].getUuid().toString());
          int bt_port_to_connect = 1;
          BluetoothSocket deviceSocket = null;
          Method m = null;
          try {
              textShowPlace.setText("created socket");
              m = device.getClass().getMethod("createInsecureRfcommSocket", new Class[] {int.class});
              deviceSocket = (BluetoothSocket) m.invoke(device,bt_port_to_connect);
              deviceSocket.connect();
              if(deviceSocket.isConnected()) 
              {
                  textShowPlace.setText("is connected");
                  textShowConnectedSocket.setText("Connected successfully.");
                  textShowConnected.setText("Connected to: "+deviceSocket.getRemoteDevice().getName().toString());
              }
              else
              {
                  textShowConnectedSocket.setText("Did not connect.");
              }
          } 
          catch (IOException e) 
          {
              textShowPlace.setText("catch statement "+e);
              textShowConnectedSocket.setText("No connection.");
          } 
          catch (NoSuchMethodException e) 
          {
              textShowConnected.setText("No such method.");
              textShowPlace.setText("catch statement "+e);
          } 
          catch (InvocationTargetException e) 
          {
              textShowPlace.setText("catch statement "+e);
              textShowConnectedSocket.setText("No connection.");
          } 
          catch (IllegalAccessException e) 
          {
              textShowPlace.setText("catch statement "+e);
              textShowConnectedSocket.setText("No connection.");
          }
          //device.createRfcommSocketToServiceRecord(uuid);                                                                            
          //device.createInsecureRfcommSocketToServiceRecord(uuid);
      }
      //DeviceItem newDevice = new DeviceItem(device.getName(), device.getAddress(), "false");
      //deviceItemList.add(newDevice);
  }
  </code></pre>
  
  <p>I'd appreciate any help on this with getting a connection going.  I'm not sure what's getting messed up here.</p>