本文介绍了Bluetooth.btcommon.bluetoother ...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是尝试运行RFCOMM服务器示例,网址为https://code.google.com/p/pybluez/source/browse/trunk/examples/simple/rfcomm-server.py

我收到此错误:

$ python2 rfcomm-server.py Traceback(最近一次调用最后一次):文件rfcomm-server.py,第20行,在profiles = [SERIAL_PORT_PROFILE]中,文件/usr/lib/python2.7/site-packages/bluetooth/bluez.py,第176行,在advertise_service中引发BluetoothError(str(e))bluetooth.btcommon.BluetoothError:(2,'没有这样的文件或目录')

我的代码正在使用windows但我无法工作ubuntu 15.10。我的错误是什么?



我是什么尝试过:



这里我的代码:



进口请求

来自蓝牙导入*



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]





打印(在RFCOMM频道上等待连接%d%端口)



client_sock, client_info = server_sock.accept()

print(接受来自,client_info)



试试:

同时为真:

data = client_sock.recv(1024)

如果len(数据)== 0:休息

print(收到[%s]%data)

userdata = {deviceid:85,sensorid:2,sensordata:data}

resp = requests.post ('http://localhost/iot/ajax2.php',params = userdata)

print(resp)

除了IOError:

pass



print(disconnected)



client_sock.close()

server_sock.close()

print(all done)

I`m simply trying to run the RFCOMM server example at https://code.google.com/p/pybluez/source/browse/trunk/examples/simple/rfcomm-server.py
I am getting this error:
$ python2 rfcomm-server.py Traceback (most recent call last): File "rfcomm-server.py", line 20, in profiles = [ SERIAL_PORT_PROFILE ], File "/usr/lib/python2.7/site-packages/bluetooth/bluez.py", line 176, in advertise_service raise BluetoothError (str (e)) bluetooth.btcommon.BluetoothError: (2, 'No such file or directory')
My code is working on windows but i could not work ubuntu 15.10.Where is my mistake?

What I have tried:

here my code:

import requests
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:
data = client_sock.recv(1024)
if len(data) == 0: break
print("received [%s]" % data)
userdata = {"deviceid": 85, "sensorid": 2, "sensordata": data}
resp = requests.post('http://localhost/iot/ajax2.php', params=userdata)
print(resp)
except IOError:
pass

print("disconnected")

client_sock.close()
server_sock.close()
print("all done")

推荐答案


这篇关于Bluetooth.btcommon.bluetoother ...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 14:15