| Reply | « Previous Thread | Next Thread » |
|
Hi,
I'm attempting to transfer files autonomously between two mobiles via Bluetooth, without the user controlling the process. Basically Mobile1 searches for Mobile2, and once Mobile2 is within range, Mobile1 will transfer the file to Mobile2, and Mobile2 will save it. The mobiles are paired Nokia 6630s. As you can probably tell I haven't had much experience with PyS60, I'm following Jurgen Scheible's Mobile Python book and found an example for taking and sending photos with Bluetooth: import camera, e32, socket, appuifwIt works so far, but I just wanted to know if there's any way to adapt this code so that it sends a specific file stored on the phone, instead of taking a photo? And how can I make the receiving phone save this file automatically? Is this even possible? Any advice or examples you can give would be very much appreciated. Thank you! |
|
Join Date: Feb 2008
Posts: 2,546
Location: Bhavnagar, Gujarat, India
gaba88
Offline
Forum Nokia Champion
|
|
hi aubregine
first of all a warm welcome to the forum nokia PyS60 discussion board. ![]() your code looks good but please note that from the next time you put some code use the quote marki.e. # provided in the tool bar. so we can observe the code more exactly ![]() Gargi Das- http://gargidas.blogsot.com Forum Nokia Python Wiki Learn Python at http://mobapps.org/PyS60 |
|
Quote:
![]() In your code take_photo() is responsible for taking a photo. If you just require to send the file (Already exisiting picture) on your phone just don't use or call the function, And accordingly have only one option to send photo (You can add more functions if you require ofcourse. Quote:
Quote:
Hope that helps, Br, Croozeus |
|
Hi, thanks very much for the welcome! Btw croozeus, it's such a coincidence that you replied because I was searching online yesterday for related tutorials and found your socket module examples. So I've modified your "Transfer File through OBEX" example very slightly so that it sends a photo instead. I also paired and authorized the phones as you recommended, and that works, so thanks for that. Here's the code:
Server File Code:
# This script lets 2 phones exchange a file via OBEX.
# This is the server, the corresponding client is obex_client.py
from socket import *
import appuifw
# Create a bluetooth socket in waiting state to be connected to
s = socket(AF_BT, SOCK_STREAM)
port = bt_rfcomm_get_available_server_channel(s)
print "Binding service to port %s"%port
s.bind(("", port))
print "Service bound."
# Advertise the OBEX service, so it can be seen by other phones
service_name=u"Test OBEX service"
print "Advertising service as %s"%repr(service_name)
bt_advertise_service(service_name, s, True, OBEX)
try:
print "Setting security to AUTH."
set_security(s, AUTH)
receive_path = u"e:\\Photo 1.jpg"
print "Receiving file."
bt_obex_receive(s, receive_path)
print "File received."
import e32
e32.ao_sleep(1)
finally:
print "Stopping service advertising."
bt_advertise_service(service_name, s, False, OBEX)
print "Closing socket."
s.close()
print "Socket closed."
print "Finished."
Code:
# this file lets 2 phones exchange a file via OBEX
# this file is the client side
# the corresponding server side file is called obex_server.py
from socket import *
import appuifw
import e32
# JL: you don't need a socket for this!
## create socket
#s=socket(AF_BT,SOCK_STREAM)
# scan for other phones offering OBEX service
addr,services=bt_obex_discover()
print "Discovered: %s, %s"%(addr,services)
if len(services)>0:
choices=services.keys()
choices.sort()
choice=appuifw.popup_menu([unicode(services[x])+": "+x
for x in choices],u'Choose port:')
port=services[choices[choice]]
else:
port=services[services.keys()[0]]
address=(addr,port)
# create file to be sent
send_path = u"e:\\Photo 1.jpg"
# send file via OBEX
print "Sending file %s to host %s port %s"%(send_path, address[0], address[1])
bt_obex_send_file(address[0], address[1], send_path)
print "File sent."
Again, thanks in advance for any advice and help you can give... |
|
Join Date: Feb 2008
Posts: 2,546
Location: Bhavnagar, Gujarat, India
gaba88
Offline
Forum Nokia Champion
|
|
hi aubregine
i think its really easy. change the code in the client side to this in place of Code:
address=(addr,port) hope this will work for you. Gargi Das- http://gargidas.blogsot.com Forum Nokia Python Wiki Learn Python at http://mobapps.org/PyS60 |
|
Thanks so much to everyone for your help, finally managed to get it working! So now the files transfer and save automatically once you run the script. Just need to specify the target address and port. I know it's quite basic for most of you, but thought some other beginners out there might find it helpful, so here's the code...
Client Code:
# this script lets 2 phones exchange a file via OBEX # this file is the client side from socket import * # define target device target = "00:00:00:00:00:00" # specify file to be sent send_path = u"e:\\Images\Photo 1.jpg" # send file via OBEX print "Sending file %s to host %s port %s"%(send_path, str(target), 4) bt_obex_send_file(str(target), 4, send_path) print "File sent." Code:
# this script lets 2 phones exchange a file via OBEX
# this file is the server
from socket import *
import appuifw
# create a bluetooth socket in waiting state to be connected to
s = socket(AF_BT, SOCK_STREAM)
port = bt_rfcomm_get_available_server_channel(s)
print "Binding service to port %s"%port
s.bind(("", port))
print "Service bound."
# advertise the OBEX service, so it can be seen by other phones
service_name = u"Test OBEX service"
print "Advertising service as %s"%repr(service_name)
bt_advertise_service(service_name, s, True, OBEX)
try:
print "Setting security to AUTH."
set_security(s, AUTH)
receive_path = u"e:\\Images\Photo 1.jpg"
print "Receiving file."
bt_obex_receive(s, receive_path)
print "File received."
import e32
e32.ao_sleep(1)
finally:
print "Stopping service advertising."
bt_advertise_service(service_name, s, False, OBEX)
print "Closing socket."
s.close()
print "Socket closed."
print "Finished."
|
|
Join Date: Feb 2008
Posts: 2,546
Location: Bhavnagar, Gujarat, India
gaba88
Offline
Forum Nokia Champion
|
|
hi aubregine
its great that you have completed it. for further reference of everybody i have put the code in a wiki article here. have a look at that and dont forget you can edit that article also. ![]() ![]() Gargi Das- http://gargidas.blogsot.com Forum Nokia Python Wiki Learn Python at http://mobapps.org/PyS60 |
|
hi, I cannot get it working. I was using N73 as server and E71 as client, log on client shows the server and service was discovered correctly, but the bt_obex_send_file raised an exception: 32,'broken pipe'. I checked both the address and port used on the client side are compliant with the server side.
Any idea? |
| Reply | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|
| Rate This Thread | |
| Thread | Thread Starter | Forum | Replies | Last Post |
|---|---|---|---|---|
| sending vcal files to Nokia N90 | tomhodder | General Messaging | 1 | 2006-07-27 13:44 |
| Sending multiple files over bluetooth from phone to PC | dguldbrandsen | Symbian Networking & Messaging | 4 | 2005-01-30 10:55 |
| Problems in sending files to the server | yuava | Other Programming Discussion 关于其他编程技术的讨论 | 4 | 2005-01-08 14:53 |
| Sending several files without using SIS | stopin | General Symbian C++ | 0 | 2003-07-10 17:32 |
| Sending Files via Bluetooth | mike456 | Bluetooth Technology | 1 | 2002-09-05 08:48 |