Monday, June 30, 2014

Dead Man's Switch - Simple To Implement

One tool that has been discussed endlessly is called the "Dead Man's Switch". A "Dead Man's Switch" is a tool that requires interaction either continuously or regularly, and if that interaction doesn't work, the "switch" is triggered. These kinds of tools have been used in a number of areas. Usually, they are used in high-security areas, such as military triggers. Just a note, Wikileaks had an "Insurance File" that contained a number of encrypted documents that was available in the BitTorrent world, and a form of a Dead Man's Switch with the decryption key.

Anything that should happen if something else happens to you is a prime candidate to implement a switch like this, hence, I needed my own switch set up to get information to my wife.

Since I had just altered the process for my dead man's switch, I thought it might work well to illustrate how I had it set up, so if anyone wants to create one on a Linux platform, it is a simple process.

Here's how it worked.
  1. A cron was set up that checked the age of a file. If this file was too old, it triggered an action (e.g. mailing a copy of my "Insurance File" to a close friend). The cron ran once every day, e.g. (at midnight as an example) :

      0 0 * * * /usr/bin/run_like_a_deadman.sh

    The cron script looked like :
      
      #!/bin/sh
      
      MAX_AGE_IN_DAYS=5
      PRE_MAX_AGE_IN_DAYS=3
      SWITCH_FILE=/my/deadman/file/to/check
      SWITCH_FILE_LAST_MODIFIED=`stat --format='%Y' "$SWITCH_FILE"`
      CURRENT_TIME=`date +%s`
      AGE_IN_DAYS=`echo "($CURRENT_TIME - $SWITCH_FILE_LAST_MODIFIED) / 86400" | bc`
      
      if [ "$MAX_AGE_IN_DAYS" -lt "$AGE_IN_DAYS" ]; then
        # max_age exceeded, trigger deadman
        echo "If you are receiving this e-mail, please know the following.  (1) I haven't reset my digital deadman switch.  (2) I wish this hadn't had to happen like this.  (3) Since I have been unable to reset the timer, something bad must have happened to me in the last $AGE_IN_DAYS days. There is a floppy disk hidden in the LP collection of the cellar that includes some instructions.  Please review the instructions.  And, above all else, PLEASE know that I will miss all of you!" | mail -s 'CRITICAL: deadman switch activated' friendOne@gmail.com
        exit;
      fi;
      
      if [ "$PRE_MAX_AGE_IN_DAYS" -lt "$AGE_IN_DAYS" ]; then
        # warning, PRE_MAX_AGE_IN_DAYS exceeded, fire a warning shot
        echo "please follow the procedure prescribed to reset the deadman switch timer." | mail -s 'WARNING: deadman switch active' myself@gmail.com
      #else
      #  # all is well, let's do nothing
      fi;
      
    This said that if I didn't log in to my server in three days, I'd get an e-mail (if my address was myself@gmail.com) telling me I have to log in. If I hadn't logged in for 5 days, my friend (friendOne@gmail.com) would get an e-mail.
  2. Whenever I logged into my server, I had a .bashrc command that touched the trigger file.  For example, it simply ran :

      touch /my/deadman/file/to/check
      

    You could also accomplish this through a remote server, if you had a secure server somewhere else by adding something like :

      /usr/bin/wget -q -O /dev/null http://www.example.com/cgi-bin/reset_deadman_timer.pl

     A simple CGI could look like :

      #!/usr/bin/perl
      
      `touch /srv/.deadman`;
      print "Content-Type: text/plain\n\nOK";

     Please note that the above isn't really secure. Virtually anyone could post to the URL if they found it and prevent things from happening unless you had some SERIOUS mechanisms to keep things locked down.  And in that case, since it would be a public server, anyone with access to the server could possibly step through the process to figure it out.
Just a little bit of information that you might find beneficial.  Enjoy!

Thursday, June 12, 2014

Going to try the Google Book Scanner

I've decided I want another project (wait a minute... shouldn't I finish what I've already started?).  Here's the deal.  My father loves to collect books - and some of the older books are magnificent.  Not to look at, but because of the information in them.

