- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在让我的 python 代码正常工作时遇到了一些困难。我有 Rpi2 和 SIM900 模块连接。我可以调用电话、接听电话、发送短信,甚至可以接收短信。但是放在一起让我很头疼。我在谷歌上滚动了一遍又一遍,现在我看到即使结果总是一样的,所以我在 0 点上取得了进一步的进展。
所以我的议程是向 SimModule 发送短信。如果 SMS 从批准列表中的电话号码到达,Python 将读取传入的 SMS,并将包含特定代码,它将调用特定号码:
短信示例
RV -> make call to cell no: 49
RI -> make call to cell no: 48
MV -> make call to cell no: 47
MI -> make call to cell no: 46
到目前为止,我可以使用以下代码阅读短信
import serial
import time
import sys
class sim900(object):
def __init__(self):
self.open()
def open(self):
self.ser = serial.Serial('/dev/ttyAMA0', 115200, timeout=5)
def SendCommand(self,command, getline=True):
self.ser.write(command)
data = ''
if getline:
data=self.ReadLine()
return data
def ReadLine(self):
data = self.ser.readline()
# print data
return data
def GetAllSMS(self):
self.ser.flushInput()
self.ser.flushOutput()
command = 'AT+CMGL=\"ALL\"\r'#gets incoming sms that has not been read
print self.SendCommand(command,getline=True)
data = self.ser.readall()
print data
self.ser.close()
def Call49(self):
self.ser = serial.Serial('/dev/ttyAMA0', 115200, timeout=5)
self.ser.write('ATD49;\r')
time.sleep(1)
time.sleep(1)
self.ser.write(chr(26))
# responce = ser.read(50)
self.ser.close()
print "calling"
def Call48(self):
self.ser = serial.Serial('/dev/ttyAMA0', 115200, timeout=5)
self.ser.write('ATD48;\r')
time.sleep(1)
self.ser.write(chr(26))
# responce = ser.read(50)
self.ser.close()
print "calling"
h = sim900()
h.GetAllSMS()
我可以阅读短信(见下文)
AT+CMGL="ALL"
AT+CMGL="ALL"
+CMGL: 1,"REC READ","+30000000000","","17/08/27,23:28:51+08"
RV
+CMGL: 2,"REC READ","+30000000000","","17/08/28,00:34:12+08"
RI
OK
如果在 SMS“def GetAllSMS”电话号码 +30000000000 中将与将执行“def Call48”的文本 RV 一起存在,如果它是 RI 将执行“def Call47”,我现在如何添加功能
一些帮助将不胜感激。提前 Tnx。
最佳答案
正确解析调制解调器响应可能很棘手(例如,参见 this answer)。如果您要使用消息传递功能以及语音调用和 USSD 请求,您可能最终会重新创建 python-gsmmodem library :) 但是在解析 SMS 响应的特殊情况下,您可以使用此代码(改编自提到的 python-gsmmodem)。
import re
def GetAllSMS(self):
self.ser.flushInput()
self.ser.flushOutput()
result = self.SendCommand('AT+CMGL="ALL"\r\n')
msg_lines = []
msg_index = msg_status = number = msg_time = None
cmgl_re = re.compile('^\+CMGL: (\d+),"([^"]+)","([^"]+)",[^,]*,"([^"]+)"$')
# list of (number, time, text)
messages = []
for line in result:
cmgl_match = cmgl_re.match(line)
if cmgl_match:
# New message; save old one if applicable
if msg_index != None and len(msg_lines) > 0:
msg_text = '\n'.join(msg_lines)
msg_lines = []
messages.append((number, msg_time, msg_text))
msg_index, msg_status, number, msg_time = cmgl_match.groups()
msg_lines = []
else:
if line != 'OK':
msg_lines.append(line)
if msg_index != None and len(msg_lines) > 0:
msg_text = '\n'.join(msg_lines)
msg_lines = []
messages.append((number, msg_time, msg_text))
return messages
此函数将读取所有 SMS 并将它们作为元组列表返回:[("+30000000000", "17/08/28,00:34:12+08", "RI"), ( "+30000000000", "17/08/28,00:34:12+08", "RV")
... 遍历该列表以检查数字是否有效并采取必要的措施:
for number, date, command in messages:
if number != "+30000000000":
continue
if command == 'RI':
self.call_1()
elif command == 'RV':
self.call_2()
关于python - 使用 SIM900 的 AT 命令接收短信和调用电话,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45917778/
我想获取双 SIM 卡手机中两张 SIM 卡的 SIM 卡序列号/ID。有没有办法获取它们?提前致谢。 最佳答案 import java.lang.reflect.Method; im
我知道我们可以使用 TelephonyManager 类检索单个 Sim 卡的信息。但是如何检索有关多张 SIM 卡的信息?比如说,我的手机丢了,有人更换了其中一个插槽中的 SIM 卡。我如何收到包括
我想使用 Python 中的 R 包 fracdiff 和 arfima。我使用 rpy2 作为 导入了这个库 from rpy2.robjects.packages import importr f
这个问题在这里已经有了答案: How to get sim id from iphone (1 个回答) Programmatically get own phone number in iOS
我正在构建一个网络监视器应用程序。在这里,我已成功实现了所有功能,例如跟踪 Wifi 或移动数据的数据使用情况,但我想知道哪个 SIM 卡连接到互联网并使用移动数据。 使用下面的代码,我可以知道我的双
我有一个检测来电的 Android 应用程序,我需要改进这个应用程序以在 duos 移动设备上运行。所以我创建了一个在 list 中注册的广播接收器以进行操作:电话状态已更改,并且在我的 onRece
过去几天我一直在寻找这个,我才知道: “Android开箱即用不支持双卡,是厂商自定义修改,没有公共(public)API控制。” 以下链接中提供了一个解决方案,但它不适用于我的手机三星 Galaxy
我被搜索了有关 NFC SIM 卡的信息,发现 such explanations关于他们在这里和那里: For those who want to use near field communicat
我有一部带 2 张 SIM 卡的 Android 手机,我想检测来电的目标——是 SIM 1 还是 SIM 2。是否可以从通话信息中获取目标号码? 最佳答案 最后我使用这段代码得到了解决方案。希望它对
我有一部带 2 张 SIM 卡的 Android 手机,我想检测来电的目标——是 SIM 1 还是 SIM 2。是否可以从通话信息中获取目标号码? 最佳答案 最后我使用这段代码得到了解决方案。希望它对
我想检查哪个 SIM 卡正在为双卡 android 手机拨出电话。阅读本文 Android : Check whether the phone is dual SIM . 工作起来很有魅力,可以检测
我想在双卡设备中获取两个 sim 号码。 最佳答案 使用 API > 21 需要权限android.Manifest.permission.READ_PHONE_STATE. public class
我尝试为单个 SIM 设备配置 EAP-SIM 并成功连接。现在我想在双 SIM 设备上配置特定的 SIM 卡。 我的观察是在单个 SIM 设备中配置 EAP 时,没有规定指定 SIM 身份。那么如何
如何在具有双 SIM 卡的 Android 中发送短信用于广播而不是 Intent ?如何在android中检测双卡?用户想要选择 sim 卡来发送短信广播。在 android 中设置用于在 andr
我正在开发一个应用程序,我需要知道来电是来自 sim 1 还是 sim 2。在某些设备中,广播接收器会检测到它,但并非所有设备都发生这种检测。 如何检测到 sim 1 或 sim 2 有来电? 最佳答
I searched and read all the questions and answers similar to this question but non is solving my pro
有没有办法以编程方式检查 Android 中的 sim 1 或 sim 2 的移动数据是否处于 Activity 状态? 我还想获得数据处于 Activity 状态的运营商提供商。 情商:sim 1
我想在收到短信时获得 SIM 卡的唯一 ID(line1number 或 simserialnumber...)。它适用于单 SIM 卡。是否可以使用多 SIM 卡? 最佳答案 多 SIM 卡支持仅添
我正在尝试检查我的移动设备是否是双 sim 卡,sim1 是否准备就绪,sim2 是否准备就绪,我已使用 java 反射完成此操作,现在我想知道 sim1 是否正在漫游以及 sim2 是否正在漫游,如
我有双卡 Android 智能手机。我知道 android SDK 不支持双卡双待设备。我想在默认插槽上访问 sim 的 sim 运营商名称。但是当我运行程序时,它给了我一个空字符串。以下是我的代码:
我是一名优秀的程序员,十分优秀!