Skip to content

Commit

Permalink
a better sample script
Browse files Browse the repository at this point in the history
  • Loading branch information
Claudio committed Sep 28, 2008
1 parent 389c2b6 commit e26f921
Showing 1 changed file with 51 additions and 22 deletions.
73 changes: 51 additions & 22 deletions sample.rb
@@ -1,27 +1,56 @@
require 'rbluez'
include Rbluez

=begin
hc = Hci.new
hc.hci_connect("00:1c:c1:87:35:34")
sleep 5
puts hc.hci_lq
puts hc.hci_auth
puts hc.hci_read_tpl(1)
puts hc.hci_remote_version

puts "first example"

bt = Hci.new
bt.hci_set_local_name("My Phone")
bt.hci_set_local_cod(COD_COMPUTER_LAPTOP)
puts bt.hc.hci_local_name
puts bt.hci_local_bdaddr
puts bt.hci_local_cod
for r in bt.hci_scan
puts "Remote device: #{r[:bdaddr]}"
puts "Remote device of class: #{r[:dev_class]}"
puts "Remote name #{bt.hci_remote_name(r[:bdaddr]}"
end
bt.hci_close

puts "second example"

bt = Hci.new
bt.hci_connect("00:11:22:33:44:55")
sleep 5
hc.hci_disconnect
hc.hci_close
=end
puts bt.hci_lq
puts bt.hci_auth
puts bt.hci_read_tpl(1)
puts bt.hci_remote_version
bt.hci_disconnect
bt.hci_close


=begin
this is a third example but you need two bluetooth host because
one is the client and one is the server
#Server bluetooth
bt = Rfcomm.new
#bt.rfcomm_bind
#bt.rfcomm_listen(29)
#puts "Socket listening..."
#client, client_bdaddr = bt.rfcomm_accept
#puts "Connessione da #{client_bdaddr}"
#puts "Dati ricevuti #{client.rfcomm_recv(20)}"
bt.rfcomm_connect("00:11:67:8e:49:a1")
bt.rfcomm_send("ciao da claudio aaaaaaaaaaaa", 0)

#client.rfcomm_close # close client connection
bt.rfcomm_close # close main socket connection
bt.rfcomm_bind
bt.rfcomm_listen(29)
puts "Socket listening..."
client, client_bdaddr = bt.rfcomm_accept
puts "Connessione da #{client_bdaddr}"
puts "Dati ricevuti #{client.rfcomm_recv(20)}"
client.rfcomm_close # close client connection
bt.rfcomm_close
#Client bluetooth
bt.Rfcomm.new
bt.rfcomm_connect("00:11:22:33:44:55")
bt.rfcomm_send("Hello world!", 0)
bt.rfcomm_close
=end

0 comments on commit e26f921

Please sign in to comment.