import serial import time class SMSsender: def __init__(self): self.destination = "" self.msg = "" def setRecipient(self, dest): self.destination = dest def setContent(self, message): self.msg = message def connectPhone(self): #replace '/dev/ttyACM0' with your device name #replace 460800 with a suitable baud-rate of your phone self.ser = serial.Serial('/dev/ttyACM0', 460800, timeout=2) time.sleep(1) def sendMessage(self): self.ser.write('ATZ\r') time.sleep(1) self.ser.write('AT+CMGF=1\r') time.sleep(1) self.ser.write('''AT+CMGS="''' + self.recipient + '''"\r''') time.sleep(1) self.ser.write(self.content + "\r") time.sleep(1) self.ser.write(chr(26)) time.sleep(1) def disconnectPhone(self): self.ser.close()To send sms use this follow the code below:
sms = SMSsender() sms.setRecipient('+8801*********') sms.setContent('Write your message here') sms.connectPhone() sms.sendMessage() sms.disconnectPhone()You may also try this link(I've not tested yet): sms-over-3g-and-bluetooth-from-python
Source: linux-101.org
No comments:
Post a Comment