Showing posts with label switch. Show all posts
Showing posts with label switch. Show all posts

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

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.

Tuesday, March 4, 2014

Status of the Home Brew Security System

I decided to upgrade from an Arduino and a large media server to an Udoo quad core (http://shop.udoo.org/usa/product/udoo-quad.html), because I didn't want to have to have the event server on the same network as everyone else.  I'm sort of paranoid.  What I found is :
  • The Udoo uses GPIO inputs that ARE available through the Linux image.
  • The Udoo failed to work with my relays.  This was because the relays were 5v relays (perfect for the Arduino Mega2560 I was using), but the Udoo uses a 3v logic level.  Simply put, the relays would never work.
  • I could put my entire event server package onto the Udoo, and have a self-contained alert system.  This was my goal.
Here's what happened.

I found a great tutorial from Adafruit at http://www.udoo.org/ProjectsAndTutorials/linux-gpio-manipulation/.  I slapped together some listener programs to watch the GPIO states, and I was suddenly in business again.  I no longer needed to upload any code to the Atmel chip on board - I could do it all in native C code, standard-Linux stuff.  Those tools were checked into the event server repository (subversion), and have been thoroughly tested.

Next, I needed to be able to work the garage door.  I toyed with building a separate, stand-alone device, but I'd already done that, and I was starting to get lazy.  I found a device on ebay, http://www.ebay.com/itm/111248757109?ssPageName=STRK:MEWNX:IT&_trksid=p3984.m1497.l2649, that was $50, and had two relays and Ethernet.  The downside is this came hard coded to an IP address of 192.168.1.199.  I had to use a crossover cable to connect it up, and reconfigure it to use DHCP.  It has a simple web-based interface.  So, being the nerd I am, I watched network traffic to see what requests were being sent.  When I'd click one of the relay buttons on the web page, it would send a request :
    http://192.168.1.199/relays.cgi?relay=1
    
When I turned it back off, it sent an identical request.  There was no "off" or "on" designation in the requests.  Apparently, the device simply took "toggle" commands".

I did find if I left off the ?relay=1, it simply gave me the following page:
    <div>
    <font size="5"> one                             <span style="color:red">0 </span> </font>
    <br />
    <br />
    <br />
    <font size="5"> two                             <span style="color:red">0 </span> </font>
    </div>
    
    <div>
    <p hidden>
    Status: 0 0 
    Relay1: one                          
    Relay2: two                          
    
Now I was getting somewhere.  I toggled it, ran the previous, and found that the "Status: 0 0" line went to "Status: 1 0".  It's a two relay board, so now I know how to get the current state.  Next, I needed to identify what had to be done to ensure it was always turning the switch off when it was done acting like a momentary push-button :
  1. Ensure the switch was in the off position.
  2. Toggle the switch to the "on" position.
  3. Wait for 1 second.
  4. Toggle the switch back to the "off" position.
So, I used the request without the "?relay=1" to get the "Status: " line for the relay I needed.  If it had a 1 for that one, I had to turn it off first.  In my case, it should ALWAYS be in the off position already.  Next, I had to toggle it to "on" position, and a simple request to the following would work perfectly :
    http://192.168.1.199/relays.cgi?relay=1
    
Then, I slept for a second, and then made that toggle request a second time to turn it off.  I hooked it up, and ran it.  Woohooo!  I'm back online again!  Here's the code I used :

#!/usr/bin/perl

use LWP;
use HTTP::Request;

my $relay_host = '192.168.1.199';
my $relay_index = 0;

my $ua = LWP::UserAgent->new('alarmsystem');
$ua->credentials($relay_host.':80',"Protected", 'admin', 'admin');

# FIRST - Ensure this thing is OFF
my $res = $ua->get('http://'.$relay_host.'/relays.cgi');
print $res->content;
exit;
if ($res->content =~ /status: ([\d\s]+)/i) {
  my (@rows) = split(/[\s\t]+/,$1);

  if ($rows[$relay_index] == 1) {
    my $res = $ua->get('http://'.$relay_host.'/relays.cgi?relay='.($relay_index+1));
  }
};

# SECOND - Turn it ON
my $res = $ua->get('http://'.$relay_host.'/relays.cgi?relay='.($relay_index+1));
# sleep for a second
sleep(1);
# LAST - Turn it back to OFF
my $res = $ua->get('http://'.$relay_host.'/relays.cgi?relay='.($relay_index+1));

Sunday, October 6, 2013

Steering Column - Coming Together

With some bad engineering drawings, a bad memory, and some skill with Tetris from growing up, I finally figured out how the steering column's Tilt/Telescopic components fit together.  There were a few steps to get me to a point that the Chevrolet manuals talked about :

  1. Find out how the light dimmer switch shaft sets into the housing.
  2. Find out how the turn signal switch connects to the dimmer switch (hint - it uses a plastic carrier that sets into a plastic shell that the tilt/telescopic lever runs through).
  3. Understand how the wiring fits into the wiper/turn signal switch carrier housing (that also houses the ignition lock cylinder)
  4. Locate a suitable pivot pin for the wiper/turn signal switch that connects the switch to the housing.
  5. Put that all together in one fell swoop (you kind of have to do this - without the housing, the parts will fall out, and without the parts in the right place, the housing won't connect.
For the pivot pin, I had lost mine, and found out that no one sells a replacement.  Goofing off, I realized that my Honda Civic (metric) had six bolts for the timing belt cover, and (since I had replaced the engine this year) I had the old bolts laying around.  Those bolts fit into the threads for the housing, and the shoulder on the bolt had a slightly larger diameter (that's a good thing) than what it should be (it wouldn't fit into the switch).  I grabbed my drill, slapped the bolt into the chuck, and grabbed a file.  I basically turned the shoulder without a lathe until it was the right size.

Then I ran out to grab the ratchet to install it..... and found the old pivot bolt still in the socket from nine months ago!  I compared them, and they were almost identical, the original had an extra pivot pin on the end (e.g. two shoulders of different sizes with a threaded section sandwiched in between).  The "replacement" would have still worked, but I opted for the original (anyone wonder why?).

I set about installing everything, and had success in getting those parts completely installed (complete with a new ignition lock cylinder).  Next up, finishing the rest of the assembly, which I can now use the AIM for (the assembly instruction/engineering diagrams at the factory).

Monday, September 23, 2013

Back to the Corvette - The Steering Column

I started trying to re-assemble the steering column, but didn't get anywhere.  Well, maybe I did.  I started checking the wiper switch, found that it wasn't working as the wiring diagram said it should, and started looking for new ones.  I failed to find one I could buy.

Over the weekend, I was chatting with my father, who asked me, "well, why not just rebuild your switch?  You've just about rebuilt everything else without knowing how it was engineered!"

It took a few days for that to fully sink in, and this morning, I asked myself, "why not?"

I took the switch completely out of the housing (just down to the plastic/contact pieces), and grabbed a drill bit (had to be the right size).  I started to drill the rivets (where you don't drill all the way through, you simply drill far enough into the rivet for it to separate), and used a pocket knife (great edge, not flimsy like an x-acto knife, perfect for prying apart without breaking the surrounding plastics).  That got my contacts off of the plastic frame for the switch.  Other than paint that had gotten into the switch and a wire that someone had cut, my switch was actually in great shape.

I used a wire brush to clean the contacts.

Before installing things, I thought it would be easier to solder in a new chunk of wire in the one that had been clipped.  I broke out the soldering iron, solder, heat shrink tubing, and slapped that puppy back together.  I added the contacts back to the switch frame, placed the eyelets, grabbed the rivets, and popped it all back together.

I needed to test it, but, since my voltmeter was not working (translation: I was too lazy to go buy a new 9v battery), I opted to get a better visual test for this.  I ran down and grabbed my Arduino Nano, connected the common point for the switch connector to ground, and slapped a modified button code onto it that defaulted with a pull-up resistor on three inputs, and three outputs to LED's.  This way, if the wire wasn't connected to ground, the LED would light up.  If it was connected to ground, the LED would turn off.

It gave me a great visual way to ensure that it was connected properly.  Now I can start to figure out the entire reassembly.  It will take some time, but once I get it, I'll have the steering column put back together fairly quickly, and then I can finally do the electrical test before connecting the battery to adjust the windows.  Getting one small step closer!


Wednesday, August 28, 2013

Corvette - Alarm Key Working

So, I had purchased an alarm switch off of eBay a while back for the Corvette (while working on the Civic).  I finally got around to having a lock smith take a look at the switch (I had no key, and it was advertised as "filling a hole" and was in "rough shape" according to the photos).  I had held the thing in my hand numerous times, and I've been wondering if it's possible to restore it to functionality.

Well, I finally overcame my fear and headed to the lock smith.  $26 later, I had the following :

  • A functional key to fit the switch - I needed to have them re-key, but didn't have that key with me.
  • Electrical testing operates as designed.
  • A feel good "That's the cleanest set of tumblers I've ever seen on something that old - I think they just never used it."
I'd install it, but I have one thing left to do - get it re-keyed to match the new ignition keys. Once that is done, it's time to install it, check the electrical, and then connect a battery so that I can get the window glass adjusted and the door and dash panels installed.  One small step, but it's been a hurdle.