Archive for November, 2008

Cracking a NUT with code

November 18, 2008 9:48 pm

I got the gear that I lent to Amanda’s campaign back and am getting it set up for a project that me and a few friends are doing.  Today was mainly getting the PowerCom KIN-1500AP UPS up and running.  I ended up having to write some code to get the shutdown working properly.

See:

#! /usr/bin/perl
# little script that will wait till batteries are almost dead to power down
# if power comes back before then then NUT is restarted
# min battery level to start shutdown
$min_battery_level = 80;
# seconds to wait between poll of UPS status
$poll_interval = 10;
$upsc_bin = "/bin/upsc";
$logger_bin = "/usr/bin/logger";
$upsname = "black@localhost";
$ups_status = &get_ups_status();
$ups_battery_level = &get_ups_battery_level();
`$logger_bin -t $0 "called by NUT"`;
`$logger_bin -t $0 "UPS_STATUS is $ups_status"`;
`$logger_bin -t $0 "UPS_BATTRY is at $ups_battery_level"`;

while ( &get_ups_battery_level() > $min_battery_level ) {

   ### The UPS is back on line and we can exit
   if ( &get_ups_status() eq 'good' ) {
      `$logger_bin -t $0 "UPS_STATUS is good."`;
      `$logger_bin -t $0 "Restarting NUT and exiting $0"`;
      `/etc/init.d/nut restart`;
      exit 1;
   }
   else {
      foreach ( `$upsc_bin $upsname` ) {
         if ($_ =~ m/ups\.status/) {
            `$logger_bin -t $0 "$_"`;
            $ups_battery_level = &get_ups_battery_level();
            `$logger_bin -t $0 "battery.charge: $ups_battery_level"`;
            sleep $poll_interval;
         }
      }
   }
}
# If we get to this point the battery is really low and we need to shutdownp
`$logger_bin -t $0 "battery.charge is below $min_battery_level"`;
`$logger_bin -t $0 "Shutting system down"`;
`/sbin/shutdown -h -P now`;
########################################
sub get_ups_battery_level() {
   foreach ( `$upsc_bin $upsname` ) {
      if ($_ =~ m/battery\.charge/) {
            $charge = $_;
            $charge =~ s/(.*)(\:\ )(.*)/$3/ ;
            chomp ($charge);
      }
   }
   return $charge;
} #End of sub get_ups_battery_level()

sub get_ups_status() {
   foreach ( `$upsc_bin $upsname` ) {
      if ($_ =~ m/ups\.status/) {
         if ( $_ =~ m/OL/ ) {
            $status = "good";
         }
         else {
            $status = "bad";
         }
      }
   }
   return $status;
} #End of sub get_ups_status()

The CNC machine is working great.  I am still learning the intricacies of CAM and gcode… well that and waiting for the variable speed controller and mill ends to arrive.  I emailed the city to find out the process for selection on the CRC.  This week they are reviewing the applications and the beginning of December is when they will interview.  Jonathan over at Bikeportland.org posted a very telling story of why I feel that Citizen oversight of the police service is necessary:

PSU Cycling Club president Reuben Vyn and Officer Pryce. (Photos: Peter Welte, Story: BikePortland.org)

PSU Cycling Club president Reuben Vyn and Officer Pryce. (Photos: Peter Welte, Story: BikePortland.org)

Our Moon Landing

November 5, 2008 2:06 am

There comes a time in ones life where the events leading up to an event overshadow the event.

Tonight is one.

Obama is President and his vision of unity is our version of the moon landing.  Here in North Portland I hear fireworks and horns honking.  More so I feel the a weight lifted off of the the shoulders of Americans.  Now our time is upon us to to show what are willing do to sacrifice to solve our problems.

This day makes me smile in a long time for my Country.

CRC application is in

November 1, 2008 2:21 pm

Yesterday I biked down to City Hall to turn in my application to be on the CRC.  While on the steps talking to D on my cell phone Les was walking in.  I only had time to say ‘Hi’, but it was really good to see him.

On the way home I stopped by Free Geek to get some shielded cable and DB25 connectors for the CNC machine.  Free Geek is such a wonderful resource and maturation of Open Source.  It was nice to see all the Ubuntu CD’s gone and the thrift store full of people recycling.

I the rest of the night soldering a protective circuit for the limit switches and getting the pinouts right for the shielded cable.  I was listening to Countdown on MSNBC with Micheal Moore really resonated with me.  People keep their jobs because of health insurance.  I have known many people that loath their jobs and\or employers… yet keep their job only because of health insurance.  His premis was that this stifles people by locking them in a job that they do not like and away from occupations that they could excel in.