i am having this problem related to function implementation. my program is about sending an unread sms string to a bluetooth module and after sending the strings of sms messages it will mark the unread messages as read then move to a sms notification function that will notify me is there is an incoming sms messages after that the unread message will be sent to the bluetooth module as string again and mark the unread message as read. this is the problem after sending the sms string it does not do the function of marking the sms as read anymore hope somebody will help me here.

here is the flow of program that must be implemented:
Bluetooth>send unread sms string to BT>mark read>sms notification[if there is incoming sms]>send unread sms string to BT>mark read> then the cycle goes but i have a problem succeeding mark read.

here is the code:

import appuifw
import socket
import e32
import inbox,string
from time import ctime
import codecs
import os
import e32
from appuifw import *
import bluetooth

inb = inbox.Inbox()
sms_ids = inb.sms_messages()
msgs = []
msg_unread = []
msg_read = []


def bt_connect():
global sock
sock=socket.socket(socket.AF_BT,socket.SOCK_STREAM)
target=''
if not target:
address,services=socket.bt_discover()
print "Discovered: %s, %s"%(address,services)
if len(services)>1:
import appuifw
choices=services.keys()
choices.sort()
choice=appuifw.popup_menu([unicode(services[x])+": "+x
for x in choices],u'Choose port:')
target=(address,services[choices[choice]])
else:
target=(address,services.values()[0])
print "Connecting to "+str(target)
sock.connect(target)
print "OK."

bt_sendtext()

def bt_sendtext():
global sock

box=inbox.Inbox()
id=box.sms_messages()

for item in id:
if box.unread(item):
j=box.address(item)
d=(u'from '+j+' ')[:160]
print d
b=box.content(item)
c=(b+'\0')[:160]
print c
sock.send(d)
sock.send(c)

markread()

smsnoti()

def markread():
inb = inbox.Inbox()
sms_ids = inb.sms_messages()
for id in :
msgs.append(inb.content(id))

def setreadunread(message, status):
global msgs
i = 0
for msg in msgs:
if message == msg:
if status == 1:
inb.set_unread(sms_ids,1)
else:
inb.set_unread(sms_ids,0)
i = i+1

def get_readandunreadmessages_inlist():
global msg_unread
global msg_read
msg_unread = []
msg_read = []
for id in sms_ids:
if inb.unread(id):
msg_unread.append(inb.content(id))
else:
msg_read.append(inb.content(id))


def setmessageread():
global msg_unread
get_readandunreadmessages_inlist()
try:
i=0
while (i != msg_unread):
setreadunread(msg_unread, 0)
i=i+1
except IndexError, e:
print "Done"

def showmessagestatus():
global sms_ids
for id in sms_ids:
print inb.content(id)[:20]
print inb.unread(id)


def smsnoti():
def message(msgid):
box = inbox.Inbox()
bt_sendtext()
app_lock.signal()

box = inbox.Inbox()
box.bind(message)

app_lock = e32.Ao_lock()
app_lock.wait()

appuifw.app.title = u"bt mob to PC"
bt_connect()

here is the code pls help me

Attachments
import appuifw
import socket
import e32
import inbox,string
from time import ctime
import codecs
import os
import e32
from appuifw import *
import bluetooth

inb = inbox.Inbox()
sms_ids = inb.sms_messages()
msgs = []
msg_unread = []
msg_read = []


def markread():

    for id in sms_ids:
        msgs.append(inb.content(id))

    def setreadunread(message, status):
        global msgs
        i = 0
        for msg in msgs:
            if message == msg:
                if status == 1:
                    inb.set_unread(sms_ids[i],1)
                else:
                    inb.set_unread(sms_ids[i],0)      
            i = i+1                                
            
    def get_readandunreadmessages_inlist():
        global msg_unread
        global msg_read
        msg_unread = []
        msg_read = []
        for id in sms_ids:
            if inb.unread(id):
                msg_unread.append(inb.content(id))
            else:
                msg_read.append(inb.content(id))

    def setmessageread():
        global msg_unread
        get_readandunreadmessages_inlist() 
        try:
            i=0
            while (i != msg_unread):
                setreadunread(msg_unread[i], 0)
                i=i+1
            #print "Done"
        except IndexError, e:
            print "Done"

    setmessageread()


def smsnoti():
    # Give note on new message
    def message(msgid):
        box = inbox.Inbox()
        appuifw.note(u"A new message:\n %s" % box.content(msgid))
        bt_sendtext()
        app_lock.signal()

    # bind inbox to new message event
    box = inbox.Inbox()    
    
    box.bind(message)
     
    #Wait for Exit
    app_lock = e32.Ao_lock()
    app_lock.wait()

def bt_connect():
    global sock
    sock=socket.socket(socket.AF_BT,socket.SOCK_STREAM)
    target=''
    if not target:
        address,services=socket.bt_discover()
        print "Discovered: %s, %s"%(address,services)
        if len(services)>1:
            import appuifw
            choices=services.keys()
            choices.sort()
            choice=appuifw.popup_menu([unicode(services[x])+": "+x
                                        for x in choices],u'Choose port:')
            target=(address,services[choices[choice]])
        else:
            target=(address,services.values()[0])
    print "Connecting to "+str(target)
    sock.connect(target)
    print "OK."

    bt_sendtext()
    
#def sms():
#    box=inbox.Inbox()
#    id=box.sms_messages()
 
#    for item in id:
#        if box.unread(item):
#            j=box.address(item)
#            d=(u'from '+j+'\n')
#            print d
#            b=box.content(item)
#            c=(b+'\n')
#            print c
        
def bt_sendtext():
    global sock
    
    box=inbox.Inbox()
    id=box.sms_messages()
 
    for item in id:
        if box.unread(item):
            j=box.address(item)
            d=(u'from '+j+' ')[:160]
            print d
            b=box.content(item)
            c=(b+'\0')[:160]
            print c
            sock.send(d)
            sock.send(c)

    markread()
    
    smsnoti()    
#        try:
#            for d in item:
#                print d
#            for c in item:
#                print c
#        finally:
#            f.close()
#            add = d
#            inb = c



#def exit_key_handler():
#    script_lock.signal()
#    appuifw.app.set_exit()

appuifw.app.title = u"bt mob to PC"

#script_lock = e32.Ao_lock()

#appuifw.app.exit_key_handler = exit_key_handler()

bt_connect()

#script_lock.wait()

I recommend that you place print statements in various places in your code, so that you can find the actual place of the issue. It may not be the function that is not working, it could be one of your if() statements or whatever. Work through your code, so that you can work out if you actually get to the right place in the code.

Hope this makes sense
SgtMe

This article has been dead for over six months. Start a new discussion instead.