For example, I've been thinking a lot about how the human race isolated elements in the first place.  Most modern books won't tell you how to obtain pure carbon, or helium.  But, one or two of my fathers old books (from around the 1940's) DO tell you how to isolate some basic elements.

Here's the problem... my father is thinking about just getting rid of all of his books.  That could pose a potential loss of valuable information.

Here's the solution... I started thinking about simply scanning the books to a digital format so that he could easily access them, and not have to drag them out.  I remembered a HackADay article once upon a time about a Google project for scanning books without cutting pages out, breaking bindings, or spending hundreds of thousands of dollars on equipment.  Ultimately, I found that some students at the University of Michigan built a new version of the scanner that seemed to run off of a Raspberry Pi.  Perfect!

There are some tasks I'm going to have to work around, though.  First, the Michigan students' project utilized laser cut plexiglass, anodized aluminum, and machined parts.  I can't really afford that, so I'm going to have to break out the old ingenuity for this one.  I like their adjustable vacuum for page turning, so I'll need to replicate that without having custom parts machined.  We'll see how this one turns out.

There are four major components from what I've been able to determine :

  1. The Frame
  2. Book Caddy/Movement (including a stepper motor)
  3. Page Turning/Vacuum and vacuum tube
  4. Scanning Elements/Raspberry Pi

The Frame

I'll probably settle for ordering some super-thin Delrin sheets online for the frame of the book scanner (less friction on the book) and epoxy them down to some small, cheap plywood for rigidity.  That would give me the frame needed to get things started.  I'd first build the frame using counter-sunk screws.  The Michigan project actually used some machinists to do this so that it would all be flush - I frankly don't care, since I'll be gluing the Delrin over the top of the screws.  I probably ought to use some hinges to make it collapsable so that I can break it down and store it out of the way.

The Scanning Element

You need two scanners.  I've located a cheap ($5 at a yard sale) HP All-In-One office printer that is SANE-compatable.  It's an HP 2410xi printer/scanner/fax/astronaut/AI chess player unit - it does anything an office might need regularly (not so serious about the astronaut/AI chess playing of it - please don't think it really does that).

That means I already have one scanning element, and I need a second one.  I'm in the hunt for that.

To make it work, it has to be SANE compatible.  Who wants to connect TWO USB wires to a computer and scan from two scanners at the same time?  So, I'll use a Raspberry Pi inside the machine, connected to both, and run a command-line scan under two processes, which is why the requirement is there.  Then I can use ImageMagick to crop images down to size, and create a PDF based on those.

The Page Turner

For this, I like the technique that the University of Michigan students did - and adjustable vacuum tube.  However, I cannot begin to think about dumping cash into a machine shop somewhere, so I'm probably doing to have to settle for a Delrin tube, threaded on one end, and slots cut into it.  It would then be attached to the a shop vacuum.  The blowing end of the vacuum would also be fed back into the unit to "blow" back at the spot to prevent double pages from getting turned and missing one.

The Book Caddy and Movement

So, I've already ordered some NEMA 17's (17PM-K402-P4V) motors to use in this.  They don't have to be strong, but I'd like to be able to have the Raspberry Pi operate them.  Of the motors I received, one of them had a damaged connector/circuit board on arrival:



It wasn't a packaging problem as the package was in great shape and showed no signs of damage, and only one was damaged, so I simply expect that the one motor had arrived at the vendor's "warehouse" (this was an eBay order) in that state, and wasn't inspected before being shipped.  After contacting the vendor, they are replacing it. Sounds like great people to work with!

S10 to Replace Civic

Well, I found a replacement vehicle for the Civic.  I'd prefer to have a small engine for a commuter, but this one has a V6.  It's a Chevy S10 V6 regular cab (a little tight for stuff inside the cab), and a long bed (a bit rare).  It's been working quite well for me.

However, it did cost a little more than the Civic, so it interfered with some of that cost going to headlight unit paint.  Finally saved up a little, and decided I'd better get to the wiring, and started playing with the wiring.

My fear was that I'd connect the batter and melt a wire, causing the whole car to burn to the ground (yeah, I kept a fire extinguisher close by, just in case, even if the odds of it being that bad were so minuscule).  So, I followed the advice of some experts, and threw in a little bit of a procedure for my own sanity.  Here's how I tested the electrical.

Preparation :

  1. Put the battery in place.
  2. Connect the positive battery cable end (+).
  3. Do NOT connect the ground cable yet.  Instead, wire some spare connectors to it that you can connect at will.
  4. Disconnect/remove all of the fuses.
  5. Obtain a headlight (this step is invaluable, and is the advice I received from some experts).
  6. Connect one side of the headlight to the negative (-) battery cable (not the battery).

I ran the first test with no fuses connected/in the vehicle, because I wanted to make sure all was well before proceeding.  I then re-connected one fuse at a time and re-tested, just to ensure each circuit was acceptable.

Actual Test :

  1. Connect the negative terminal of the battery (-) to the other terminal of the light.
  2. Check the headlight.  If it's on, something is shorted in the circuits that are still connected.  If it's off, you're okay.
  3. Turn the key to the accessory/on position (but not start, just in case you don't have fluids/etc) just to ensure things behave as expected, each time checking the headlight.
  4. Repeat as necessary for each circuit as you connect fuses.

So, that's what I kept doing.  I'd connect a fuse, and check that circuit.  Everything looked flawless...

... until I finished and decided to get the stupid door glass adjusted.  The power window regulators wouldn't move.  I started with the trusty old volt meter on the wiring.  Checking the whole thing out, I found the power window relay is bad.  Bypassing that to ensure the rest of the wiring was okay and the motors ran, I still couldn't get the motors to turn.  I checked the voltages on the connectors at the motor side, and... I had the right voltage.  It looks like the wiring is fine.  It means that the power window motors aren't so good.  Now I've got to replace the power window motors again (I have done that a couple of times already), and hope it's not a mechanical bind with the regulator.

So... I started out expecting the whole car was going to "blow up" from something being shorted out, and found out the opposite is true - the wiring is great, some components connected to it, not so much.

While I was at it, I decided to try an electrical pop-up headlight conversion.  I had obtained a couple of 1995 Ford Probe headlight motors from a junk yard.  I slapped them up to the battery, and they worked perfectly.  They have about the same throw as the C3 Corvette, so I'm in great shape.  Some others had done this conversion in the past, and I borrowed their process - I cut some brackets, soldered some wires together so that the motors work in tandem (and put heat shrink tubing around that), and bolted them in place.  I still have yet to adjust them (I'll need finished headlights), and I still have yet to finish the circuits, but I'm close.

At this point, here's the list of things to do :

  1. Replace power window motors and relay (can only find that through mail order services [sigh]).
  2. Adjust door glass
  3. Install door mirrors
  4. Install door panels
  5. Install A/C ducts
  6. Install dash panels
  7. Get headlight units painted and installed
  8. Complete circuit (two diodes and battery wiring) for the pop-up motors
  9. Install rear speakers/amplifier
  10. Ensure fluids are in the car
  11. Actually try to start it
It's amazing that I'm that close - and yet it's taking me so long to get there.  I will continue to work when I can, though.