diff --git a/examples/ReadCard/ReadCard.ino b/examples/ReadCard/ReadCard.ino index 2043fb5..37d6b99 100644 --- a/examples/ReadCard/ReadCard.ino +++ b/examples/ReadCard/ReadCard.ino @@ -11,7 +11,6 @@ #include "Spacecat.h" - #define RC522_SS_PIN 15 Spacecat cat; @@ -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); + } diff --git a/examples/SimpleValidation/SimpleValidation.ino b/examples/SimpleValidation/SimpleValidation.ino index e886d25..7f3ef7d 100644 --- a/examples/SimpleValidation/SimpleValidation.ino +++ b/examples/SimpleValidation/SimpleValidation.ino @@ -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 @@ -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); @@ -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(); } + }