I'm a beginner in python and i'm looking for a library to send and receive SMS through a Huawei modem. I tried gammu, pysms and pygsm but failed to get them to work. Could you give me code examples with those libraries?
Asked
Active
Viewed 1.7k times
8
-
2Try this: https://code.google.com/p/pyhumod/ – Piotr Dabkowski Apr 09 '14 at 22:52
-
Not sure why this is quite useful indeed!! upvote by me (and several other 'future' come present users!!!!!) – JB-007 Jul 14 '21 at 03:16
1 Answers
3
You can try this code, it works for me , just plug your USB dongle and get it's device node path(in linux use lsusb and ls -lha /dev/tty*) and replace /dev/ttyACM0
with that path.Then you should able to send sms, This code works for me with Huawei USB modem.
#!/usr/bin/env python
"""
sms.py - Used to send txt messages.
"""
import serial
import time
class TextMessage:
def __init__(self, recipient="0123456789", message="TextMessage.content not set."):
self.recipient = recipient
self.content = message
def setRecipient(self, number):
self.recipient = number
def setContent(self, message):
self.content = message
def connectPhone(self):
self.ser = serial.Serial('/dev/ttyACM0', 460800, timeout=5)
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()
for more details try this link (archive of that dead link as of 2014-08-25 )
-
-
Thanks for sharing python serial send text. If not work, just custome AT Command. Refer to GSM Modem. – Pamungkas Jayuda Nov 23 '19 at 06:20