×

Discussion Board

Results 1 to 8 of 8
  1. #1
    Registered User
    Join Date
    May 2008
    Posts
    15

    bluetooth: retrieving asynchronous data

    Hi everyone,

    Im starting to program in Python with a Nokia N95, and I would like to have some tips. I want basically retrieve Data through a Bluetooth connection but asynchronously. I want to be able to do whatever while im not receiving any data, but if one comes, i stop what im doing and i get the data. Ive been use to program microcontroller, etc... and u can do that very easily with interruption.

    But in python, on symbian system, thats totally different, Ive been reading a lot about Twisted, Asyncore, or select() to use either asynchronous socket, or thread. But i still didnt figure out how to do that, and with Bluetooth. If someone could light this up and help me that would be great.

    Cheers,
    Fran

  2. #2
    Regular Contributor
    Join Date
    Aug 2004
    Posts
    295

    Re: bluetooth: retrieving asynchronous data

    Get started on pys60, play with example programs. Using bluetooth socket is similar to using regular tcp socket.

    This might be bit confusing. So just get it started. Make a simplest program receiving/sending data, after that lets see further.

    You must likely cant use twisted, asyncore or select on pys60, but in practice this might not be a problem.

  3. #3
    Registered User
    Join Date
    May 2008
    Posts
    15

    Re: bluetooth: retrieving asynchronous data

    Hey simo!
    I already started!! But I didnt show my code, that's why I asked how could I get further, I already communicate with my pc, but in a synchronous way...

    Using Tcp socket wont help so much, because Ive never really done that, it's just that i do not know where to start with the asynchronous thing, like what should i create, which properties, etc... There is plenty of things on google, its just not so clear what i need and what i dont.


    Thanks!!

    fran

    Here is my simple code...

    Code:
    #Api importations
    import e32 
    import appuifw
    import TopWindow
    import graphics
    import socket
    #Functions implementation
    
    	#Exit the script
    
    def quit():
    	print "Socket closed"
    	try:
    		sock.close()
    	except NameError:
    		appuifw.note(u"Bluetooth connection not opened.","info")
    	window.hide()
    	app_lock.signal()
    
    	#Choose the service
    
    def choose_service(services):
    	names=[]
    	channels=[]
    	for name, channel in services.items():
    		names.append(name)
    		channels.append(channel)
    	index=appuifw.popup_menu(names,u"Choose service")
    	return channels[index]
    
    	#Connect to a peripherique
    	
    def connect():
    	global sock
    	#adress, services=socket.bt_discover()
    	#print(adress)
    	#channel=choose_service(services)
    	#print(channel)
    	sock=socket.socket(socket.AF_BT, socket.SOCK_STREAM)
    	sock.connect(('00:0e:9b:d9:5d:a2',1))	
    
    def receive():
    	global sock
    	data=sock.recv(1)
    	if data=="1":
    		appuifw.note(u"I receive 1","info")
    	elif data=="0":
    		appuifw.note(u"I received 0","info")
    		
    def bt_send_data():
    	sock.send("Message sent!")
    	receive()
    	
    #Code implementation
    global sock
    appuifw.app.menu=[(u"Send message",bt_send_data),
    				(u"Connect",connect)]
    appuifw.app.screen="large"
    
    #Start
    app_lock=e32.Ao_lock()
     
    appuifw.app.exit_key_handler=quit
    #End
    app_lock.wait()

  4. #4
    Nokia Developer Champion
    Join Date
    Feb 2008
    Location
    Ahmedabad, Gujarat, India
    Posts
    3,852

    Re: bluetooth: retrieving asynchronous data

    Quote Originally Posted by qcalv View Post
    Hi everyone,

    Im starting to program in Python with a Nokia N95, and I would like to have some tips. I want basically retrieve Data through a Bluetooth connection but asynchronously. I want to be able to do whatever while im not receiving any data, but if one comes, i stop what im doing and i get the data. Ive been use to program microcontroller, etc... and u can do that very easily with interruption.

    But in python, on symbian system, thats totally different, Ive been reading a lot about Twisted, Asyncore, or select() to use either asynchronous socket, or thread. But i still didnt figure out how to do that, and with Bluetooth. If someone could light this up and help me that would be great.

    Cheers,
    Fran
    hi Fran
    welcome to the python dibo please have a look at this
    hope this will help you.
    have a ffedback

  5. #5
    Registered User
    Join Date
    May 2008
    Posts
    15

    Re: bluetooth: retrieving asynchronous data

    Hi gaba88,

    This is already what I did in the code, but the thing is that I do not want to receive the Data only when I call the function receive() but at any time. I want to do different operations in the main loop, and I want a sort of thread (Im not sure if this is what i need) in the background taking care of any incoming Data on the bluetooth port. Is it possible?

    fran

  6. #6
    Nokia Developer Champion
    Join Date
    Feb 2008
    Location
    Ahmedabad, Gujarat, India
    Posts
    3,852

    Re: bluetooth: retrieving asynchronous data

    Quote Originally Posted by qcalv View Post
    Hi gaba88,

    This is already what I did in the code, but the thing is that I do not want to receive the Data only when I call the function receive() but at any time. I want to do different operations in the main loop, and I want a sort of thread (Im not sure if this is what i need) in the background taking care of any incoming Data on the bluetooth port. Is it possible?

    fran
    hi fran again
    why dont you make your function run in a loop.

  7. #7
    Registered User
    Join Date
    May 2008
    Posts
    15

    Re: bluetooth: retrieving asynchronous data

    hi fran again
    why dont you make your function run in a loop.
    Well, I dont like it. For my application, I still dont know if i will have a global loop or not, and I prefer to use background process rather than a global loop. Of course, if I have to, like if it doesnt make any sense to create a thread, then Ill do that.

    But I want to be sure, there is no other way to do it, , thanks though.

    fran

  8. #8
    Regular Contributor
    Join Date
    Mar 2008
    Posts
    151

    Re: bluetooth: retrieving asynchronous data

    I think we're having a parallel discussion on this thread

    As far as I can see there doesn't seem to be an easy way for a function to spring to life whenenver the bt socket receives some data. In VB for example I use:

    Private Sub DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles serialPort.DataReceived

Similar Threads

  1. Nokia 5200 Bluetooth data transfer when pairing
    By bernard2001 in forum General Development Questions
    Replies: 3
    Last Post: 2007-10-26, 11:27
  2. Asynchronous Bluetooth GPS reading
    By conos in forum Mobile Java Networking & Messaging & Security
    Replies: 7
    Last Post: 2007-08-21, 12:46
  3. Closing bluetooth socket AFTER all data has been sent
    By tumppi in forum Symbian Networking & Messaging (Closed)
    Replies: 2
    Last Post: 2007-07-09, 13:28
  4. suckho, i have encontered the same problems. Could you tell me how you resolved it?
    By dicson_hu in forum Symbian Networking & Messaging (Closed)
    Replies: 4
    Last Post: 2005-12-09, 10:56
  5. GPRS connection problems on 6600..
    By suckho in forum Symbian Networking & Messaging (Closed)
    Replies: 10
    Last Post: 2005-12-02, 14:00

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×