Browse files

a better sample script

  • Loading branch information...
1 parent 389c2b6 commit e26f9216f153676e35c964bee4e5ce54f2a5e0b8 Claudio committed Sep 28, 2008
Showing with 51 additions and 22 deletions.
  1. +51 −22 sample.rb
@@ -1,27 +1,56 @@
require 'rbluez'
include Rbluez
-hc =
-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 =
+bt.hci_set_local_name("My Phone")
+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]}"
+puts "second example"
+bt =
sleep 5
+puts bt.hci_lq
+puts bt.hci_auth
+puts bt.hci_read_tpl(1)
+puts bt.hci_remote_version
+ this is a third example but you need two bluetooth host because
+ one is the client and one is the server
+#Server bluetooth
bt =
-#puts "Socket listening..."
-#client, client_bdaddr = bt.rfcomm_accept
-#puts "Connessione da #{client_bdaddr}"
-#puts "Dati ricevuti #{client.rfcomm_recv(20)}"
-bt.rfcomm_send("ciao da claudio aaaaaaaaaaaa", 0)
-#client.rfcomm_close # close client connection
-bt.rfcomm_close # close main socket connection
+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
+#Client bluetooth
+bt.rfcomm_send("Hello world!", 0)

0 comments on commit e26f921

Please sign in to comment.