Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
626 B
0
Indexable
Never
import serial
import time

# Replace 'COMx' with the COM port assigned to your phone
ser = serial.Serial('COMx', 9600, timeout=1)

def send_sms(number, message):
    ser.write(b'AT\r\n')
    time.sleep(1)
    ser.write(b'AT+CMGF=1\r\n') # Set SMS mode to text
    time.sleep(1)
    ser.write(b'AT+CMGS="' + number.encode() + b'"\r\n')
    time.sleep(1)
    ser.write(message.encode() + b'\x1A') # Message termination
    time.sleep(1)
    print("SMS sent!")

if __name__ == "__main__":
    number = input("Enter recipient's phone number: ")
    message = input("Enter message: ")
    send_sms(number, message)
    ser.close()
Leave a Comment