can send sms
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
/.idea/
|
||||||
@@ -1,33 +1,51 @@
|
|||||||
import serial
|
import serial
|
||||||
|
from gsmmodem import GsmModem
|
||||||
|
from gsmmodem.modem import SentSms
|
||||||
|
|
||||||
serial_list=[]
|
PORT = "/dev/tty.usbmodem11101"
|
||||||
ser = serial.Serial("COM74", 115200, timeout=1)
|
BAUDRATE = 115200
|
||||||
|
ser = serial.Serial(PORT, BAUDRATE, timeout=1)
|
||||||
|
|
||||||
|
|
||||||
def changeToSMSMode():
|
def has_sim() -> bool:
|
||||||
cmd = "AT+CMGF=1\r" # text mode
|
# check pin
|
||||||
sendCommand(cmd)
|
cmd_check_pin = "AT+cpin?\r"
|
||||||
msg = ser.read(64)
|
msg = send_command(cmd_check_pin)
|
||||||
print(msg)
|
if b'OK' in msg:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def sendCommand(cmd: str):
|
def send_command(cmd: str) -> bytes:
|
||||||
print("send command {}".format(cmd))
|
print("send command {}".format(cmd))
|
||||||
ser.write(cmd.encode())
|
ser.write(cmd.encode())
|
||||||
msg = ser.read(100)
|
msg = ser.read(100)
|
||||||
print(msg)
|
print(msg)
|
||||||
|
return msg
|
||||||
|
|
||||||
|
|
||||||
|
def send_sms(sms_destination: str, msg: str):
|
||||||
|
print('Initializing modem...')
|
||||||
|
modem = GsmModem(PORT, BAUDRATE)
|
||||||
|
modem.connect('0000')
|
||||||
|
# modem.waitForNetworkCoverage(10)
|
||||||
|
print('Sending SMS to: {0}'.format(sms_destination))
|
||||||
|
|
||||||
|
response = modem.sendSms(sms_destination, msg, True)
|
||||||
|
if type(response) == SentSms:
|
||||||
|
print('SMS Delivered.')
|
||||||
|
else:
|
||||||
|
print('SMS Could not be sent')
|
||||||
|
|
||||||
|
modem.close()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
#enable verbose logs
|
# enable verbose logs
|
||||||
cmd = "AT+CMEE=2\r"
|
cmd = "AT+CMEE=2\r"
|
||||||
sendCommand(cmd)
|
send_command(cmd)
|
||||||
#check pin
|
if has_sim():
|
||||||
cmd_check_pin = "AT+cpin?\r"
|
send_sms("+33649614591","Modem pool test")
|
||||||
sendCommand(cmd_check_pin)
|
else:
|
||||||
# cmd = "AT\r"
|
print("no cart sim")
|
||||||
# sendCommand(cmd)
|
|
||||||
# msg = ser.read(64)
|
|
||||||
# print(msg)
|
|
||||||
# changeToSMSMode()
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user