0

I am trying to make a Bluetooth controlled raspberry pi car. I installed all the modules and packages to get started with Bluetooth. I also wrote a program for the car.

After running the program I get this error:

server_sock =bluetooth.BluetoothSocket(bluetooth.RFCOMM)
AttributeError : 'module' object has no attribute 'BluetoothSocket'

What does this mean?

Do you think I installed the packages incorrectly? Well it gave me errors while installing the packages.

Here is the code

import bluetooth
import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(18,GPIO.OUT)

def Blink(numTimes,speed):
  for i in range(0,numTimes):
    GPIO.output(18,True)
    print "Blinking " + str(i+1)
    time.sleep(speed)
    GPIO.output(18,False)
    time.sleep(speed)
    print ("Done Blinking LED")

server_sock=bluetooth.BluetoothSocket( bluetooth.RFCOMM )

port = 1
server_sock.bind(("",port))
server_sock.listen(1)

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

while True:
  data = client_sock.recv(1024)
  print "received [%s]" % data
  if (data == "1"):
    print ("LED ON")
    GPIO.output(18,GPIO.HIGH)
  if (data == "0"):
    print ("LED OFF")
    GPIO.output(18,GPIO.LOW)
  if (data == "5"):
    print ("LED Blink")
    Blink(10,0.1)
  if (data == "e"):
    print ("Exit")
    break

client_sock.close()
server_sock.close()
1

I'm not allowed to comment yet, so I'm posting this "answer" to ask for clarification. We need more context and source code. BlueZ is very tricky to deal with and makes a huge difference if you're using BlueZ 5 vs BlueZ 4 or older. Also, there's dbus methods and bluetoothctl methods and hciconfig methods of accessing the bluetooth device.

This is a topic that interests me because I am currently working on a project with bluetooth and have dealt with many problems. The method I used is based on the one at http://blog.fraggod.net/2015/03/28/bluetooth-pan-network-setup-with-bluez-5x.html because it worked best.

Your error means that you are attempting to access the "BluetoothSocket" attribute of a "BluetoothSocket" which makes no sense. I can't say more without more context though.

  • Thanks Jon M, Can you also tell me in order what to do to make bluetooth fully functional in the pi , i would really appreciate if u told all the packages to install and pairing and all that, by the way i am using raspberry pi 3 – user117064 Jan 5 '17 at 8:04
  • Thanks Jon M, Can you also tell me in order what to do to make bluetooth fully functional in the pi , i would really appreciate if u told all the packages to install and pairing and all that, by the way i am using raspberry pi 3 – user117064 Jan 5 '17 at 10:56
  • That's a whole subject by itself, and not appropriate for this comment format.. Pair the devices first. You only have to do that once (hopefully). Here's a tutorial: lifehacker.com/… then establish a PAN to network between your Pi and another Bluetooth device. To make your Pi the server, use this tutorial: blog.fraggod.net/2015/03/28/… unless you want a different type of bluetooth connection like serial, A2DP or whatever. That's different. – FlippingBinary Jan 5 '17 at 12:43
  • Thanks Jon , so do u think I won't get that syntax error I got (it's in my question) – user117064 Jan 5 '17 at 15:43
  • I meant won't I get the syntax error after following the likehacker article – user117064 Jan 5 '17 at 15:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.