pi pet camera

We’re on spring break this week, and couldn’t get any takers to look after out guinea pig, Mon$ter.  The plan was to just put lots of extra food and water in his habitat.  I repurposed my pi-zero based front door security device (because we replaced it with a ring) and set it up to take a picture of Mon$ter every hour, and post it on my home web server so we can see how he’s doing.

rasspberry pi pet cam
Screenshot of my web browser pet cam app
pi zero w with camera and 12VDC lead-acid backup battery
pi zero w with camera and 12VDC lead-acid backup battery facing Mon$ter’s cage

Here’s the simple script.  It makes some system calls to some other scripts I wrote to scp the images to the web server.

interfacing elegoo uno R3 to pine64

elegoo UNO R3 interfaced to a pine64 via UART
elegoo UNO R3 interfaced to a pine64 via UART

I’m really late to just now be getting on board (no pun intended) with arduino.  Until now, I have focused on SBC’s that run a full linux distribution.  I just bought an elegoo 37 sensor kit off amazon, and it was only $11 to throw in an elegoo UNO R3.

Just to try it out, I modified the serial output example.  Instead of using a potentiometer,  I used a 16K ohm photoresistor in a voltage divider circuit with a 330 ohm resistor.  When the binary value of the analog read drops below 200,  digital pin 13 turns on an LED so you can have some light.

Analog binary value on the pine64 to the left of the IDE
Analog binary value on the pine64 to the left of the IDE

Here’s the setup->

elegoo UNO R3 photo resistor voltage divider analog read
elegoo UNO R3 photo resistor voltage divider analog read

subnet scanner utility in perl using Net::Ping

I often times have to assign an ipv4 address to a device at work and need to know what addresses are available on a particular subnet.  On other occasions, I just need to know what hosts are up / down on a subnet.  Normally, I would use nmap on my personal laptop, but only authorized devices are allowed on my company network, and I certainly want to stay out of trouble. Plus, I have to use windows 10 at work, and I do not have admin privelages.  I wrote a simple perl script that scans a user-defined range of ip addresses using the Net::Ping module from cpan.

This is the first of a suite of network utilities that I am writing to help troubleshoot network issues in cases where I do not have nmap available.   Here is a scan of a small portion of my home network:

Perl based subnet scanner using Net::Ping
Perl based subnet scanner using Net::Ping

Here is the source code so far:

 

#!/usr/bin/perl -w
use Net::Ping;
use Time::HiRes qw(gettimeofday);
use Term::ANSIColor;
use 5.010;
 
print "ping tester\n--------------------------\n";
#print "enter ip: ";

#get address
#chomp(my $host = );
#print "host: $host\n";

#create ping object
my $p = Net::Ping->new('icmp');
#hi res time
$p->hires();

#a single ip address
my $host;

#up / down devices
my @online_devices; 
my @offline_devices; 

#get address range from user
print "Enter IP address range: ";
chomp(my $ip_range = );
#print "range: $ip_range\n";
$ip_range =~ /(\d+\.\d+\.\d+)\.(\d+)-(\d+)/;
my $network = $1;
my $start_ip = $2;
my $end_ip = $3;
#print "start IP: $start_ip\nend IP: $end_ip\n";

#get t0 for benchmark
my $t0 = gettimeofday();

for(my $i=$start_ip;$i<=$end_ip;$i++)	{
	$host = "$network.$i";
	print "checking $host....\n";
	
	#list context, returns duration
	my ($ret, $dur, $ip) = $p->ping($host, 0.25);
	
	#format time
	$dur = sprintf("%.6f", $dur); 	
	
	#results
	if($ret){
		print colored  ("$host is up  latency: $dur seconds", 'white on_green');
		print "\n";
		push @online_devices, $host;
	}#end if
	else{
		print colored ("$host down", 'white on_red');
		print "\n";
		push @offline_devices, $host;
	}#end else		
	print "-----------------------------\n";
}#end for

#kill ping object
$p->close();

#benchmarking results
my $t1 = gettimeofday();
my $elapsed = $t1 - $t0; 
$elapsed = sprintf("%6f", $elapsed);
print "\ntime elapsed: $elapsed....\n";

#report file
open RP, ">", "report.txt" or die $!;

#results
my $up_sz = @online_devices;
my $down_sz = @offline_devices;
print "$up_sz devices online\n$down_sz devices offline\n";

print "\nOnline devices....\n------------------------------------------------------\n";
print RP "Online devices....\n------------------------------------------------------\n";
foreach $a (@online_devices){
	say $a;
	print RP $a."\n"; 
}#end foreach

print "\n\nOffnline devices....\n------------------------------------------------------\n";
print RP "Offline devices....\n------------------------------------------------------\n";
foreach $a (@offline_devices){
	say $a;
	print RP $a."\n"; 
}#end foreach

close RP;

remake of 80’s computer toy word game

80's computer word game
80’s computer word game

Way back on Christmas of ’87, my sister got a computer toy similar to this one.  I couldn’t put it down.  It had a word game with 8, 14-segment LEDs where you had to enter letters one at a time and guess the word before your tries ran out, sort of like wheel of fortune.  I got bored on Sunday night, and wrote a command line version.

perl command line word game
perl command line word game

It requires an external file, words.txt, from which it randomly chooses a word for each round.  Above is the game play.

Here is the source:

#!/usr/bin/perl -w
use Tie::File;
use strict;

#array of all letters
my @letters = 'a' .. 'z';
my $szletters = @letters;
my @used_letters;
my $n_tries = 0;
my $wf = 0;
my $iword = '';
my $letter = '';
my @wrd;

my @words;
tie @words, 'Tie::File', "words.txt" or die $!;

my $nw = @words;
#print "nwords: $nw \n";
my $num = int(rand($nw));

my $word = $words[$num];

#print "word: $word\n";

my $lngth = length($word);

for(my $l=0; $l < $lngth; $l++){
#print '-';
$iword = $iword."-";
}#end for
print "\n";

@wrd = split //, $word;
my $lef = 0;
do {
print $iword."\n";
print "enter a letter: ";
chomp($letter = );
#print "letter: $letter\n";

#clear out iword
$iword = '';

push @used_letters, $letter;
for(my $l=0;$l<$lngth;$l++){
foreach my $v (@used_letters){
if($wrd[$l] eq $v){
$iword = $iword.$v;
$lef = 1;#set flag true
}#end if
}#end foreach

unless($lef == 1){
$iword = $iword.'-';
}#end unless
$lef = 0;
}#end for

print "used letters: @used_letters \n";

if($iword eq $word){
print "$word\n";
print "YOU WIN!!!\n";
$wf = 1;
}#end if

} while($wf ==0);