获取蓝牙设备的响应
我正在尝试编写一个简单的模块来发送短信。 我使用蓝牙连接到移动设备,使用以下示例:
file: bt-sendsms.py
import bluetooth
target = '00:32:AC:32:36:E8' # Mobile address
print "Trying to send SMS on %s" % target
BTSocket = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
BTSocket.connect((target, 2)) # BT Address
BTSocket.send('ATZ\r')
BTSocket.send('AT+CMGF=1\r')
#sockfd.send('AT+CSCA="+972547716507"\r') # This line changes the SMSC address - do not modify unless required
BTSocket.send('AT+CMGS="+972547877763"\r') # TO Phone Number
BTSocket.send('This is a test message - port 2.\n')
BTSocket.send(chr(26)) # CTRL+Z
print "SMS sent"
sockfd.close()
print "Closed"
我的问题是我无法验证或获取短信发送或任何套接字操作的错误代码。
任何对正确方向的推荐将不胜感激
I'm trying to write a simple module that will enable sending SMS. I using bluetooth to connect to the mobile using the below example:
file: bt-sendsms.py
import bluetooth
target = '00:32:AC:32:36:E8' # Mobile address
print "Trying to send SMS on %s" % target
BTSocket = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
BTSocket.connect((target, 2)) # BT Address
BTSocket.send('ATZ\r')
BTSocket.send('AT+CMGF=1\r')
#sockfd.send('AT+CSCA="+972547716507"\r') # This line changes the SMSC address - do not modify unless required
BTSocket.send('AT+CMGS="+972547877763"\r') # TO Phone Number
BTSocket.send('This is a test message - port 2.\n')
BTSocket.send(chr(26)) # CTRL+Z
print "SMS sent"
sockfd.close()
print "Closed"
My problem is that I'm unable to verify or get an error code for the SMS sending or any of the socket operation.
Any referral to the right direction will be appreciated
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从 Python 看来,您似乎正在打开任何旧的 RFCOMM 通道,并希望它能够神奇地接受 AT 命令并执行消息传递。
我认为(我可能是错的)您需要连接到特定的配置文件/服务通道,我认为对于短信来说,它是消息传递访问配置文件(MAP),它尚未标准化,因此找到一部带有它的手机,好吧,我不会说不可能,但非常非常不可能。 否则,某些手机将支持 AT 命令进行消息传送,但这超出了规格范围,例如,据我所知,索尼爱立信手机将通过拨号网络配置文件 (DUN) 支持它。
那么,首先,您的移动设备是否支持一些不符合规范的 SMS AT 命令,如果支持,则支持特定配置文件或临时专有配置文件? 接下来,您需要连接到该配置文件。
您可以使用以下Python浏览支持的服务等...(检查所有周围的BT设备)...
一旦找到正确的服务/配置文件,您的下一个问题将是协商安全性(用于配对的PIN码),我还没有还没想好怎么做!
请访问 www.bluetooth.org 来满足您的所有蓝牙需求!
From the Python you look like you are opening any old RFCOMM channel and hoping it will magically take the AT commands and do the messaging.
I think (and I could be wrong) that you need to connect to a specific profile/sevice channel and I think for SMS it is the the Messaging Access Profile (MAP), which is not yet standardised so finding a phone with it on, well I won't say impossible but very, very unlikely. Otherwise, some phones will support AT commands for messaging but this is outside the specs e.g. I have it on authority that Sony-Ericson phones will support it though the Dial-Up Networking profile (DUN).
So, first of all, does your mobile device support some out of spec AT commands for SMS and if so, on a certain profile or on an ad-hoc proprietary one? Next, you need to connect to that profile.
You can browse the supported services etc... using the following Python (checks all surrounding BT devices)...
Once you find the correct service/profile, your next problem will be negotiating security (pin code for pairing), which I haven't worked out how to do yet!
See the www.bluetooth.org for all your Bluetooth needs!