SlideShare uma empresa Scribd logo
1 de 3
Baixar para ler offline
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((quot;quot;, porta))
   sock.listen(1)

   print 'Estabelecendo servico'
   socket.bt_advertise_service(uquot;EXEMPLO PYCON 2008quot;, 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(uquot;EXEMPLO PYCON 2008quot;, sock, False, socket.RFCOMM)
   sock.close()
   conexao.close()
   print quot;Conexao finalizadaquot;
**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 quot;Conectando a %s na porta %squot; % (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 quot;Conexao finalizadaquot;
**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(quot;EXEMPLO PYCON 2008quot;, 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 quot;Conexao finalizadaquot;




**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 quot;Conexao finalizadaquot;

Mais conteúdo relacionado

Destaque

Prima vista 2012 kohta
Prima vista 2012 kohtaPrima vista 2012 kohta
Prima vista 2012 kohta
Papitrolla
 
This is binding - the idea
This is binding - the ideaThis is binding - the idea
This is binding - the idea
Hakim Albasrawy
 
Students Comments Anna
Students Comments AnnaStudents Comments Anna
Students Comments Anna
tina_wilkinson
 

Destaque (20)

Gamification - Are you a player in the brand engagement game?
Gamification - Are you a player in the brand engagement game?Gamification - Are you a player in the brand engagement game?
Gamification - Are you a player in the brand engagement game?
 
PSP Angela Khan
PSP Angela KhanPSP Angela Khan
PSP Angela Khan
 
The Agile Pretender
The Agile PretenderThe Agile Pretender
The Agile Pretender
 
JGI Branding Strategy
JGI Branding StrategyJGI Branding Strategy
JGI Branding Strategy
 
PSP Tizianad
PSP TizianadPSP Tizianad
PSP Tizianad
 
iPhone 4 Bumper Conspiracy
iPhone 4 Bumper ConspiracyiPhone 4 Bumper Conspiracy
iPhone 4 Bumper Conspiracy
 
Psp Hong Davies
Psp Hong DaviesPsp Hong Davies
Psp Hong Davies
 
The Triangulation of Truth
The Triangulation of TruthThe Triangulation of Truth
The Triangulation of Truth
 
Ülesanne
ÜlesanneÜlesanne
Ülesanne
 
Prima vista 2012 kohta
Prima vista 2012 kohtaPrima vista 2012 kohta
Prima vista 2012 kohta
 
Chikasui
ChikasuiChikasui
Chikasui
 
This is binding - the idea
This is binding - the ideaThis is binding - the idea
This is binding - the idea
 
Gappei jokaso
Gappei jokasoGappei jokaso
Gappei jokaso
 
Students Comments Anna
Students Comments AnnaStudents Comments Anna
Students Comments Anna
 
Life Worlds
Life WorldsLife Worlds
Life Worlds
 
Beyond the Middle
Beyond the MiddleBeyond the Middle
Beyond the Middle
 
Evolution of ‘in store' - can bricks & mortar and e commerce work together ef...
Evolution of ‘in store' - can bricks & mortar and e commerce work together ef...Evolution of ‘in store' - can bricks & mortar and e commerce work together ef...
Evolution of ‘in store' - can bricks & mortar and e commerce work together ef...
 
Bersaing
BersaingBersaing
Bersaing
 
Social Games on Facebook: Worth it?
Social Games on Facebook: Worth it?Social Games on Facebook: Worth it?
Social Games on Facebook: Worth it?
 
Banking on the Millennial Experience
Banking on the Millennial ExperienceBanking on the Millennial Experience
Banking on the Millennial Experience
 

Semelhante a Comunicação Bluetooth Entre Python e PyS60

Multi client
Multi clientMulti client
Multi client
ganteng8
 
MultiClient chatting berbasis gambar
MultiClient chatting berbasis gambarMultiClient chatting berbasis gambar
MultiClient chatting berbasis gambar
yoyomay93
 
Multi client
Multi clientMulti client
Multi client
Aisy Cuyy
 
sms frame work
sms frame worksms frame work
sms frame work
Arulalan T
 

Semelhante a Comunicação Bluetooth Entre Python e PyS60 (20)

python programming
python programmingpython programming
python programming
 
Multi client
Multi clientMulti client
Multi client
 
UDP.yash
UDP.yashUDP.yash
UDP.yash
 
Introduction to asyncio
Introduction to asyncioIntroduction to asyncio
Introduction to asyncio
 
uygulamalarla siber güvenlik-siber guvenlik haftasi.pptx
uygulamalarla siber güvenlik-siber guvenlik haftasi.pptxuygulamalarla siber güvenlik-siber guvenlik haftasi.pptx
uygulamalarla siber güvenlik-siber guvenlik haftasi.pptx
 
tp socket en C.pdf
tp socket en C.pdftp socket en C.pdf
tp socket en C.pdf
 
为什么 rust-lang 吸引我?
为什么 rust-lang 吸引我?为什么 rust-lang 吸引我?
为什么 rust-lang 吸引我?
 
[4] 아두이노와 인터넷
[4] 아두이노와 인터넷[4] 아두이노와 인터넷
[4] 아두이노와 인터넷
 
Udp socket programming(Florian)
Udp socket programming(Florian)Udp socket programming(Florian)
Udp socket programming(Florian)
 
MultiClient chatting berbasis gambar
MultiClient chatting berbasis gambarMultiClient chatting berbasis gambar
MultiClient chatting berbasis gambar
 
Socket programming
Socket programmingSocket programming
Socket programming
 
Encrypt all transports
Encrypt all transportsEncrypt all transports
Encrypt all transports
 
session6-Network Programming.pptx
session6-Network Programming.pptxsession6-Network Programming.pptx
session6-Network Programming.pptx
 
Multi client
Multi clientMulti client
Multi client
 
INTRODUCTION TO SOCKETS IN COMPUTER NETWORKS DEPT OF CSE.ppt
INTRODUCTION TO SOCKETS IN COMPUTER NETWORKS DEPT OF CSE.pptINTRODUCTION TO SOCKETS IN COMPUTER NETWORKS DEPT OF CSE.ppt
INTRODUCTION TO SOCKETS IN COMPUTER NETWORKS DEPT OF CSE.ppt
 
Computer Networks Lab File
Computer Networks Lab FileComputer Networks Lab File
Computer Networks Lab File
 
ZeroMQ: Messaging Made Simple
ZeroMQ: Messaging Made SimpleZeroMQ: Messaging Made Simple
ZeroMQ: Messaging Made Simple
 
sockets_intro.ppt
sockets_intro.pptsockets_intro.ppt
sockets_intro.ppt
 
Sockets intro
Sockets introSockets intro
Sockets intro
 
sms frame work
sms frame worksms frame work
sms frame work
 

Último

Último (20)

Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 

Comunicação Bluetooth Entre Python e PyS60

  • 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((quot;quot;, porta)) sock.listen(1) print 'Estabelecendo servico' socket.bt_advertise_service(uquot;EXEMPLO PYCON 2008quot;, 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(uquot;EXEMPLO PYCON 2008quot;, sock, False, socket.RFCOMM) sock.close() conexao.close() print quot;Conexao finalizadaquot;
  • 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 quot;Conectando a %s na porta %squot; % (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 quot;Conexao finalizadaquot;
  • 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(quot;EXEMPLO PYCON 2008quot;, 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 quot;Conexao finalizadaquot; **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 quot;Conexao finalizadaquot;