3 Replies Latest reply on Aug 9, 2016 8:04 AM by rbulha

    rfcomm-server using python on edison



      I am trying to implement a python script that would be the server of my bluetooth connection and my android app connects to it. Everything seems to be ok in the code, but i always get some errors whenever i try to run it via terminal on my edison. this is the code:


      from bluetooth import *


      #allocate a socket

      server_sock = BluetoothSocket( RFCOMM )


      #bind socket to port 1 of the first available



      #put socket into listening mode


      print "listening for connection on port!"                #"listening on port %d" % port


      port = server_sock.getsockname()[1]

      uuid = "00001101-0000-1000-8000-00805F9B34FB"


      #Advertise SP service

      advertise_service( server_sock, "SampleServer",

                          service_id = uuid,

                          #service_classes = [SERIAL_PORT_CLASS],

                          #profiles = SERIAL_PORT_PROFILE


      print "Waiting for connection on RFCOMM channel %d" % port


      #Returns socket and address/port of the client.

      client_sock, client_address = server_sock.accept()

      print "Accepted connection from ", client_address



          while True:

              data = client_sock.recv(1024)

              if len(data) == 0: break

              print "received [%s]" % data

      except IOError:



      print "disconnected!"



      print "all done!"


      And this is the error i get:


      Traceback (most recent call last):

        File "rfcomm-server.py", line 18, in <module>

          service_id = uuid,

        File "/usr/lib/python2.7/site-packages/bluetooth/bluez.py", line 176, in advertise_service

          raise BluetoothError (str (e))

      bluetooth.btcommon.BluetoothError: (2, 'No such file or directory')

      Please can someone help me out, as i am just learning python!!


        • 1. Re: rfcomm-server using python on edison

          Hello Michael27,


          I was checking the error you were getting and I decided to look for the bluez.py file. However I discovered that the Bluetooth library was not present in my Edison. So, I believe this issue may be related to that library, I'd suggest you to check this file and to look for the meaning of the BluetoothError (str (e)) flag. I mean this issue could be caused by several reasons, like some file of the library may be corrupted or you could have forgotten to unblock the Edison's Bluetooth before trying this script so that when it tries to access Bluetooth, the antenna is not available.



          • 2. Re: rfcomm-server using python on edison

            Hi Peter,

            Have you installed pyBluez? You'd have to instal it to find the bluez.py file. This is the path to mine, "/usr/lib/python2.7/site-packages/bluetooth/bluez.py". I have done all the checks, and bluetooth is enabled and available but there isnt any luck. How ever i have tried same script on a windows PC and it worked fine. I dont know if there is compatibility issues involved...

            • 3. Re: rfcomm-server using python on edison

              Just to help someone with the same issue. I solved the problem by doing this (run the Bluetooth daemon in 'compatibility' mode)


              Edit this file:


              vi /lib/systemd/system/bluetooth.service


              Add -C after "bluetooth"



              Description=Bluetooth service







              ExecStart=/usr/lib/bluez5/bluetooth/bluetoothd -E -C




              CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE







              Then reboot the system.


              To verify if the the service is running you can type the command:


              sdptool browse local

              1 of 1 people found this helpful