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?
How to send and receive SMS from python using usb modem? [closed]
Asked Answered
Try this: code.google.com/p/pyhumod –
Blynn
Not sure why this is quite useful indeed!! upvote by me (and several other 'future' come present users!!!!!) –
Trinitroglycerin
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 )
link not working, without it, this answer is usless –
Gonophore
Thanks for sharing python serial send text. If not work, just custome AT Command. Refer to GSM Modem. –
Multipurpose
© 2022 - 2024 — McMap. All rights reserved.