Notices


Reply
Thread Tools
Posts: 15 | Thanked: 1 time | Joined on Mar 2008
#41
Hi! Tested myself too that Python app and gotta say that I loved it, it worked well! Thank you very much
 
Posts: 20 | Thanked: 1 time | Joined on Jan 2010 @ The Netherlands
#42
Originally Posted by pende View Post
Hi there,

I added some code and now you are able to send sms and receive a reply. Code is available for download here http://ztbsauer.com/sender.py

For now it replies only for one command but feel free to expand it for own needs.
Hi pende, I tried your code but it doesn't work. If I run it and send an sms (with "ping" ) to the device, I receive the sms and on stdout it shows:

New message received from +xxxxxxxxxxx
Message length 4
Message: ping
Sending reply: pong

But I don't receive the "pong" message on my other mobile.

In the code, I see that you replace the '+' by "00"; adding that to my phone number (above obfuscated with x-es) gives a total number of 13 digits. Is the odd number still a problem? If so, how can I resolve this?
 
Posts: 451 | Thanked: 334 times | Joined on Sep 2009
#43
Originally Posted by pende View Post
I added some code and now you are able to send sms and receive a reply. Code is available for download here http://ztbsauer.com/sender.py
This might be a daft question, but never worked with python before...

How do you initiate a function in the python file.

I.e. I see that the default with sender.py is listen. How do I run the sendmessage with number and text from CLI?
 
zoner's Avatar
Posts: 74 | Thanked: 38 times | Joined on Feb 2010
#44
<hijack>

Originally Posted by 白い熊 View Post
I'm asking since I already programmed elisp code for Emacs's BBDB to initiate calling, and automatically record, who you've called etc. including the call time to BBDB database
could you please (in another thread) discuss your setup for dialing with bbdb?

</hijack>
 
Posts: 451 | Thanked: 334 times | Joined on Sep 2009
#45
Originally Posted by pende View Post
Hi there,
I added some code and now you are able to send sms and receive a reply. Code is available for download here http://ztbsauer.com/sender.py
I modified
Code:
if __name__ == '__main__':
        listen()
to
Code:
if __name__ == '__main__':
        sendmessage("+XXXXXXXX", "Test")

to test it, but nothing gets sent... Where's the problem?
 
Posts: 451 | Thanked: 334 times | Joined on Sep 2009
#46
Originally Posted by zoner View Post
could you please (in another thread) discuss your setup for dialing with bbdb?
I'll release the full elisp code once I get this SMS stuff settled, can't get it to work so far.
 
Posts: 451 | Thanked: 334 times | Joined on Sep 2009
#47
A programmer has modified the script for me to accept commandline arguments, to send an SMS, so:
Code:
#!/usr/bin/python

import dbus
import sys

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 resetnumber(number):
        '''
        Adds trailing F to number if length is
        odd.
        '''
        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
    '''
    octifiedmsg = octify(msg)
    number = resetnumber(number)
    octifiednumber = [ semi_octify(number[i:i+2]) for i in range(0, len(number), 2) ]
        
    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        

if __name__ == "__main__":
    if len(sys.argv) != 3:
        print "usage %s number message" % sys.argv[0]
    else:
        sms = SMS(sys.argv[2], sys.argv[1])
        sms.send()
        print "sending sms..."
However, when you use an international format with the leading plus like: "+XXX" for the number, it bombs with:
Code:
Traceback (most recent call last):
  File "./send_sms.py", line 114, in <module>
    sms = SMS(sys.argv[2], sys.argv[1])
  File "./send_sms.py", line 93, in __init__
    self.pdustring = createPDUstring(number, msg)
  File "./send_sms.py", line 72, in createPDUstring
    octifiednumber = [ semi_octify(number[i:i+2]) for i in range(0,
  len(number), 2) ]
  File "./send_sms.py", line 52, in semi_octify
    octet = (1 << 4) | digit_1
UnboundLocalError: local variable 'digit_1' referenced before assignment
When you use two leading zeros like "00XXXX..." it doesn't bomb, but the SMS is not received, therefore probably not sent.

It seems the problem is with the PDU encoding. Anyone got the above (prior) script to actually send an SMS? Where is the problem?
 
Posts: 451 | Thanked: 334 times | Joined on Sep 2009
#48
It seems the fault is definitely with this PDU encoding process. Isn't there a possibility to forward the text and number to internal Nokia PDU encoding and SMS sending routine, if there is such a thing? I.e. telepathy etc. Have been reading up through telepathy documents, but don't know how to send an SMS through its API.
 
Posts: 226 | Thanked: 47 times | Joined on Jan 2008 @ Poland / Bialystok
#49
Just thinking - is there any /dev/tty... interface inside OS to communicate with GSM engine using AT commands?
If such port exists, sending SMS should be rather straightforward.
 

The Following 2 Users Say Thank You to XTC For This Useful Post:
Posts: 451 | Thanked: 334 times | Joined on Sep 2009
#50
Of course, you're my man, there's pnatd for communicating with the modem. OK, no to check how to send plain text SMSes via AT commands. Do you know how to do this?
 
Reply

Thread Tools

 
Forum Jump


All times are GMT. The time now is 22:27.