{"id":4354,"date":"2022-05-20T02:29:08","date_gmt":"2022-05-20T09:29:08","guid":{"rendered":"http:\/\/www.sheer.us\/weblogs\/?p=4354"},"modified":"2022-05-20T02:29:08","modified_gmt":"2022-05-20T09:29:08","slug":"perl-bluetooth-communications","status":"publish","type":"post","link":"https:\/\/www.sheer.us\/weblogs\/programming\/perl\/perl-bluetooth-communications","title":{"rendered":"Perl bluetooth communications"},"content":{"rendered":"<p>I had a couple of notes on using Net::Bluetooth from a raspberry pi to talk to a Bluetooth serial port because I couldn&#8217;t get the example code given with Net::Bluetooth to work.<\/p>\n<p>The following will connect to a mac address and send and receive data from it (in this particular example, a ESP32):<\/p>\n<p><PRE><br \/>\n#!\/usr\/bin\/perl<\/p>\n<p>use Net::Bluetooth;<br \/>\nuse Data::Dumper;<br \/>\nuse IO::Handle;<br \/>\nmy $obj = Net::Bluetooth->newsocket(&#8220;RFCOMM&#8221;);<\/p>\n<p>$addr = &#8216;C4:4F:33:58:B6:FB&#8217;;<br \/>\n$port = 1;<\/p>\n<p>if($obj->connect($addr, $port) != 0) {<br \/>\n     die &#8220;connect error: $!\\n&#8221;;<br \/>\n}<\/p>\n<p>my $fh = $obj->perlfh();<br \/>\n$fh->autoflush(1);<\/p>\n<p>sleep(1);<\/p>\n<p>print &#8220;sending \\n&#8221;;<\/p>\n<p>print $fh &#8220;V\\n&#8221;;<br \/>\nprint &#8220;receiving\\n&#8221;;<\/p>\n<p>$buf = readline($fh);<br \/>\nprint &#8220;Fetchhost: $buf\\n&#8221;;<br \/>\n<\/PRE><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I had a couple of notes on using Net::Bluetooth from a raspberry pi to talk to a Bluetooth serial port because I couldn&#8217;t get the example code given with Net::Bluetooth to work. The following will connect to a mac address and send and receive data from it (in this particular example, a ESP32): #!\/usr\/bin\/perl use [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[32,4,3],"tags":[],"_links":{"self":[{"href":"https:\/\/www.sheer.us\/weblogs\/wp-json\/wp\/v2\/posts\/4354"}],"collection":[{"href":"https:\/\/www.sheer.us\/weblogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sheer.us\/weblogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sheer.us\/weblogs\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sheer.us\/weblogs\/wp-json\/wp\/v2\/comments?post=4354"}],"version-history":[{"count":1,"href":"https:\/\/www.sheer.us\/weblogs\/wp-json\/wp\/v2\/posts\/4354\/revisions"}],"predecessor-version":[{"id":4355,"href":"https:\/\/www.sheer.us\/weblogs\/wp-json\/wp\/v2\/posts\/4354\/revisions\/4355"}],"wp:attachment":[{"href":"https:\/\/www.sheer.us\/weblogs\/wp-json\/wp\/v2\/media?parent=4354"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sheer.us\/weblogs\/wp-json\/wp\/v2\/categories?post=4354"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sheer.us\/weblogs\/wp-json\/wp\/v2\/tags?post=4354"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}