私はPython 2.6で作業しています。私の携帯電話、すなわちNokia E-72がデータケーブル経由でPCに接続されているときにSMSをモバイルに送信したいと思います。データケーブル接続でPython 2.6でSMSを送信
モバイルはシリアルポート経由で接続されており、コードにも正しいポートが入力され、コードにエラーはありませんが、メッセージは送信されません。
import serial
import time
phone = serial.Serial()
phone.baudrate = 38400
phone.bytesize = 8
phone.stopbits = 1
phone.xonxoff = 0
phone.rtscts = 0
phone.timeout = 0
phone.port = 4 #try different ports here, if this doesn't work.
phone.parity=serial.PARITY_NONE
phone.open()
print phone.portstr
recipient = "+923219409998"
message = "We did it!"
try:
time.sleep(0.5)
phone.write(b'ATZ\r')
time.sleep(0.5)
phone.write(b'AT+CMGF=1\r')
time.sleep(0.5)
phone.write(b'AT+CMGS="' + recipient.encode() + b'"\r')
time.sleep(0.5)
phone.write(message.encode() + b"\r")
time.sleep(0.5)
phone.write(bytes([26]))
time.sleep(0.5)
phone.readall()
finally:
phone.close()
誰でも問題を見つけられるようになる前に、コードの書式を修正してください。 – Gangadhar
電話機でも許可されているかどうかわかりませんが、シリアル接続であることを確認してください。 – Geoffroy
はい、シリアル接続です。なぜあなたはこれを求めているのですか? – user1325702