如何使用AT命令发送/接收短信?
谁能帮我在Python中使用AT命令发送和接收短信?
如果重要的话,我正在使用 Fedora 8。
哪款手机使用 Linux 会更好(诺基亚、索尼爱立信、三星……)? 所有手机都支持使用 AT 命令发送和接收短信吗?
Can anyone help me to send and receive SMS using AT commands in Python?
In case it matters, I'm using Fedora 8.
Which phone will be better with Linux (Nokia, Sony Ericson, Samsung,.....)?
Will all phones support sending and receiving SMS using AT commands?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
下面是一些可以帮助您入门的示例代码(在 Python 3000 中):
您需要做另外两件事:
以适当的格式对消息进行编码(主要是 GSM 03.38,有一个方便的 unicode.org 上的翻译表)。如果您确实不关心 ASCII 以外的任何字符,则可以检查每个字符是否都在
string.printable
中。检查消息的长度(我不确定是否与编码有关,但有时是 140 个字符,有时是 160)。
您可以使用
phone.readall()
检查错误,但最好在将消息发送到手机之前确保消息正确。还要注意,睡眠似乎是必要的。大多数手机都会理解这一点。为了让我的旧诺基亚 C5 打开串行连接,我必须从插入 USB 电缆时弹出的菜单中选择“PC 套件”。这在蓝牙上应该同样有效。
该代码使用 PySerial 包,适用于 python 2 和 3。
另请参阅:
Here's some example code that should get you started (in Python 3000):
You need to do two additional things:
Encode the message in the appropriate format (mostly GSM 03.38, there's a handy translation table at unicode.org). If you really don't care about any characters other than ASCII, you can just check if every character is in
string.printable
.Check the length of the message (I'm not sure if it's to do with the encoding, but it's sometimes 140 characters, sometimes 160).
You can use
phone.readall()
to check for errors, but it's best to make sure your message is OK before you send it off to the phone. Note also that the sleeps seem to be necessary.Most phones will understand this. In order to get my old Nokia C5 to open up the serial connection, I had to select "PC Suite" from the menu that pops up when you insert the USB cable. This should work equally well over Bluetooth.
The code uses the PySerial package, available for python 2 and 3.
See also:
查看使用 At 命令发送短信这会有所帮助。
要使用 At 命令接收短信,这应该有所帮助
to see send sms using At command this will help.
To recieve sms using At command this should help
与电话交谈很容易。您只需打开适当的
/dev/ttyACM*
设备并与其交谈。哪个手机比较麻烦。任何支持“网络共享”和 SMS 消息的完整 AT 命令集的手机都应该没问题。Talking to the phone is easy. You just need to open the appropriate
/dev/ttyACM*
device and talk to it. Which phone is trickier. Any phone that supports "tethering" and the full AT command set for SMS messages should be fine.我建议将
time.sleep
替换为条件循环,等待调制解调器“OK”的响应,然后再继续下一个状态。I would suggest replace the
time.sleep
with condition loop waiting for the response from the modem "OK" before continue next state.