2

I am trying an example code in python which works as a bluetooth server. This code gives following error..

Traceback (most recent call last): File "/var/lib/cloud9/examples/Sa/rfcomm-server_py", line 7, in from bluetooth import * File "/var/lib/cloud9/examples/Sa/bluetooth/init.py", line 43, in from .bluez import * File "/var/lib/cloud9/examples/Sa/bluetooth/bluez.py", line 6, in import _bluetooth as _bt ImportError: No module named _bluetooth

I am using beaglebone green wireless board in cloud9 IDE

    # file: rfcomm-server.py
    # auth: Albert Huang <albert@csail.mit.edu>
    # desc: simple demonstration of a server application that uses RFCOMM   sockets
    # $Id: rfcomm-server.py 518 2007-08-10 07:20:07Z albert $

   from bluetooth import *

   server_sock=BluetoothSocket( RFCOMM )
   server_sock.bind(("",PORT_ANY))
   server_sock.listen(1)

   port = server_sock.getsockname()[1]

   uuid = "94f39d29-7d6d-437d-973b-fba39e49d4ee"

   advertise_service( server_sock, "SampleServer",
               service_id = uuid,
               service_classes = [ uuid, SERIAL_PORT_CLASS ],
               profiles = [ SERIAL_PORT_PROFILE ], 
 #                   protocols = [ OBEX_UUID ] 
                )

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

  client_sock, client_info = server_sock.accept()
  print("Accepted connection from ", client_info)

 try:
 while True:
    data = client_sock.recv(1024)
    if len(data) == 0: break
    print("received [%s]" % data)
 except IOError:
  pass

  print("disconnected")

 client_sock.close()
  server_sock.close()
   print("all done")
sachith
  • 129
  • 2
  • 12

1 Answers1

1

I didn't turn on the bluetooth on Beaglebone green wireless board, but after running the following command, the code above worked perfectly:

$ bb-wl18xx-bluetooth
Brady Dowling
  • 4,920
  • 3
  • 32
  • 62
sachith
  • 129
  • 2
  • 12