Difference between revisions of "ACKsess"

From Hackerspace ACKspace
Jump to: navigation, search
m
(full update on implementation)
Line 8: Line 8:
 
knock knock.
 
knock knock.
  
 +
=== current implementation ===
  
 +
==== hardware ====
 +
 +
===== arduino Mega 1280 =====
 +
Used the arduino to get it working quickly, new design should be underway (by someone else).
 +
[[User:Xopr|Xopr]] made a mini prototype shield where the onewire pullup sits, the NPN transistor (to switch the 12Vin via the relay to ground), the LED, external button and some extra ground connections.
 +
 +
You can add a usb A to B cable for debugging on 115200 baud.
 +
 +
===== proto shield =====
 +
 +
The shield fetches power and uses some of the digital I/O 0 to 7.
 +
 +
'''Arduino pins'''
 +
# TxD, not used
 +
# relay pin, set high to pull breakout pin X to low
 +
# led pin, uses pwm heart beat every 5 seconds and blinks fast if the door is unlocked
 +
# reader pin: the onewire data pin
 +
# button pin: for use for external opener, pullup (connect to ground to trigger)
 +
 +
breakout pins:
 +
<pre>
 +
,_________
 +
|
 +
|o external open (pullup, connect to ground to trigger)
 +
|o onewire data (probe green)
 +
|o led + (probe orange)
 +
|o Vin (12v for relay) (bundle-with-orange)
 +
|o door-open (GND-switch) (bundle-with-blue)
 +
|o GND (currently not connected, for use with external button)
 +
|o GND (probe orange)
 +
|o GND (probe blue)                  o o o
 +
|                                    e b c NPN transistor
 +
'__________
 +
</pre>
 +
* The NPN transistor used is a BC548 (goes up to 500mA), drived with a 100-300 something ohm resistor on the base (from the top of my head).
 +
* Note that is has a diode (1n4000 something) antiparallel between collector and emittor as coil reverse voltage protection
 +
* The onewire pull up used is 4k7 to 5v
 +
 +
===== DS9092L iButton probe =====
 +
I had to reverse engineer the wiring somewhat (connector was gone), but here it is:
 
