我想通过蓝牙将Raspberry Pi连接到一体(我正在编写一个将来会使用手机通过蓝牙连接到Pi的应用程序。)
我该怎么做?我无法在SO或其他任何地方找到答案。
如何通过蓝牙传输数据?
答案 0 :(得分:1)
我该怎么做?我无法在SO或其他任何地方找到答案。
我用它搜索了this
如何通过蓝牙传输数据?
这可能会帮助link
或者您可以编写与此类似的python脚本
# Uses Bluez for Linux
#
# sudo apt-get install bluez python-bluez
#
# Taken from: https://people.csail.mit.edu/albert/bluez-intro/x232.html
# Taken from: https://people.csail.mit.edu/albert/bluez-intro/c212.html
import bluetooth
def receiveMessages():
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 " + str(address)
while True:
data = client_sock.recv(1024)
print "received [%s]" % data
#client_sock.close()
#server_sock.close()
def sendMessageTo(targetBluetoothMacAddress):
port = 1
sock=bluetooth.BluetoothSocket( bluetooth.RFCOMM )
sock.connect((targetBluetoothMacAddress, port))
sock.send("hello!!")
sock.close()
def lookUpNearbyBluetoothDevices():
nearby_devices = bluetooth.discover_devices()
for bdaddr in nearby_devices:
print str(bluetooth.lookup_name( bdaddr )) + " [" + str(bdaddr) + "]"
lookUpNearbyBluetoothDevices()
receiveMessages()
代码描述::它查找可用的蓝牙设备,并从第一个发起连接的蓝牙设备接收消息。它会根据功能参数中指定的mac地址向目标蓝牙设备发送消息。
参考: Link