Comunicação Bluetooth Entre Python e PyS60

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    Favorites, Groups & Events

    Comunicação Bluetooth Entre Python e PyS60 - Presentation Transcript

    1. Felipe Ronchi Brigido Contato: lipaun@gmail.com Comunicação Bluetooth entre Python / PyS60 * PyBluez -> pybluez.googlecode.com * Socket (Pys60) -> www.mobilenin.com * LightBlue -> lightblue.sourceforge.net --> www.btessentials.com **chat_cel.py** import socket import appuifw print 'Estabelecendo socket' sock = socket.socket(socket.AF_BT, socket.SOCK_STREAM) print 'Reservando porta' porta = socket.bt_rfcomm_get_available_server_channel(sock) sock.bind((\"\", porta)) sock.listen(1) print 'Estabelecendo servico' socket.bt_advertise_service(u\"EXEMPLO PYCON 2008\", sock, True, socket.RFCOMM) print 'Aguardando conexao' conexao, endereco = sock.accept() print 'Conexao estabelecida com %s na porta %s'% (endereco, porta) print 'Iniciando chat!' conexao.send('Iniciando chat!') try: while True: msg = conexao.recv(1024) msg = unicode(msg) conexao.send(appuifw.query(msg, 'text', u'')) except: pass socket.bt_advertise_service(u\"EXEMPLO PYCON 2008\", sock, False, socket.RFCOMM) sock.close() conexao.close() print \"Conexao finalizada\"
    2. **chat_pc.py** import bluetooth # - Busca de dispositivos while True: print 'Buscando dispositivos' dispositivos = bluetooth.discover_devices(lookup_names = True) print 'Dipositivos encontrados:' for disp in dispositivos: print '%s | %s' % (dispositivos.index(disp), disp[1]) num = raw_input('Digite o numero do dispositivo a conectar: ') try: num = int(num) break except: pass endereco = dispositivos[num][0] # - Busca de servicos while True: print 'Buscando servicos' servicos = bluetooth.find_service(address = endereco) print 'Servicos encontrados:' for servico in servicos: print '%s | %s - %s' % (servicos.index(servico), servico['port'], servico['name']) srv = raw_input('Digite o numero do servico a conectar: ') try: srv = int(srv) break except: pass porta = servicos[srv]['port'] print 'Estabelecendo socket.' sock = bluetooth.BluetoothSocket( bluetooth.RFCOMM ) print \"Conectando a %s na porta %s\" % (endereco, porta) sock.connect((endereco, porta)) try: while True: msg = raw_input(sock.recv(1024) + '\\n>>> ') if msg == '': break sock.send(msg) except: pass sock.close() print \"Conexao finalizada\"
    3. **chat_cel_light.py** import lightblue import appuifw print 'Estabelecendo socket' sock = lightblue.socket() print 'Reservando porta' sock.bind(('', 0)) sock.listen(1) print 'Establecendo servico' lightblue.advertise(\"EXEMPLO PYCON 2008\", sock, lightblue.RFCOMM) print 'Aguardando conexao' conexao, endereco = sock.accept() print 'Conexao estabelecida com %s na porta %s'% (endereco[0], endereco[1]) print 'Iniciando chat!' conexao.send('Iniciando chat!') try: while True: msg = conexao.recv(1024) msg = unicode(msg) conexao.send(appuifw.query(msg, 'text', u'')) except: pass lightblue.stopadvertise(sock) sock.close() conexao.close() print \"Conexao finalizada\" **chat_pc_light.py** import lightblue print 'Buscando servico' servico = lightblue.selectservice() print 'Estebelecendo socket.' sock = lightblue.socket() print 'Conectando ao servico de %s' % servico[2] sock.connect((servico[0], servico[1])) try: while True: msg = raw_input(sock.recv(1024) + '\\n>>> ') if msg == '': break sock.send(msg) except: pass sock.close() print \"Conexao finalizada\"

    + Felipe Ronchi BrigidoFelipe Ronchi Brigido, 2 years ago

    custom

    457 views, 0 favs, 0 embeds more stats

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 457
      • 457 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 0
    • Downloads 14
    Most viewed embeds

    more

    All embeds

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories