maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Applications (https://talk.maemo.org/forumdisplay.php?f=41)
-   -   is it possible to send a text with alarmed? (https://talk.maemo.org/showthread.php?t=62754)

thesnake505 2010-09-22 21:32

is it possible to send a text with alarmed?
 
as title i want to send a text message at a set time to 3 people,is this possible? if so how?

cheers snake

elie-7 2010-09-22 21:45

Re: is it possible to send a text with alarmed?
 
first of all thats a great idea, because we can use this for holidays, for example i would like my phone to send a message to all my contacts saying 'merry xmas' 25 december, or happy new year or.....without having to send it manually .
if there was a way to send messages via xterm than i think that should be possible.

CepiPerez 2010-09-22 21:52

Re: is it possible to send a text with alarmed?
 
Yes, I have a script that does it

In Alarmed:
Select "Command execution" and put this command
/path/to/sendsms.py PHONENUMBER "MESSAGE"

sendsms.py contains this:
Code:

#!/usr/bin/env python2.5         
import sched, time               
import dbus                     
import gobject                   
from dbus.mainloop.glib import DBusGMainLoop
 
def octify(str):
        '''   
        Returns a list of octet bytes representing
        each char of the input str.             
        '''                                     
 
        bytes = map(ord, str)
        bitsconsumed = 0   
        referencebit = 7   
        octets = []         
 
        while len(bytes):
                byte = bytes.pop(0)
                byte = byte >> bitsconsumed
 
                try:                     
                        nextbyte = bytes[0]
                        bitstocopy = (nextbyte & (0xff >> referencebit)) << referencebit
                        octet = (byte | bitstocopy)                                   
 
                except:
                        octet = (byte | 0x00)
 
                if bitsconsumed != 7:
                        octets.append(byte | bitstocopy)
                        bitsconsumed += 1             
                        referencebit -= 1             
                else:                                 
                        bitsconsumed = 0               
                        referencebit = 7               
 
        return octets
 
def semi_octify(str):
        '''         
        Expects a string containing two digits.
        Returns an octet -                   
        first nibble in the octect is the first
        digit and the second nibble represents
        the second digit.                     
        '''                                   
        try:                                 
                digit_1 = int(str[0])         
                digit_2 = int(str[1])         
                octet = (digit_2 << 4) | digit_1
        except:                               
                octet = (1 << 4) | digit_1     
 
        return octet
 
 
def deoctify(arr):
 
        referencebit = 1
        doctect = []   
        bnext = 0x00   
 
        for i in arr:
 
                bcurr = ((i & (0xff >> referencebit)) << referencebit) >> 1
                bcurr = bcurr | bnext                                     
 
                if referencebit != 7:
                        doctect.append( bcurr )
                        bnext = (i & (0xff << (8 - referencebit)) ) >> 8 - referencebit
                        referencebit += 1                                             
                else:                                                                 
                        doctect.append( bcurr )                                       
                        bnext = (i & (0xff << (8 - referencebit)) ) >> 8 - referencebit
                        doctect.append( bnext )                                       
                        bnext = 0x00                                                 
                        referencebit = 1                                             
 
        return ''.join([chr(i) for i in doctect])
 
 
def createPDUmessage(number, msg):
        '''                     
        Returns a list of bytes to represent a valid PDU message
        '''                                                   
        numlength = len(number)                               
        if (numlength % 2) == 0:                               
                rangelength = numlength                       
        else:                                                 
                number = number + 'F'                         
                rangelength = len(number)                     
 
        octifiednumber = [ semi_octify(number[i:i+2]) for i in range(0,rangelength,2) ]
        octifiedmsg = octify(msg)                                                     
        HEADER = 1                                                                   
        FIRSTOCTETOFSMSDELIVERMSG = 10                                               
        ADDR_TYPE = 129 #unknown format                                               
        number_length = len(number)                                                   
        msg_length = len(msg)                                                         
        pdu_message = [HEADER, FIRSTOCTETOFSMSDELIVERMSG, number_length, ADDR_TYPE]   
        pdu_message.extend(octifiednumber)                                           
        pdu_message.append(0)                                                         
        pdu_message.append(0)                                                         
        pdu_message.append(msg_length)                                               
        pdu_message.extend(octifiedmsg)                                               
        return pdu_message                                                           
 
 
def sendmessage(number, message):
 
        bus = dbus.SystemBus()
        smsobject = bus.get_object('com.nokia.phone.SMS', '/com/nokia/phone/SMS/ba212ae1')
        smsiface = dbus.Interface(smsobject, 'com.nokia.csd.SMS.Outgoing')
        arr = dbus.Array(createPDUmessage(number.replace('+', '00'), message))
 
        msg = dbus.Array([arr])
        smsiface.Send(msg,'')
 
 
def callback(pdumsg, msgcenter, somestring, sendernumber):
 
        msglength = int(pdumsg[18])
        msgarray = pdumsg[19:len(pdumsg)]
 
        msg = deoctify(msgarray)
 
        if msg > 0:
              print 'New message received from %s' % sendernumber
              print 'Message length %d' % msglength
              print 'Message: %s' % msg
 
              if msg == "ping":
                      print "Sending reply: pong"
                      sendmessage(sendernumber.replace("+","00"), "pong")
              else:
                      print "Unknown command"
 
 
def listen():
        DBusGMainLoop(set_as_default=True)
        bus = dbus.SystemBus() #should connect to system bus instead of session because the former is where the incoming signals come from
        bus.add_signal_receiver(callback, path='/com/nokia/phone/SMS', dbus_interface='Phone.SMS', signal_name='IncomingSegment')
        gobject.MainLoop().run()
 
 
if __name__ == '__main__':
  import time
 
  def schedule_task(schedule, fn, *args):
      import sched
      s = sched.scheduler(time.time, time.sleep)
      startTime = time.mktime(time.strptime(schedule, '%b %d %H:%M %Y'))
      s.enterabs(startTime, 0, fn, args)
      s.run()
 
  import getopt, sys
  try: 
    opts, args = getopt.getopt(sys.argv[1:],"hlt:", ["help","listen","time="])
 
  except getopt.GetoptError, err:
    # print help information and exit:
    print str(err) # will print something like "option -a not recognized"
    usage()
    sys.exit(2) 
  listening = False
  timeofday = ''
  for opt, arg in opts:
    if opt in ("-h", "--help"):
      usage()                   
      sys.exit()                 
    elif opt in ("-l", "--listen"):
      listening = True               
    elif opt in ("-t", "--time"):
      timeofday = arg                         
    else:
      assert False, "unhandled option"
 
  number = args[0]         
  msg = args[1]
  if msg != '':
    if timeofday == '':
        sendmessage(number, msg)
    else:
        today = time.strftime('%b %d x %Y', time.localtime())
        schedule = today.replace('x', timeofday)
        schedule_task(schedule, sendmessage, number, msg)
  if listening:
    listen()

This code was tokem from vertsms app.
Maybe it contains unused functions, but it works

thesnake505 2010-09-22 21:53

Re: is it possible to send a text with alarmed?
 
cool man,can u supply it wil simple instructions?

CepiPerez 2010-09-22 21:59

Re: is it possible to send a text with alarmed?
 
Edited #3
Make shure sendsms.py has exec permissions
chmod +x /path/to/sendsms.py

thesnake505 2010-09-22 22:05

Re: is it possible to send a text with alarmed?
 
so i save the script in a file called sendsms.py

save say in my docs so

chmod +x/MyDocs/sendsms.py in alarmed? sorry am a bit of noob!

CepiPerez 2010-09-22 22:08

Re: is it possible to send a text with alarmed?
 
Nop.
Save the file in MyDocs
Then open x-term and type:
chmod +x /home/user/MyDocs/sendsms.py

If you want to try if the script works then in x-term type
/home/user/MyDocs/sendsms.py YOURNUMBER "Test message"

If you receive a message from yourself then it works

thesnake505 2010-09-22 22:19

Re: is it possible to send a text with alarmed?
 
ahh cool man, i got ya, next question

i saved the file (am at work using n900) and its saved as sendsms.py.text, how do i remove the txt from the name?

CepiPerez 2010-09-22 22:31

Re: is it possible to send a text with alarmed?
 
in x-term:
mv /home/user/MyDocs/sendsms.py.txt /home/user/MyDocs/sendsms.py

thesnake505 2010-09-22 22:56

Re: is it possible to send a text with alarmed?
 
ok getting some were i think, other then i now get this

/home/user # /home/user/MyDocs/sendsms.py 07********* "hay"
/bin/sh: /home/user/MyDocs/sendsms.py: Permission denied
/home/user #

CepiPerez 2010-09-22 23:21

Re: is it possible to send a text with alarmed?
 
in x-term:
sudo gainroot
chmod +x /home/user/MyDocs/sendsms.py
chown user:users /home/user/MyDocs/sendsms.py

j.s 2010-09-23 00:08

Re: is it possible to send a text with alarmed?
 
Quote:

Originally Posted by CepiPerez (Post 823927)
in x-term:
sudo gainroot
chmod +x /home/user/MyDocs/sendsms.py
chown user:users /home/user/MyDocs/sendsms.py

Mydocs is a stupid FAT partition. chmod and chown do not work.

/home/user is a better place for this. Maybe /home/use/bin or /home/user/scripts. (May need to create.)

CepiPerez 2010-09-23 00:12

Re: is it possible to send a text with alarmed?
 
Yes I forgot that
I have all my scripts in /home/user/scripts

WhiteWolf 2010-09-29 19:34

Re: is it possible to send a text with alarmed?
 
I tried not to run it gives errors.

The problem is that not send any sms, because recipients do not receive them.

Any ideas?

theonelaw 2011-01-16 10:23

Re: is it possible to send a text with alarmed?
 
Put in /usr/local/sbin
chmod to 755
in xterm:

/usr/local/sbin/sendsms.py 08numeric**** "message"

works for me. thanks all

WhiteWolf 2011-01-16 15:37

Re: is it possible to send a text with alarmed?
 
"sendsms.py" I have never worked

mramkumar7 2011-01-21 20:29

Re: is it possible to send a text with alarmed?
 
in xterm when i try to run it, its saying no such file or directory, this is how i ran it,

Went to the location of sendsms.py (/home/user/SendSchedSMS/)and typed the following

./sendsms.py numericnumber "Message"

No Such File or Directory is what i get

theonelaw 2011-01-22 14:35

Re: is it possible to send a text with alarmed?
 
Quote:

Originally Posted by mramkumar7 (Post 925663)
in xterm when i try to run it, its saying no such file or directory, this is how i ran it,

Went to the location of sendsms.py (/home/user/SendSchedSMS/)and typed the following

./sendsms.py numericnumber "Message"

No Such File or Directory is what i get

Need to move it off /home/user because that is a FAT partition,
best stick it in /usr/sbin maybe, and chmod 755

Someone else may have a better solution,
but that works for me.

danx 2011-01-22 15:02

Re: is it possible to send a text with alarmed?
 
how about e mails , cantbis be done with it .

mramkumar7 2011-01-23 10:12

Re: is it possible to send a text with alarmed?
 
Quote:

Originally Posted by theonelaw (Post 926072)
Need to move it off /home/user because that is a FAT partition,
best stick it in /usr/sbin maybe, and chmod 755

Someone else may have a better solution,
but that works for me.

Even now i am getting the same message... that no such file or directory.

is the syntax right?

./sendsms.py <number> <message inside quotes>

someone help!!!

theonelaw 2011-01-23 10:35

Re: is it possible to send a text with alarmed?
 
Quote:

Originally Posted by mramkumar7 (Post 926598)
Even now i am getting the same message... that no such file or directory.

is the syntax right?

./sendsms.py <number> <message inside quotes>

someone help!!!

Which directory is it in ?

should run it like this:

/usr/local/sbin/sendsms.py <number> <message inside quotes>

or
/whatever/directory/you-put-it-in/sendsms.py <number> <message inside quotes>


DId you chmod it to be executable?

JimBeam 2011-01-23 15:44

Re: is it possible to send a text with alarmed?
 
Hi,

I've tried the script. While it does run, it doesn't seem to send an sms.

I've combined this script and the old script (pymaemosms or some such) into a script that shows some more debug info.
When running it, it completes, but my sms doesn't show up (number formatted as +<countrycode><phonenumber>.
Anyone knows what's going on or how I can troubleshoot some more? (You can use the --verbose argument to show some more details).

Code:

#!/usr/bin/env python2.5
'''
sms.py
Apparently this script required Python 2.5+.
Be careful to save this script with Unix line endings.

see below for source/modification history
'''
def octify(str):
    '''
    Returns a list of octet bytes representing
    each char of the input str.
    '''

    bytes = map(ord, str)
    bitsconsumed = 0
    referencebit = 7
    octets = []

    while len(bytes):
            byte = bytes.pop(0)
            byte = byte >> bitsconsumed

            try:
                    nextbyte = bytes[0]
                    bitstocopy = (nextbyte & (0xff >> referencebit)) << referencebit
                    octet = (byte | bitstocopy)

            except:
                    octet = (byte | 0x00)

            if bitsconsumed != 7:
                    octets.append(byte | bitstocopy)
                    bitsconsumed += 1
                    referencebit -= 1
            else:
                    bitsconsumed = 0
                    referencebit = 7

    return octets

def semi_octify(str):
    '''
    Expects a string containing two digits.
    Returns an octet -
    first nibble in the octect is the first
    digit and the second nibble represents
    the second digit.
    '''
    try:           
            #had to tweak variables for this to work
            digit_1 = 0
            digit_2 = 0
            octet = 0
            #end tweak
            digit_1 = int(str[0])
            digit_2 = int(str[1])
            octet = (digit_2 << 4) | digit_1
    except:
            octet = (1 << 4) | digit_1

    return octet

def formatnumber(number):
        '''
        Adds trailing F to number if length is
        odd (used to be called resetnumber).
        '''
        length = len(number)
        if (length % 2) != 0:
            number = number + 'F'
        return number

def createPDUstring(number, msg):
    '''
    Returns a list of bytes to represent a valid PDU message
    '''
    if verbose == True: print "Debug: message: " + msg
    octifiedmsg = octify(msg)
    if verbose == True:
        print "Debug: octified message: "
        print octifiedmsg
    number = formatnumber(number)
    if verbose == True: print "Debug: formatted number: " + number
    octifiednumber = [ semi_octify(number[i:i+2]) for i in range(0, len(number), 2) ]
    if verbose == True:
        print "Debug: octified number: "
        print octifiednumber

    HEADER = 1
    FIRSTOCTETOFSMSDELIVERMSG = 10
    ADDR_TYPE = 129 #unknown format
    number_length = len(number)
    msg_length = len(msg)
    pdu_message = [HEADER, FIRSTOCTETOFSMSDELIVERMSG, number_length, ADDR_TYPE]
    pdu_message.extend(octifiednumber)
    pdu_message.append(0)
    pdu_message.append(0)
    pdu_message.append(msg_length)
    pdu_message.extend(octifiedmsg)
    return pdu_message

class SMS(object):
    '''
    Sends sms messages
    '''

    def __init__(self, msg, number):
        self.pdustring = createPDUstring(number, msg)

    def send(self):
        self.__dbus_send(self.pdustring)

    def __dbus_send(self, pdu_string):
        import dbus
        bus = dbus.SystemBus()
        smsobject = bus.get_object('com.nokia.phone.SMS', '/com/nokia/phone/SMS/ba212ae1')
        smsiface = dbus.Interface(smsobject, 'com.nokia.csd.SMS.Outgoing')
        arr = dbus.Array(pdu_string)
        msgdeliver = dbus.Array([arr])
        smsiface.Send(msgdeliver,'')

    def print_pdustring(self):
        print self.pdustring

def usage():
    print "Usage:"
    print "sms.py [--timeofday=hh:mm] [--verbose] [number] [message]"
    print "Sends the message to the destination number."
    print ""
    print "If number and message are specified, but no timeofday,"
    print "the sms will be sent immediately."
    print "Example: sms.py +12024561414 ""Hi, Mr. President"""
    print ""
    print "--timeofday (or -t): hour and minute when the message"
    print "must be sent, presumable in 24 hour style???"
    print ""
    print "If message and/or number isn't specified, the program"
    print "will ask you for this."
    print ""
    print "--verbose (or -v) will print debug info"

if __name__ == '__main__':
    '''
    Main function.
    You can either specify destination number and message between double quotes on the command line
    or don't specify anything and let the program ask interactively.
    '''
    import time

    def schedule_task(schedule, fn, *args):
        import sched
        s = sched.scheduler(time.time, time.sleep)
        startTime = time.mktime(time.strptime(schedule, '%b %d %H:%M %Y'))
        s.enterabs(startTime, 0, fn, args)
        s.run()

    def sendsms(number, msg):
        sms = SMS(msg, number)
        #debugging:
        if verbose == True:
            print "Debug: pdustring that will be sent:"
            sms.print_pdustring()
        sms.send()
        print 'Message sent.'

    import getopt, sys
    #getopt may/should? be replaced by argparse, available in python 2.7+
    try:
        # if adding options, modify the parameter after sys.argv to contain all single-character
        # options
        opts, args = getopt.getopt(sys.argv[1:],"htv", ["help","time=","verbose"])
    except getopt.GetoptError, err:
        # print help information and exit:
        print str(err) # will print something like "option -a not recognized"
        usage()
        sys.exit(2)
    # Init timeofday to an empty string. We'll need this later
    # on to test for user specifying timeofday.
    timeofday = ''
    verbose = False
    for opt, arg in opts:
        if opt in ("-h", "--help"):
            usage()
            sys.exit()
        elif opt in ("-t", "--time"):
            timeofday = arg
        elif opt in ("-v", "--verbose"):
            verbose = True
            print "Debug: printing debug output."
        else:
            assert False, "Unhandled option"
            #If this happens, add additional elif clauses above.

    # Get number, message and time of day. If necessary, ask user.
    # If number and message specified on command line, but no time of day,
    # assume you want to send directly so no need for timeofday
    try:
        number = args[0]
    except:
        # probably index out of range because of no arguments.
        # I'm too lazy to find out how to properly count arguments in python,
        # so I'm using exceptions.
        number = ''

    try:
        msg = args[1]
    except:
        # same here.
        msg = ''

    # If number and message specified,
    # but no timeofday, assume we want to
    # send immediately (handy for batch files)
    if number != '' and msg != '' and timeofday == '':
        sendnow = True
    else:
        sendnow = False
    if number == '':
        number = raw_input('Phone number of receiver: ')
    if msg == '':
        msg = raw_input('Message to send: ')

    # Actually send the message:
    if sendnow == False:
      timeofday = raw_input('Time of day to send [Hit enter if you want to send it now]: ')
      today = time.strftime('%b %d x %Y', time.localtime())
      schedule = today.replace('x', timeofday)
      if verbose == True:
          print "Debug: scheduling message for transmission on:"
          print schedule
      schedule_task(schedule, sendsms, number, msg)
    else:
      sendsms(number, msg)

'''
http://talk.maemo.org/showthread.php?t=62754&highlight=sms
sendsms.py
Original filename: pymaemosms or something!?
Sending SMS Using Python Dbus:

I used the following links for reference:
1. http://www.dreamfabric.com/sms/
2. http://www.exothermia.net/monkeys_and_robots/2009/04/24/python-code-to-decode-sms-pdu/
3. http://wiki.maemo.org/Phone_control
4. https://garage.maemo.org/plugins/wiki/index.php?Tools&id=1106&type=g
5. https://garage.maemo.org/plugins/wiki/index.php?CSD%20programming%20information&id=1106&type=g

Additional Notes:
1. Use the dbus-monitor to see dbus communication. Follow link #4 above on how to see the dbus CSD communication log.
2. The phone number is expected to be in semi-octets
3. Each character in the message should be represented as an octet. Refer to this http://www.dreamfabric.com/sms/hello.html link on how to convert a message to octets
'''


JimBeam 2011-01-23 18:44

Re: is it possible to send a text with alarmed?
 
Quote:

Originally Posted by JimBeam (Post 926765)
I've combined this script and the old script (pymaemosms or some such) into a script that shows some more debug info.
When running it, it completes, but my sms doesn't show up (number formatted as +<countrycode><phonenumber>.

Seems it does work if you don't use +<countrycode> as a prefix...

Interesting, wonder whether that depends on your cellular operator or whether the script can be improved?!?!?

mramkumar7 2011-01-24 14:52

Re: is it possible to send a text with alarmed?
 
Quote:

Originally Posted by theonelaw (Post 926609)
Which directory is it in ?

should run it like this:

/usr/local/sbin/sendsms.py <number> <message inside quotes>

or
/whatever/directory/you-put-it-in/sendsms.py <number> <message inside quotes>


DId you chmod it to be executable?

yes i did the same. i even did chmod 777, still getting the same issue

theonelaw 2011-01-24 15:26

Re: is it possible to send a text with alarmed?
 
Quote:

Originally Posted by mramkumar7 (Post 927404)
yes i did the same. i even did chmod 777, still getting the same issue

Assumption on my part, the usual mistake:
Perhaps you need python which I got long ago by installing something
that had a dependency on python.

Am checking now, but I think I got it when I was working on advanced-clock-plugin.

do you have a directory /usr/share/python ?
if you do, then it is probably something else missing

mramkumar7 2011-01-26 10:02

Re: is it possible to send a text with alarmed?
 
Quote:

Originally Posted by theonelaw (Post 927428)
Assumption on my part, the usual mistake:
Perhaps you need python which I got long ago by installing something
that had a dependency on python.

Am checking now, but I think I got it when I was working on advanced-clock-plugin.

do you have a directory /usr/share/python ?
if you do, then it is probably something else missing

yes i do have /usr/share/python

the version is python 2.5

xur17 2011-02-09 01:24

Re: is it possible to send a text with alarmed?
 
Quote:

Originally Posted by JimBeam (Post 926765)
Hi,

I've tried the script. While it does run, it doesn't seem to send an sms.

I've combined this script and the old script (pymaemosms or some such) into a script that shows some more debug info.
When running it, it completes, but my sms doesn't show up (number formatted as +<countrycode><phonenumber>.
Anyone knows what's going on or how I can troubleshoot some more? (You can use the --verbose argument to show some more details).

Code:

#!/usr/bin/env python2.5
'''
sms.py
Apparently this script required Python 2.5+.
Be careful to save this script with Unix line endings.

see below for source/modification history
'''
def octify(str):
    '''
    Returns a list of octet bytes representing
    each char of the input str.
    '''

    bytes = map(ord, str)
    bitsconsumed = 0
    referencebit = 7
    octets = []

    while len(bytes):
            byte = bytes.pop(0)
            byte = byte >> bitsconsumed

            try:
                    nextbyte = bytes[0]
                    bitstocopy = (nextbyte & (0xff >> referencebit)) << referencebit
                    octet = (byte | bitstocopy)

            except:
                    octet = (byte | 0x00)

            if bitsconsumed != 7:
                    octets.append(byte | bitstocopy)
                    bitsconsumed += 1
                    referencebit -= 1
            else:
                    bitsconsumed = 0
                    referencebit = 7

    return octets

def semi_octify(str):
    '''
    Expects a string containing two digits.
    Returns an octet -
    first nibble in the octect is the first
    digit and the second nibble represents
    the second digit.
    '''
    try:           
            #had to tweak variables for this to work
            digit_1 = 0
            digit_2 = 0
            octet = 0
            #end tweak
            digit_1 = int(str[0])
            digit_2 = int(str[1])
            octet = (digit_2 << 4) | digit_1
    except:
            octet = (1 << 4) | digit_1

    return octet

def formatnumber(number):
        '''
        Adds trailing F to number if length is
        odd (used to be called resetnumber).
        '''
        length = len(number)
        if (length % 2) != 0:
            number = number + 'F'
        return number

def createPDUstring(number, msg):
    '''
    Returns a list of bytes to represent a valid PDU message
    '''
    if verbose == True: print "Debug: message: " + msg
    octifiedmsg = octify(msg)
    if verbose == True:
        print "Debug: octified message: "
        print octifiedmsg
    number = formatnumber(number)
    if verbose == True: print "Debug: formatted number: " + number
    octifiednumber = [ semi_octify(number[i:i+2]) for i in range(0, len(number), 2) ]
    if verbose == True:
        print "Debug: octified number: "
        print octifiednumber

    HEADER = 1
    FIRSTOCTETOFSMSDELIVERMSG = 10
    ADDR_TYPE = 129 #unknown format
    number_length = len(number)
    msg_length = len(msg)
    pdu_message = [HEADER, FIRSTOCTETOFSMSDELIVERMSG, number_length, ADDR_TYPE]
    pdu_message.extend(octifiednumber)
    pdu_message.append(0)
    pdu_message.append(0)
    pdu_message.append(msg_length)
    pdu_message.extend(octifiedmsg)
    return pdu_message

class SMS(object):
    '''
    Sends sms messages
    '''

    def __init__(self, msg, number):
        self.pdustring = createPDUstring(number, msg)

    def send(self):
        self.__dbus_send(self.pdustring)

    def __dbus_send(self, pdu_string):
        import dbus
        bus = dbus.SystemBus()
        smsobject = bus.get_object('com.nokia.phone.SMS', '/com/nokia/phone/SMS/ba212ae1')
        smsiface = dbus.Interface(smsobject, 'com.nokia.csd.SMS.Outgoing')
        arr = dbus.Array(pdu_string)
        msgdeliver = dbus.Array([arr])
        smsiface.Send(msgdeliver,'')

    def print_pdustring(self):
        print self.pdustring

def usage():
    print "Usage:"
    print "sms.py [--timeofday=hh:mm] [--verbose] [number] [message]"
    print "Sends the message to the destination number."
    print ""
    print "If number and message are specified, but no timeofday,"
    print "the sms will be sent immediately."
    print "Example: sms.py +12024561414 ""Hi, Mr. President"""
    print ""
    print "--timeofday (or -t): hour and minute when the message"
    print "must be sent, presumable in 24 hour style???"
    print ""
    print "If message and/or number isn't specified, the program"
    print "will ask you for this."
    print ""
    print "--verbose (or -v) will print debug info"

if __name__ == '__main__':
    '''
    Main function.
    You can either specify destination number and message between double quotes on the command line
    or don't specify anything and let the program ask interactively.
    '''
    import time

    def schedule_task(schedule, fn, *args):
        import sched
        s = sched.scheduler(time.time, time.sleep)
        startTime = time.mktime(time.strptime(schedule, '%b %d %H:%M %Y'))
        s.enterabs(startTime, 0, fn, args)
        s.run()

    def sendsms(number, msg):
        sms = SMS(msg, number)
        #debugging:
        if verbose == True:
            print "Debug: pdustring that will be sent:"
            sms.print_pdustring()
        sms.send()
        print 'Message sent.'

    import getopt, sys
    #getopt may/should? be replaced by argparse, available in python 2.7+
    try:
        # if adding options, modify the parameter after sys.argv to contain all single-character
        # options
        opts, args = getopt.getopt(sys.argv[1:],"htv", ["help","time=","verbose"])
    except getopt.GetoptError, err:
        # print help information and exit:
        print str(err) # will print something like "option -a not recognized"
        usage()
        sys.exit(2)
    # Init timeofday to an empty string. We'll need this later
    # on to test for user specifying timeofday.
    timeofday = ''
    verbose = False
    for opt, arg in opts:
        if opt in ("-h", "--help"):
            usage()
            sys.exit()
        elif opt in ("-t", "--time"):
            timeofday = arg
        elif opt in ("-v", "--verbose"):
            verbose = True
            print "Debug: printing debug output."
        else:
            assert False, "Unhandled option"
            #If this happens, add additional elif clauses above.

    # Get number, message and time of day. If necessary, ask user.
    # If number and message specified on command line, but no time of day,
    # assume you want to send directly so no need for timeofday
    try:
        number = args[0]
    except:
        # probably index out of range because of no arguments.
        # I'm too lazy to find out how to properly count arguments in python,
        # so I'm using exceptions.
        number = ''

    try:
        msg = args[1]
    except:
        # same here.
        msg = ''

    # If number and message specified,
    # but no timeofday, assume we want to
    # send immediately (handy for batch files)
    if number != '' and msg != '' and timeofday == '':
        sendnow = True
    else:
        sendnow = False
    if number == '':
        number = raw_input('Phone number of receiver: ')
    if msg == '':
        msg = raw_input('Message to send: ')

    # Actually send the message:
    if sendnow == False:
      timeofday = raw_input('Time of day to send [Hit enter if you want to send it now]: ')
      today = time.strftime('%b %d x %Y', time.localtime())
      schedule = today.replace('x', timeofday)
      if verbose == True:
          print "Debug: scheduling message for transmission on:"
          print schedule
      schedule_task(schedule, sendsms, number, msg)
    else:
      sendsms(number, msg)

'''
http://talk.maemo.org/showthread.php?t=62754&highlight=sms
sendsms.py
Original filename: pymaemosms or something!?
Sending SMS Using Python Dbus:

I used the following links for reference:
1. http://www.dreamfabric.com/sms/
2. http://www.exothermia.net/monkeys_and_robots/2009/04/24/python-code-to-decode-sms-pdu/
3. http://wiki.maemo.org/Phone_control
4. https://garage.maemo.org/plugins/wiki/index.php?Tools&id=1106&type=g
5. https://garage.maemo.org/plugins/wiki/index.php?CSD%20programming%20information&id=1106&type=g

Additional Notes:
1. Use the dbus-monitor to see dbus communication. Follow link #4 above on how to see the dbus CSD communication log.
2. The phone number is expected to be in semi-octets
3. Each character in the message should be represented as an octet. Refer to this http://www.dreamfabric.com/sms/hello.html link on how to convert a message to octets
'''


Is it okay if I use this for a small program I am writing?


All times are GMT. The time now is 08:48.

vBulletin® Version 3.8.8