我想将 hex cmd (0X2A,0X0A,0X58) 从树莓派发送到我的另一个蓝牙接口设备 (Arduino) 以接收传感器数据。当我使用 server.send(0X2A,0X0A,0X58) 时。它不起作用。所以如何发送该请求 cmd 以从蓝牙接收数据。我已经配对了我的蓝牙设备。
from bluetooth import
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, "SampleServer",
service_id = uuid,
service_classes = [ uuid, SERIAL_PORT_CLASS ],
profiles = [ SERIAL_PORT_PROFILE ],
# protocols = [ OBEX_UUID ]
)
print "Waiting for connection on RFCOMM channel %d" % port
client_sock, client_info = server_sock.accept()
print "Accepted connection from ", client_info
try:
while True:
server.send(0X2A,0X0A,0X58)
data = client_sock.recv(1024)
if len(data) == 0: break
print "received [%s]" % data
except IOError:
pass
print "disconnected"
client_sock.close()