您如何通过蓝牙和Python处理和接收串行数据?
我正在尝试制作一个简单的Python服务器,该服务器通过蓝牙将数据访问为explained here.
我的server.py文件在发送文本“ temp”时发送一个随机数,它是:
#!/usr/bin/env python
import os
import glob
import time
import random
from bluetooth import *
def read_temp():
return random.random()
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, "TestServer",
service_id = uuid,
service_classes = [ uuid, SERIAL_PORT_CLASS ],
profiles = [ SERIAL_PORT_PROFILE ],
# protocols = [ OBEX_UUID ]
)
while True:
print "Waiting for connection on RFCOMM channel %d" % port
cli