leviaeon 0 Newbie Poster

Hello guys,
I am implementing this code that will transfer a string from mobile to a bluetooth device. I have already done the extraction of sms from the inbox and then save it as a text file by the way I am using nokia 6600 as a test phone. Then after that I establish bluetooth connection now here goes the problem I cant send a string to the bluetooth to be transmitted to our bluetooth module that uses LMX9830. the problem is in the function sendstr() that I am currently working on. hope someone will help me on this. thanks in advance.

code:

import sys
import socket
import inbox,string
from time import ctime
import codecs
import os
import e32


def sms():
box=inbox.Inbox()
id=box.sms_messages()

for item in id:
if box.unread(item):
b=box.content(item)
j=str(box.address(item))
f = codecs.open('E:/BackupSMS/SMS'+ j +'.txt','w', 'utf8') #Here You can use j in place of a if you want random no as names of files generated
f.write(box.address(item))
f.write('\n')
f.write(ctime(box.time(item)))
f.write('\n')
f.write(box.content(item))
f.write('\n')
f.close()


def bt_connect():
global script_lock
global sock
sock=socket.socket(socket.AF_BT,socket.SOCK_STREAM)
target=''
if not target:
address,services=socket.bt_discover()
if len(services)>1:
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])

sock.connect(target)
script_lock.wait()

def sendstr():
f = open(u'E:\\BackupSMS\\SMSLou.txt', 'rb')
s = str(f)
s.read()
sock.send(s.read())

script_lock.wait()

global script_lock
script_lock = e32.Ao_lock()
sms()
bt_connect()
sendstr()

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.