can send sms
This commit is contained in:
@@ -0,0 +1 @@
|
||||
/.idea/
|
||||
@@ -1,33 +1,51 @@
|
||||
import serial
|
||||
from gsmmodem import GsmModem
|
||||
from gsmmodem.modem import SentSms
|
||||
|
||||
serial_list=[]
|
||||
ser = serial.Serial("COM74", 115200, timeout=1)
|
||||
PORT = "/dev/tty.usbmodem11101"
|
||||
BAUDRATE = 115200
|
||||
ser = serial.Serial(PORT, BAUDRATE, timeout=1)
|
||||
|
||||
|
||||
def changeToSMSMode():
|
||||
cmd = "AT+CMGF=1\r" # text mode
|
||||
sendCommand(cmd)
|
||||
msg = ser.read(64)
|
||||
print(msg)
|
||||
def has_sim() -> bool:
|
||||
# check pin
|
||||
cmd_check_pin = "AT+cpin?\r"
|
||||
msg = send_command(cmd_check_pin)
|
||||
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))
|
||||
ser.write(cmd.encode())
|
||||
msg = ser.read(100)
|
||||
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__':
|
||||
#enable verbose logs
|
||||
# enable verbose logs
|
||||
cmd = "AT+CMEE=2\r"
|
||||
sendCommand(cmd)
|
||||
#check pin
|
||||
cmd_check_pin = "AT+cpin?\r"
|
||||
sendCommand(cmd_check_pin)
|
||||
# cmd = "AT\r"
|
||||
# sendCommand(cmd)
|
||||
# msg = ser.read(64)
|
||||
# print(msg)
|
||||
# changeToSMSMode()
|
||||
|
||||
send_command(cmd)
|
||||
if has_sim():
|
||||
send_sms("+33649614591","Modem pool test")
|
||||
else:
|
||||
print("no cart sim")
|
||||
|
||||
Reference in New Issue
Block a user