Archive for the 'police' category

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)

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.

And I am Back

October 20, 2008 11:17 pm

Wow what a really busy summer!  Which is why I have not posted much on this.

The most driving things for me right now is filling out my application to volunteer on the Citizen Review Committee.  It is vital that government be legitimate to citizens.  Having citizen oversight is essential for our Democracy to flourish… no only if there were public hearings on the Wall Street bailout happening right now.

In the geek realm I am building a CNC machine for a project that will most likely use some cool open hardware.  It feels so good to work with my hands and tools after years of doing Systems Administration.  I very much feel as though I am in a transitional period of my life into the political realm.  I still enjoy and believe that technology is available to do great things for people… but only if the technology is open and affordable to all.