Raspberry PI B+ raspbian: raspberrypi 3.18.7+ #755 PREEMPT Thu Feb 12 17:14:31 GMT 2015 ** Garmin GLO **: Bluetooth GPS receiver Bluetooth dongle: Elecom-Logitec ** LBT-UAN04C1 ** (CSR chipset with a reputation for Linux)
Let's introduce modules
apt-get install bluez bluez-utils
Don't forget to apt-get install python-bluez for coding with python ver.2.
(1) hcitool scan Scan Garmin GLO. You should see an address like 12:34:56:78:90: AB. ** (2) Port connection **
sudo rfcomm bind /dev/rfcomm1 12:34:56:78:90:AB 1
This will create a Garmin GLO Virtual COM port as / dev / rfcomm1. However, the GLO bluetooth status LED remains blinking slowly. (Not paired) ** (3) Data dump from port ** Easy way is
cat < /dev/rfcomm1
is. If you do this, the GLO bluetooth status LED will be lit (ie paired) with a delay and you will see the NMEA output on the console. When you are finished, use ctrl -c to exit.
Or
dd if=/dev/rfcomm1 of= ...
Is also OK.
Python (ver.2) In python ver.2, PyBluez is used.
sudo apt-get install python-bluez
Let's introduce it with.
import bluetooth
bd_addr = "12:34:56:78:90:AB"
port = 1
sock=bluetooth.BluetoothSocket(bluetooth.RFCOMM)
sock.connect((bd_addr, port))
data=sock.recv(1024)
sock.close()
print data
In this case, the data returned by sock.recv () will be of type str.
Python3 python3 uses the standard socket module.
import socket
bd_addr = "12:34:56:78:90:AB"
port = 1
sock = socket.socket(socket.AF_BLUETOOTH, socket.SOCK_STREAM, socket.BTPROTO_RFCOMM)
sock.connect((bd_addr, port))
data = sock.recv(1024)
sock.close()
dataReadable = data.decode('utf-8')
print(dataReadable)
In this case, the data returned by sock.recv () will be of type bytes. So, let's convert it to str with decode ().
Recommended Posts