Skip to content

Commit

Permalink
examples for v1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Asyasyarif committed Apr 26, 2020
1 parent d97f2e9 commit 5f22b61
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 59 deletions.
14 changes: 5 additions & 9 deletions examples/ReadCard/ReadCard.ino
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

#include "Spacecat.h"


#define RC522_SS_PIN 15
Spacecat cat;

Expand All @@ -20,16 +19,13 @@ void setup(){
Serial.begin(115200);

//the reset pin of RC522 connected to Ground (GND)
cat.RC522_PIN(RC522_SS_PIN);
Serial.println("ready");
cat.begin(RC522_SS_PIN);
}

void loop(){

if(cat.readCard()){
Serial.print("RFID: ");
Serial.println(cat.RFID());
}
delay (200);

cat.readCard();
delay (10);

}

89 changes: 39 additions & 50 deletions examples/SimpleValidation/SimpleValidation.ino
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,22 @@
* Spacecat requires :
* RC522 : https://github.com/miguelbalboa/rfid
* ArduinoJson : https://github.com/bblanchon/ArduinoJson
* - use the latest version (Currently is 6.14.1)
* - im use the latest version (Currently is 6.14.1)
*
* An simple example of how to auth the User
* - SUCCEED
* - FILL_THE_PASSWORD
* - ERR_NOT_FOUND
* - UNSUCCESSFULL
*
* -- SUCCEED
* if Users registered and don't have a Password,
* it will automatically accepted
*
* -- FILL_THE_PASSWORD
* for example i'm use hard code for password : "12345678",
* if the User Password is match, you'll get a messages on serial Monitor "Password Correct"
* and if Wrong you'll get "Wrong Password"
* for real purpose it must have to use keypad,
* and put User Password into *.enterpassword attributes.
*
* -- UNSUCCESSFULL
* this case if User, Placment or the Rule does not meet the conditions
*
* An simple example of how to auth the User :
* you can very easily manage user, placement, and can also add the rule for each placement
*
* Every you doing tap card or request to server, You definitely get a return value :
* 101 Project not active
* 102 User not active
* 103 Placement not
* 104 SUCCEED
* 105 UNSUCCESSFULL
* 106 Invalid Password
* 107 User Need Fill the Password
* 108 User reach the limit of parameter
* 109 Not Found
*
*
* Written by Arif @2019.
* Bandung, Indonesia
Expand All @@ -39,13 +33,31 @@
const char WIFI_SSID[] = ""; // your network SSID (name)
const char WIFI_PASSWORD[] = ""; // your network password

const char DEVICE_NAME[] = "Device 1";
const char DEVICE_NAME[] = "";
const char SPACECAT_USERNAME[] = "";
const char SPACECAT_PASSWORD[] = "";

#define RC522_SS_PIN 15

Spacecat cat(SPACECAT_USERNAME, SPACECAT_PASSWORD, DEVICE_NAME);

void handleCallback(int code, String refrenceID, String name, String messages){

Serial.print("Code : ");
Serial.println(code);

Serial.print("Ref : ");
Serial.println(refrenceID);

Serial.print("Name : ");
Serial.println(name);

Serial.print("Messages : ");
Serial.println(messages);

}


void setup() {
//for debuging purpose
Serial.begin(115200);
Expand All @@ -67,39 +79,16 @@ void setup() {
Serial.println("WiFi connected");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());

//the Reset pin of RC522 connected to Ground (GND)
cat.RC522_PIN(RC522_SS_PIN);
cat.begin();

cat.begin(RC522_SS_PIN);
cat.setSimpleCallback(&handleCallback);
}


void loop() {

if(WiFi.status() == WL_CONNECTED){

switch (cat.validate()){

case SUCCEED:
Serial.printf("User Authenticated : %s ", cat.Name().c_str());
break;

//Password 12345678 is just example, change it with your password
case FILL_THE_PASSWORD:
Serial.println("Insert Password :");
if(cat.enteredPassword("123456")){
Serial.println("Password Correct");
}else{
Serial.println("Wrong Password");
}
break;

case UNSUCCESSFULL:
Serial.printf("Failed : %s", cat.Messages().c_str());
break;

default:
break;
}
cat.loop();
}

}

0 comments on commit 5f22b61

Please sign in to comment.