Nfc-ing a lock

project_locks

(Daniel Consuegra) #1

I’ve read it her somewhere but I’ve not found the actual process, including parts and software, of getting a smart lock like the Danalock to act when a certain NFC card is swiped…

Hope the guys who’ve done it read this post!

I live in Spain and have a mortise for of lock…

So far I’ve only seen the Danalock as compatible… But if you have other options, feel free to write them here too!

Thanks!


(ActionTiles.com co-founder Terry @ActionTiles; GitHub: @cosmicpuppy) #2

Off the top of my head…

Use an spare “old” Android phone as the NFC reader. Lots of Apps available that can call Tasker upon sensing registered cards and then it uses SmartThings App to open lock.


(Daniel Consuegra) #3

Item checklist

SmartThings hub - check!
Old Android - check!
NFC card - check!
Tasker app on old phone - check!
NFC to Bluetooth or microusb interface - failed!

Any idea how to get NFC to the old phone? I once saw a Bluetooth/NFC device but it wasn’t available to regular consumers… :cry:


#4

I don’t know about Spain.

In the US, most android phones sold in the last two years have an NFC chip and reader built in, that’s how Google Pay works. Nothing to do with bluetooth. So you just pick an app you like.


(Daniel Consuegra) #5

Spain is waaaaay behind in that sense… Ooh well… I’ll have to keep looking for a solution…

Thanks!!!


(Daniel Consuegra) #6

Bingo!!!

I had it there all the time!

http://thinkmakelab.com/2014/10/22/rfid-and-smartthings-how-to/#more-213

Now if only @juano2310 would help in pointing out which arduino to get… That would be awesome…

And if he or anyone can then help creating a smartapp that will unlock a given lock if x cards show up…

Ahhh… Wish I knew how to code in groovy…

Any cool tutorials out there?


(ActionTiles.com co-founder Terry @ActionTiles; GitHub: @cosmicpuppy) #7

I hesitate to recommend any project that requires the ThingShield because those are frequently out of stock for a long time. I guess it would be a very helpful project for someone to create a WiFi (LAN) based library and Device Handler.

Anyhow… You can start learning Groovy for SmartApps and Device Handlers by following the new SmartThings documentation, as they’ve really improved over the past few months. This project won’t require too complicated code.

One common starting place is also:
http://learnxinyminutes.com/docs/groovy/

And Google: “Groovy web console”.

And drop me a PM anytime with questions.


(Juan Risso) #8

Hi @danielccm,
I did an integration, for an other project, using a https://store.particle.io/?product=particle-photon and a NFC reader. It works great with SmartThings. I can try to dig the code if you are interested :slight_smile:


(Alex) #9

@juano2310, which hardware did you use for the NFC reader?


(Juan Risso) #10

You can use any NFC I2C or UART reader.
For my project I used this one http://www.stronglink-rfid.com/en/rfid-modules/sl030.html


(Daniel Consuegra) #11

Mine is more of a mid term project but yeah! Would be cool to see the code! Thanks!


(Denis Grabocka) #12

@juano2310 I was researching for NFC and ST integration and i ran across your post here on this thread.
I am trying to use an NFC reader that when approached by an NFC ring will turn a switch off that controls a magnet lock. I am pretty sure it needs a NFC reader and something in between ST and the reader such as a Raspberry Pi or a ESP8266 or a Photon in your case ( i have personally never used a Photon) but i will be very interested on how to achieve this. Please let me know if you have any pointers for me it is beyond my programming capabilities to write a SmartApp that will store nfc values and match them when scanned from a server of sorts and than react to i.
I did not mention that i have achieved this with my android phone already with Josh’s help and SharpTools where you approach the phone that you carry to a static nfc than the phone through tasker takes care of the rest but i want to do it with the reader being static and other people to use their nfc tags as they get close to it.
let me know if you can help anything is greatly appreciated
Denis


(Juan Risso) #13

Hi Denis!
I used a particle Photon and a http://www.stronglink-rfid.com/en/rfid-modules/sl030.html

Photon to SL030 wiring:

  • A3/TAG 5
  • A4/SDA 3
  • A5/SCL 4
  • 5V -
  • GND 6
  • 3V3 1

Here is the code I used to capture the ID :slight_smile: If I’m correct you should see the ID in particle console. There is an IFTTT and SmartThings integration, I imagine you can open an lock or turn a light on with this :slight_smile:

int led = D7; 
int TAG = A3; 

char* mifare[] = { "1K", "Pro", "UltraLight", "4K", "ProX", "DesFire" };

void setup()
{
  // Init serial port to host and I2C interface to SL018/SL030
  Serial.begin(19200);
  Wire.begin();

  // Initialize D0 pin as an output
  pinMode(led, OUTPUT);
  pinMode(TAG, INPUT);
  
  // Prompt for tag
  Serial.println("Show me your tag");
}

void loop()
{
  // Wait for tag
  //while(digitalRead(TAG));
  if (digitalRead(TAG) == LOW) {   
    // Read tag ID
    readID();
  } 
  // Wait until tag is gone
  //while(!digitalRead(TAG));
}

int readID()
{
  digitalWrite(led, HIGH);
  
  // Send SELECT command
  Wire.beginTransmission(0x50);
  Wire.write(1);
  Wire.write(1);
  Wire.endTransmission();
  
 // Wait for response
  while(!digitalRead(TAG))
  {
    // Allow some time to respond
    delay(5);
    String ID;
    
    // Anticipate maximum packet size
    Wire.requestFrom(0x50, 11);
    if(Wire.available())
    {
      // Get length of packet
      byte len = Wire.read();
      
      // Wait until whole packet is received
      while(Wire.available() < len)
      {
        // Quit if no response before tag left
        if(digitalRead(TAG)) { return 0; digitalWrite(led, LOW);}
      }

      // Read command code, should be same as request (1)
      byte command = Wire.read();
      if(command != 1) { return -1; digitalWrite(led, LOW);}
      
      // Read status
      byte status = Wire.read();
      
      switch(status)
      {
        case 0: // Succes, read ID and tag type
        {
          len -= 2;
          // Get tag ID
          while(--len)
          {
            byte data = Wire.read();
            
            if(data < 0x10) {
                Serial.print(0);
                ID += "0"; 
            }    
            
            ID += String(data);
            Serial.print(data, HEX);
          }


          Serial.println(ID);
          Spark.publish("update", ID);
          
          // Get tag type
          byte type = Wire.read();
          if(type > 0 && type < sizeof(mifare))
          {
            Serial.print(" Mifare ");
            Serial.print(mifare[type - 1]);
          }
          Serial.println();
        }
        digitalWrite(led, LOW);
        delay(700);
        return 1;

      case 0x0A: // Collision
        Serial.println("Collision detected");
        break;

      case 1: // No tag
        Serial.println("No tag found");
        break;

      default: // Unexpected
        Serial.println("Unexpected result");
      }
      digitalWrite(led, LOW);
      return -1;
    }
  }
  // No tag found or no response
  digitalWrite(led, LOW);
  return 0;
}

[RELEASE] ST_Anything v2.9.2 - Arduino/ESP8266/ESP32 to ST via ThingShield, Ethernet, or WiFi
(Denis Grabocka) #14

Thank you fr your reply buddy
i am going to order the parts and try it out
i will e bothering you some more if i get stuck please forgive me LOL :slight_smile:
Denis


(Juan Risso) #16

No problem at all! I’m here to help :slight_smile: