Wednesday, February 7, 2018

Send sms using dongle by python code

In windows,

install python-gammu (pip3 install python-gammu)
plug your dongel and install it throught its software
go to device manger and click on Ports(COM & LPT)
under that menu you will see your dongel and remind the com port
install wammu
connect the dongel
get wammu > settings > connection tab and click on add button
next click guided configuration, click on usb cable radio button and Next
select i dont know radio button and click next
select AT based and next
keep driver to use as Generic...
and click next
in the drop down menu select the certain com port and click next.
it will sync with device.
click ok
in wammu click phone > and click on connect.
if its connect all is well.
then take run and type %appdata%
go down and open the .gammurc file and copy the content to the notepad and save it on a accessible location.




In linux,

install python-gammu using following
apt-get install python-gammu
Linux dont need python3. It should be run in python2.7
you can find the dongel connected port, just run dmesg right after you connected the usb dongel. there you will see it has connected to /dev/ttyUSB0 or something like that port. Some times this port may have converted to several ports in dmesg log. Get the last port in the dmesg log. use this port to include in .gammurc config file. contents are same as windows .gammurc file only replace the COM port with relevant /dev/ttyUSB port.
Note : If dongel seems to be not detected try disabling mobile connections in network settings.


Python code (It's python3 in windows)
""""""""""""""
import gammu

sm = gammu.StateMachine()
sm.ReadConfig(Filename='D:/.gammurc') #instead of this location put the location you saved the above
sm.Init()

message = {
    'Text': 'python-gammu testing message',
    'SMSC': {'Location': 1},
    'Number': '+94758851272',
}

sm.SendSMS(message)

############################################

in 'Text': put your message

No comments:

Post a Comment