Bluetooth on raspi with python
sudo apt-get install --no-install-recommends bluetooth
sudo service bluetooth status
sudo apt-get install bluetooth bluez-utils
sudo apt-get install python-bluez
My bluetooth was HC-06 (slave only) and connected to Raspi over GPIO.This is a serial to Bluetooth device so we need serial communication on raspi.
Install pyserial - sudo apt-get install python-serial
On raspi the HC-06 bluetooth module wont communicate on usb but uses serial port.It has to be connected to GPIOs on the raspi.
Frequently the program which reads serial data disconnects.So prevent getty from writing to the serial port in /etc/inittab comment
#T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100)
Make sure your raspi connects to the internet via WIFI.
The python program to be run on the raspi :
import serial
import time
print "BT example started"
usbport = '/dev/ttyAMA0' #confirm your serial tty is AMA0
ser = serial.Serial(usbport,9600,timeout=3)
while True:
#if (ser.inWaiting()>0):
time.sleep(0.01)
data = ser.read(1024)#16384)
#if(data == "h"):
if len(data) > 0:
print "got ["+ str(data) +"]"# + line
Run the python program on the raspi
I tried using my android mobile.Download Bluetooth Terminal app on your phone.
Search for bluetooth networks on your phone - you should see HC06 pin would be 1234.Connect to it.
Open the Bluetooth terminal, whatever you type it should be visible in your SSH console via the python program on the raspi.