[http://datasheets.maximintegrated.com/en/ds/DS9092L.pdf DS9092L iButton probe datasheet]
 
[http://datasheets.maximintegrated.com/en/ds/DS9092L.pdf DS9092L iButton probe datasheet]
 
Pinout:
 
Pinout:
 
# GND (blue)
 
# GND (blue)
# Data (onewire)
+
# Data (onewire) (green)
# LED cathode (-)
+
# LED cathode (-) (yellow)
# LED anode (+)
+
# LED anode (+) (orange)
 +
 
 +
 
 +
==== software ====
 +
Most of ACKsess.ino:
 +
<pre>
 +
#include <OneWire.h>
 +
 
 +
const int relayPin = 3;      // the number of the relay pin
 +
const int ledPin    = 4;    // the number of the LED pin (change to 13 to see the onboard led)
 +
const int readerPin = 5;    // the number of the iButton reader pin
 +
const int buttonPin = 6;    // the number of the pushbutton pin
 +
 
 +
OneWire ds( readerPin );
 +
byte addr[ 8 ];
 +
String keyStatus = "";
 +
 
 +
// Buttons, first defense
 +
byte but[][6] = {
 +
  /* ADD YOUR BUTTONS HERE */
 +
};
 +
 
 +
void setup(void)
 +
{
 +
  Serial.begin( 115200 );
 +
  pinMode( buttonPin, INPUT_PULLUP );
 +
  pinMode( ledPin, OUTPUT );
 +
  pinMode( relayPin, OUTPUT );
 +
 
 +
  Serial.println( "ACKsess initialized" );
 +
  Serial.print( "number of keys: " );
 +
  Serial.println( sizeof( but ) / 6 );
 +
 
 +
  // Open the door upon power up and (on board) reset
 +
  openDoor( );
 +
}
 +
 
 +
byte nState = 0;
 +
byte nLedVal = 0;
 +
 
 +
void loop(void)
 +
{
 +
  switch ( nState )
 +
  {
 +
    case 0: // forward, led fade in
 +
      nLedVal++;
 +
      if ( nLedVal >= 255 )
 +
        nState++;
 +
 
 +
      analogWrite( ledPin, nLedVal );
 +
      delay( 1 );
 +
      break;
 +
 
 +
    case 1: // backward, led fade out
 +
      nLedVal--;
 +
      if ( nLedVal <= 0 )
 +
        nState++;
 +
 
 +
      analogWrite( ledPin, nLedVal );
 +
          delay( 1 );
 +
      break;
 +
 
 +
    default: // idle
 +
        nState++;
 +
        delay( 500 );
 +
 
 +
        if ( nState >= 10 )
 +
          nState = 0;
 +
 
 +
      break;
 +
  };
 +
 
 +
  // If the external button was pushed, open the door
 +
  if ( digitalRead( buttonPin ) == LOW )
 +
    openDoor( );
 +
 
 +
  // Check keys twice each fade and on every idle state step
 +
  if ( (nLedVal == 127) || ( nState > 1 ) )
 +
  {
 +
    // Store the button info and read the keycode
 +
    getKeyCode( );
 +
    if( keyStatus == "ok" )
 +
    {
 +
      // We have a correct key type, authenticate it
 +
      Serial.print("00");
 +
      for( byte i = 5; i > 0; i--)
 +
      {
 +
        Serial.print(":");
 +
        Serial.print(addr[i], HEX);
 +
      }
 +
      Serial.println("");
 +
 
 +
      // Either open the door, or lock the system for 30 seconds
 +
      if ( authenticateKey( addr ) )
 +
      {
 +
        openDoor( );
 +
      }
 +
      else
 +
      {
 +
        Serial.println( "ACKsess denied!" );
 +
        delay( 30000 );
 +
      }
 +
    }
 +
  }
 +
}
 +
 
 +
void openDoor()
 +
{
 +
  Serial.println( "ACKsess!" );
 +
 
 +
  // Trigger the relay
 +
  digitalWrite( relayPin, HIGH );
 +
 
 +
  // Blink the led fast for about 3 seconds
 +
  for ( byte n = 0; n < 15; n++ )
 +
  {
 +
    digitalWrite( ledPin, HIGH );
 +
    delay( 100 );
 +
    digitalWrite( ledPin, LOW );
 +
    delay( 100 );
 +
  }
 +
 
 +
  // Relay off
 +
  digitalWrite( relayPin, LOW );
 +
}
 +
 
 +
void getKeyCode()
 +
{
 +
  byte present = 0;
 +
  byte data[ 12 ];
 +
  keyStatus="";
 +
 
 +
  if ( !ds.search( addr ) )
 +
  {
 +
    ds.reset_search( );
 +
    return;
 +
  }
 +
 
 +
  if ( OneWire::crc8( addr, 7) != addr[ 7 ] )
 +
  {
 +
    keyStatus = "CRC invalid";
 +
    return;
 +
  }
 +
 
 +
  keyStatus = "ok";
 +
  ds.reset( );
 +
}
 +
 
 +
boolean authenticateKey( byte* _button )
 +
{
 +
  /* SECURITY THROUGH OBSCURITY, VISIT US TO SEE SOME EXAMPLES */
 +
  return false;
 +
}
 +
</pre>

Revision as of 23:20, 9 November 2014

Project: ACKsess
Featured:
State Active
Members Vicarious, Prodigity, xopr
GitHub No GitHub project defined. Add your project here.
Description Knock knock.
Picture
No project picture! Fill in form Picture or Upload a jpeg here


synopsis

knock knock.

current implementation

hardware

arduino Mega 1280

Used the arduino to get it working quickly, new design should be underway (by someone else). Xopr made a mini prototype shield where the onewire pullup sits, the NPN transistor (to switch the 12Vin via the relay to ground), the LED, external button and some extra ground connections.

You can add a usb A to B cable for debugging on 115200 baud.

proto shield

The shield fetches power and uses some of the digital I/O 0 to 7.

Arduino pins

  1. TxD, not used
  2. relay pin, set high to pull breakout pin X to low
  3. led pin, uses pwm heart beat every 5 seconds and blinks fast if the door is unlocked
  4. reader pin: the onewire data pin
  5. button pin: for use for external opener, pullup (connect to ground to trigger)

breakout pins:

,_________
|
|o external open (pullup, connect to ground to trigger)
|o onewire data (probe green)
|o led + (probe orange)
|o Vin (12v for relay) (bundle-with-orange)
|o door-open (GND-switch) (bundle-with-blue)
|o GND (currently not connected, for use with external button)
|o GND (probe orange)
|o GND (probe blue)                   o o o
|                                     e b c NPN transistor
'__________
  • The NPN transistor used is a BC548 (goes up to 500mA), drived with a 100-300 something ohm resistor on the base (from the top of my head).
  • Note that is has a diode (1n4000 something) antiparallel between collector and emittor as coil reverse voltage protection
  • The onewire pull up used is 4k7 to 5v
DS9092L iButton probe

I had to reverse engineer the wiring somewhat (connector was gone), but here it is: DS9092L iButton probe datasheet Pinout:

  1. GND (blue)
  2. Data (onewire) (green)
  3. LED cathode (-) (yellow)
  4. LED anode (+) (orange)


software

Most of ACKsess.ino:

#include <OneWire.h>

const int relayPin = 3;      // the number of the relay pin
const int ledPin    = 4;     // the number of the LED pin (change to 13 to see the onboard led)
const int readerPin = 5;     // the number of the iButton reader pin
const int buttonPin = 6;     // the number of the pushbutton pin

OneWire ds( readerPin );
byte addr[ 8 ];
String keyStatus = "";

// Buttons, first defense
byte but[][6] = {
  /* ADD YOUR BUTTONS HERE */
};

void setup(void)
{
  Serial.begin( 115200 );
  pinMode( buttonPin, INPUT_PULLUP );
  pinMode( ledPin, OUTPUT );
  pinMode( relayPin, OUTPUT );
  
  Serial.println( "ACKsess initialized" );
  Serial.print( "number of keys: " );
  Serial.println( sizeof( but ) / 6 );

  // Open the door upon power up and (on board) reset
  openDoor( );
}

byte nState = 0;
byte nLedVal = 0;

void loop(void)
{
  switch ( nState )
  {
    case 0: // forward, led fade in
      nLedVal++;
      if ( nLedVal >= 255 )
        nState++;

      analogWrite( ledPin, nLedVal );
      delay( 1 );
      break;

    case 1: // backward, led fade out
      nLedVal--;
      if ( nLedVal <= 0 )
        nState++;

      analogWrite( ledPin, nLedVal );
          delay( 1 );
      break;

    default: // idle
        nState++;
        delay( 500 );

        if ( nState >= 10 )
          nState = 0;

      break;
  };

  // If the external button was pushed, open the door
  if ( digitalRead( buttonPin ) == LOW )
    openDoor( );

  // Check keys twice each fade and on every idle state step
  if ( (nLedVal == 127) || ( nState > 1 ) )
  {
    // Store the button info and read the keycode
    getKeyCode( );
    if( keyStatus == "ok" )
    {
      // We have a correct key type, authenticate it
      Serial.print("00");
      for( byte i = 5; i > 0; i--)
      {
        Serial.print(":");
        Serial.print(addr[i], HEX);
      }
      Serial.println("");

      // Either open the door, or lock the system for 30 seconds
      if ( authenticateKey( addr ) )
      {
        openDoor( );
      }
      else
      {
        Serial.println( "ACKsess denied!" );
        delay( 30000 );
      }
    }
  }
}

void openDoor()
{
  Serial.println( "ACKsess!" );

  // Trigger the relay
  digitalWrite( relayPin, HIGH );

  // Blink the led fast for about 3 seconds
  for ( byte n = 0; n < 15; n++ )
  {
    digitalWrite( ledPin, HIGH );
    delay( 100 );
    digitalWrite( ledPin, LOW );
    delay( 100 );
  }

  // Relay off
  digitalWrite( relayPin, LOW );
}

void getKeyCode()
{
  byte present = 0;
  byte data[ 12 ];
  keyStatus="";

  if ( !ds.search( addr ) )
  {
    ds.reset_search( );
    return;
  }

  if ( OneWire::crc8( addr, 7) != addr[ 7 ] )
  {
    keyStatus = "CRC invalid";
    return;
  }

  keyStatus = "ok";
  ds.reset( );
}

boolean authenticateKey( byte* _button )
{
  /* SECURITY THROUGH OBSCURITY, VISIT US TO SEE SOME EXAMPLES */
  return false;
}