+CME错误:无效的parem

2024-04-23 15:03:19 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图用我自己的python脚本从我的RaspberryPi发送短信。我正在使用RPi上GPIO上的串行端口与GSM调制解调器通信。我选择了文本模式的短信格式,列出的短信,等等,它都很好,直到它来发送短信。当我想寄的时候,我收到了错误的信息。在

要停止发送消息,我按esc键,按enter键(通过串行发送),效果很好(调制解调器发送回“OK”) 我知道要发送消息,在消息内容之后我必须发送ctrl-z。在linux中,当我按下ctrl-z时,我会停止程序,所以不可能按这些键然后再回车。这就是为什么我做了一个发送短信的函数,我把ctrl-zchar/sign放在这里。在

当我运行程序调制解调器响应一个错误,如标题(+CME错误:无效的参数或如果你想错误代码:+CME错误:3518)我知道这可能看起来很愚蠢,但我已经找了两天的答案,我尝试了chr(26).encode(),“\x1a”,“\x1a”(甚至不知道有没有区别),我试着用一个单独的信息内容发送它,但是没有任何效果

我可能做错了什么,但我不知道是什么。所以我发布了一些代码和数据表屏幕如何发送消息。 发送短信:

def sendSMS(self, phoneNumber=111111111, smsContent=""):
    # if phoneNumber==0:
    if phoneNumber!=111111111:
        print("Type phone number in: (without prefix +48): ", end="")
        phoneNumber = input()
        try:
            phoneNumber = int(phoneNumber)
        except Exception:
            print("Type in an integer")
            time.sleep(1)
            self.sendSMS()
    print("Type text message content (press ENTER to send): ")
    smsContent = str(input())
    char_CtrlZ = "\x1a"
    quote = "\""
    command = "AT+CMGS=" + quote + str(phoneNumber) + quote + "," + quote + "129" + quote
    message = smsContent + char_CtrlZ
    self.serialConnection.send(command)
    time.sleep(1)
    self.serialConnection.receive()
    time.sleep(1)
    if self.checkModemResponse()==True: #here I send empty string (few times, if needed) until modem responses with '>'
        print("No '>' in modem response")
        print("Message did not send")
    else:
        self.serialConnection.send(message, True, False)
        time.sleep(2)
        self.serialConnection.receive(True, True, True)
        time.sleep(1)
        if self.serialConnection.responseState=="COMPLETE_OK":
            print("Your message has been sent!")    

def checkModemResponse(self, attempt=3):
    #I have 5 states of response: UNKNOWN; COMPLETE_OK - modem responses with OK; COMPLETE_ERROR - modem responses with ERROR; UNCOMPLETE - modem responses correctly but without ERROR or OK; EMPTY modem responds correctly but with empty string
    isUncomplete = True
    if self.serialConnection.responseState!="UNCOMPLETE":
        isUncomplete = False
        attempt -= 1
        if attempt > 0:
            print("Trying again..")
            someString = "attempt: " + str(attempt)
            self.serialConnection.send(someString)
            time.sleep(1)
            self.serialConnection.receive(True, True, True)
            time.sleep(1)
            if self.serialConnection.responseState!="UNCOMPLETE":
                self.checkModemResponse(attempt)
    return isUncomplete

通过串行发送命令:

^{pr2}$

How to send an SMS: +CMGS datesheet screenshot


Tags: selfsendtrueiftime错误oksleep