{"id":358,"date":"2020-03-30T20:12:10","date_gmt":"2020-03-31T01:12:10","guid":{"rendered":"https:\/\/sundrysites.com\/?page_id=358"},"modified":"2020-03-30T20:12:10","modified_gmt":"2020-03-31T01:12:10","slug":"move-packets-from-arduino-to-hca","status":"publish","type":"page","link":"https:\/\/sundrysites.com\/index.php\/home-info\/arduino-projects\/perl-programs\/move-packets-from-arduino-to-hca\/","title":{"rendered":"Move Packets from Arduino to HCA"},"content":{"rendered":"\n<p>This Perl program runs continuously awaiting incoming packets from the Arduinos, placing them into a file where HCA can read them.&nbsp; The incoming packets are mostly formatted as HCA flags so no processing is required.&nbsp; The Arduino with the one-wire thermometers, however, sends in their one-wire addresses and this program changes those to an HCA-friendly format.<\/p>\n\n\n\n<p># major change &#8211; now interpret each record to see if it needs parsed<br># use Time::Piece;<br>use IO::Socket::INET;<br>use Data::Dumper;&nbsp; # used for diag<\/p>\n\n\n\n<p># flush after every write<br># $| = 1;<\/p>\n\n\n\n<p>my ($socket,$received_data);<br>my ($peeraddress,$peerport);<br>my $outfile = &#8220;minutely.txt&#8221;;&nbsp; #picked up by hca<br>my $outln = &#8220;&#8221;;<br>my $logfile = &#8220;minutelog.txt&#8221;;<br>my $logln = &#8220;Minutely Start Up \\n&#8221;;<br>my $infile = &#8220;ard-sensors.txt&#8221;;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;#contains sensor addr to hca element name<br>open LOGOUT, &#8220;&gt;&gt; $logfile&#8221; or die &#8220;Log file open error: $!&#8221;;<br>print LOGOUT $logln;<br>close LOGOUT;<br>$logln = &#8220;&#8221;;<br># open file that contains addr\/name translations<br>open INPUT, &#8220;$infile&#8221; or die &#8220;Input file open error: $!&#8221;;<br># once file is open, create hash of addresses and names<br>my %taddr;<br>while (&lt;INPUT&gt;)<br>{<br>chomp;<br>my ($addrkey, $addrval) = split \/=\/;<br>$taddr{$addrkey} .= exists $taddr{$addrkey} ? &#8220;$addrval&#8221; : $addrval;<br>}<br># print Dumper(\\%taddr);<br>close INPUT;<br>#&nbsp; we call IO::Socket::INET-&gt;new() to create the UDP Socket and bound<br># to specific port number mentioned in LocalPort and there is no need to provide<br># LocalAddr explicitly as in TCPServer.<br>$socket = new IO::Socket::INET (<br>LocalPort =&gt; &#8216;5000&#8217;,<br>Proto =&gt; &#8216;udp&#8217;,<br>) or die &#8220;ERROR in Socket Creation : $!\\n&#8221;;<br>$logln = &#8220;Starting infinite loop \\n&#8221;;<br>open LOGOUT, &#8220;&gt;&gt; $logfile&#8221; or die &#8220;Log file open error: $!&#8221;;<br>print LOGOUT $logln;<br>close LOGOUT;<br>while(1)<br>{<br># read operation on the socket<br>$socket-&gt;recv($received_data,1024);<br>my $datestring = localtime();<br>#get the peerhost and peerport at which the recent data received for the log<br>$peer_address = $socket-&gt;peerhost();<br>$peer_port = $socket-&gt;peerport();<br>if ($peer_port != &#8220;6000&#8221; &amp;&amp; $peer_port != &#8220;5001&#8221; )<br>{<br>$logln = &#8220;Minutely Shutting Down \\n&#8221;;<br>open LOGOUT, &#8220;&gt;&gt; $logfile&#8221; or die &#8220;Log file open error: $!&#8221;;<br>print LOGOUT $logln;<br>close LOGOUT;<br>$socket-&gt;close();<br>system (&#8220;start C:\\\\Users\\\\smarthome\\\\Documents\\\\HCA\\\\Logs\\\\minutelyrestart.bat&#8221;);<\/p>\n\n\n\n<p>exit;<br>}<br>$logln = &#8220;$datestring,$peer_address,$peer_port,$received_data\\n&#8221;;<br># see if the record starts with a special word<br>if ($received_data =~ \/taddr\/)<br>{<br>#&nbsp;&nbsp; &nbsp;print &#8220;took branch 1 \\n&#8221;;<br>my @fields = split \/:\/, $received_data;<br>my $addr1 = $fields[1];<br>if (exists $taddr{$addr1})<br>{<br>#&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;print &#8220;took branch 2 \\n&#8221;;<br>$addr2 = $taddr{$addr1};<br>$outln = $addr2 . &#8220;=&#8221; . $fields[2] . &#8220;\\n&#8221;;<br>}<br>else<br>{<br>$outln = $fields[1] . &#8220;=&#8221; . $fields[2] . &#8220;\\n&#8221;;<br>}<br>#&nbsp;&nbsp; &nbsp;print &#8220;$taddr{$addr1}&#8221;;<br>}<br>else<br># if not, just use the record as is<br>{<br>$outln = $received_data . &#8220;\\n&#8221;;<br>}<\/p>\n\n\n\n<p>open OUTPUT, &#8220;&gt;&gt; $outfile&#8221; or die &#8220;Output file open error: $!&#8221;;<br>print OUTPUT $outln;<br>close OUTPUT;<br>open LOGOUT, &#8220;&gt;&gt; $logfile&#8221; or die &#8220;Log file open error: $!&#8221;;<br>print LOGOUT $logln;<br>close LOGOUT;<br>}<\/p>\n\n\n\n<p>$socket-&gt;close();<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This Perl program runs continuously awaiting incoming packets from the Arduinos, placing them into a file where HCA can read them.&nbsp; The incoming packets are mostly formatted as HCA flags so no processing is required.&nbsp; The Arduino with the one-wire thermometers, however, sends in their one-wire addresses and this program changes those to an HCA-friendly &hellip; <a href=\"https:\/\/sundrysites.com\/index.php\/home-info\/arduino-projects\/perl-programs\/move-packets-from-arduino-to-hca\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Move Packets from Arduino to HCA<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":352,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-358","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Move Packets from Arduino to HCA - Sundrysites<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/sundrysites.com\/index.php\/home-info\/arduino-projects\/perl-programs\/move-packets-from-arduino-to-hca\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Move Packets from Arduino to HCA - Sundrysites\" \/>\n<meta property=\"og:description\" content=\"This Perl program runs continuously awaiting incoming packets from the Arduinos, placing them into a file where HCA can read them.&nbsp; The incoming packets are mostly formatted as HCA flags so no processing is required.&nbsp; The Arduino with the one-wire thermometers, however, sends in their one-wire addresses and this program changes those to an HCA-friendly &hellip; Continue reading Move Packets from Arduino to HCA &rarr;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/sundrysites.com\/index.php\/home-info\/arduino-projects\/perl-programs\/move-packets-from-arduino-to-hca\/\" \/>\n<meta property=\"og:site_name\" content=\"Sundrysites\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/sundrysites.com\\\/index.php\\\/home-info\\\/arduino-projects\\\/perl-programs\\\/move-packets-from-arduino-to-hca\\\/\",\"url\":\"https:\\\/\\\/sundrysites.com\\\/index.php\\\/home-info\\\/arduino-projects\\\/perl-programs\\\/move-packets-from-arduino-to-hca\\\/\",\"name\":\"Move Packets from Arduino to HCA - Sundrysites\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/sundrysites.com\\\/#website\"},\"datePublished\":\"2020-03-31T01:12:10+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/sundrysites.com\\\/index.php\\\/home-info\\\/arduino-projects\\\/perl-programs\\\/move-packets-from-arduino-to-hca\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/sundrysites.com\\\/index.php\\\/home-info\\\/arduino-projects\\\/perl-programs\\\/move-packets-from-arduino-to-hca\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/sundrysites.com\\\/index.php\\\/home-info\\\/arduino-projects\\\/perl-programs\\\/move-packets-from-arduino-to-hca\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/sundrysites.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Home Info\",\"item\":\"https:\\\/\\\/sundrysites.com\\\/index.php\\\/home-info\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Arduino Projects\",\"item\":\"https:\\\/\\\/sundrysites.com\\\/index.php\\\/home-info\\\/arduino-projects\\\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Perl Programs\",\"item\":\"https:\\\/\\\/sundrysites.com\\\/index.php\\\/home-info\\\/arduino-projects\\\/perl-programs\\\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"Move Packets from Arduino to HCA\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/sundrysites.com\\\/#website\",\"url\":\"https:\\\/\\\/sundrysites.com\\\/\",\"name\":\"Sundrysites\",\"description\":\"As In Various and Sundry\",\"publisher\":{\"@id\":\"https:\\\/\\\/sundrysites.com\\\/#\\\/schema\\\/person\\\/1e11ce6af1587a3431e57dfc0797ab61\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/sundrysites.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/sundrysites.com\\\/#\\\/schema\\\/person\\\/1e11ce6af1587a3431e57dfc0797ab61\",\"name\":\"Wayne Gulden\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/c0392cdfb7826ed5407aad362998bc6dd03fe293560ce15ccc2211357e3cec6e?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/c0392cdfb7826ed5407aad362998bc6dd03fe293560ce15ccc2211357e3cec6e?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/c0392cdfb7826ed5407aad362998bc6dd03fe293560ce15ccc2211357e3cec6e?s=96&d=mm&r=g\",\"caption\":\"Wayne Gulden\"},\"logo\":{\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/c0392cdfb7826ed5407aad362998bc6dd03fe293560ce15ccc2211357e3cec6e?s=96&d=mm&r=g\"},\"sameAs\":[\"https:\\\/\\\/sundrysites.com\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Move Packets from Arduino to HCA - Sundrysites","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/sundrysites.com\/index.php\/home-info\/arduino-projects\/perl-programs\/move-packets-from-arduino-to-hca\/","og_locale":"en_US","og_type":"article","og_title":"Move Packets from Arduino to HCA - Sundrysites","og_description":"This Perl program runs continuously awaiting incoming packets from the Arduinos, placing them into a file where HCA can read them.&nbsp; The incoming packets are mostly formatted as HCA flags so no processing is required.&nbsp; The Arduino with the one-wire thermometers, however, sends in their one-wire addresses and this program changes those to an HCA-friendly &hellip; Continue reading Move Packets from Arduino to HCA &rarr;","og_url":"https:\/\/sundrysites.com\/index.php\/home-info\/arduino-projects\/perl-programs\/move-packets-from-arduino-to-hca\/","og_site_name":"Sundrysites","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/sundrysites.com\/index.php\/home-info\/arduino-projects\/perl-programs\/move-packets-from-arduino-to-hca\/","url":"https:\/\/sundrysites.com\/index.php\/home-info\/arduino-projects\/perl-programs\/move-packets-from-arduino-to-hca\/","name":"Move Packets from Arduino to HCA - Sundrysites","isPartOf":{"@id":"https:\/\/sundrysites.com\/#website"},"datePublished":"2020-03-31T01:12:10+00:00","breadcrumb":{"@id":"https:\/\/sundrysites.com\/index.php\/home-info\/arduino-projects\/perl-programs\/move-packets-from-arduino-to-hca\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/sundrysites.com\/index.php\/home-info\/arduino-projects\/perl-programs\/move-packets-from-arduino-to-hca\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/sundrysites.com\/index.php\/home-info\/arduino-projects\/perl-programs\/move-packets-from-arduino-to-hca\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/sundrysites.com\/"},{"@type":"ListItem","position":2,"name":"Home Info","item":"https:\/\/sundrysites.com\/index.php\/home-info\/"},{"@type":"ListItem","position":3,"name":"Arduino Projects","item":"https:\/\/sundrysites.com\/index.php\/home-info\/arduino-projects\/"},{"@type":"ListItem","position":4,"name":"Perl Programs","item":"https:\/\/sundrysites.com\/index.php\/home-info\/arduino-projects\/perl-programs\/"},{"@type":"ListItem","position":5,"name":"Move Packets from Arduino to HCA"}]},{"@type":"WebSite","@id":"https:\/\/sundrysites.com\/#website","url":"https:\/\/sundrysites.com\/","name":"Sundrysites","description":"As In Various and Sundry","publisher":{"@id":"https:\/\/sundrysites.com\/#\/schema\/person\/1e11ce6af1587a3431e57dfc0797ab61"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/sundrysites.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/sundrysites.com\/#\/schema\/person\/1e11ce6af1587a3431e57dfc0797ab61","name":"Wayne Gulden","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/c0392cdfb7826ed5407aad362998bc6dd03fe293560ce15ccc2211357e3cec6e?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/c0392cdfb7826ed5407aad362998bc6dd03fe293560ce15ccc2211357e3cec6e?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c0392cdfb7826ed5407aad362998bc6dd03fe293560ce15ccc2211357e3cec6e?s=96&d=mm&r=g","caption":"Wayne Gulden"},"logo":{"@id":"https:\/\/secure.gravatar.com\/avatar\/c0392cdfb7826ed5407aad362998bc6dd03fe293560ce15ccc2211357e3cec6e?s=96&d=mm&r=g"},"sameAs":["https:\/\/sundrysites.com"]}]}},"_links":{"self":[{"href":"https:\/\/sundrysites.com\/index.php\/wp-json\/wp\/v2\/pages\/358","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sundrysites.com\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/sundrysites.com\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/sundrysites.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sundrysites.com\/index.php\/wp-json\/wp\/v2\/comments?post=358"}],"version-history":[{"count":1,"href":"https:\/\/sundrysites.com\/index.php\/wp-json\/wp\/v2\/pages\/358\/revisions"}],"predecessor-version":[{"id":359,"href":"https:\/\/sundrysites.com\/index.php\/wp-json\/wp\/v2\/pages\/358\/revisions\/359"}],"up":[{"embeddable":true,"href":"https:\/\/sundrysites.com\/index.php\/wp-json\/wp\/v2\/pages\/352"}],"wp:attachment":[{"href":"https:\/\/sundrysites.com\/index.php\/wp-json\/wp\/v2\/media?parent=358"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}