refacto
This commit is contained in:
parent
c6c70dca76
commit
6cbe39dca9
1 changed files with 15 additions and 20 deletions
35
the-cup.ino
35
the-cup.ino
|
|
@ -19,7 +19,6 @@
|
||||||
#include <MFRC522DriverPinSimple.h>
|
#include <MFRC522DriverPinSimple.h>
|
||||||
#include <MFRC522Debug.h>
|
#include <MFRC522Debug.h>
|
||||||
|
|
||||||
#define LED_PIN LED_BUILTIN
|
|
||||||
#define SS_PIN SDA
|
#define SS_PIN SDA
|
||||||
#define RC522_POWER_PIN 1
|
#define RC522_POWER_PIN 1
|
||||||
#define SLEEP_DURATION 1
|
#define SLEEP_DURATION 1
|
||||||
|
|
@ -71,20 +70,19 @@ void send_uid(char reader_uid[]);
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
delay(1000);
|
while (!Serial) delay(10);
|
||||||
|
|
||||||
pinMode(LED_PIN, OUTPUT);
|
|
||||||
|
|
||||||
pinMode(RC522_POWER_PIN, OUTPUT);
|
pinMode(RC522_POWER_PIN, OUTPUT);
|
||||||
digitalWrite(RC522_POWER_PIN, HIGH);
|
|
||||||
reader.PCD_Init(); // Init each MFRC522 card.
|
reader.PCD_Init(); // Init each MFRC522 card.
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
digitalWrite(RC522_POWER_PIN, HIGH);
|
||||||
|
|
||||||
if (reader.PICC_IsNewCardPresent() && reader.PICC_ReadCardSerial()) {
|
if (reader.PICC_IsNewCardPresent() && reader.PICC_ReadCardSerial()) {
|
||||||
char reader_uid[32] = "";
|
char reader_uid[32] = "";
|
||||||
read_card(reader_uid);
|
readCard(reader_uid);
|
||||||
send_uid(reader_uid);
|
sendUid(reader_uid);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
delay(200);
|
delay(200);
|
||||||
|
|
@ -93,7 +91,7 @@ void loop() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void read_card(char reader_uid[]) {
|
void readCard(char reader_uid[]) {
|
||||||
reader.PICC_HaltA();
|
reader.PICC_HaltA();
|
||||||
reader.PCD_StopCrypto1();
|
reader.PCD_StopCrypto1();
|
||||||
byte_to_string(reader.uid.uidByte, 4, reader_uid);
|
byte_to_string(reader.uid.uidByte, 4, reader_uid);
|
||||||
|
|
@ -101,7 +99,12 @@ void read_card(char reader_uid[]) {
|
||||||
displaySuccess();
|
displaySuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
void send_uid(char reader_uid[]) {
|
void sendUid(char reader_uid[]) {
|
||||||
|
connectToWifi();
|
||||||
|
postUid(reader_uid);
|
||||||
|
}
|
||||||
|
|
||||||
|
void connectToWifi() {
|
||||||
WiFiManager wm;
|
WiFiManager wm;
|
||||||
bool res;
|
bool res;
|
||||||
res = wm.autoConnect("KLUK"); // password protected ap
|
res = wm.autoConnect("KLUK"); // password protected ap
|
||||||
|
|
@ -115,6 +118,8 @@ void send_uid(char reader_uid[]) {
|
||||||
//if you get here you have connected to the WiFi
|
//if you get here you have connected to the WiFi
|
||||||
Serial.println("connected...yeey :)");
|
Serial.println("connected...yeey :)");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
void postUid(char reader_uid[]) {
|
||||||
NetworkClientSecure *client = new NetworkClientSecure;
|
NetworkClientSecure *client = new NetworkClientSecure;
|
||||||
client->setCACert(rootCACertificate);
|
client->setCACert(rootCACertificate);
|
||||||
HTTPClient https;
|
HTTPClient https;
|
||||||
|
|
@ -155,7 +160,7 @@ void byte_to_string(byte array[], unsigned int len, char buffer[]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void displayError() {
|
void displayError() {
|
||||||
rgbLedWrite(RGB_BUILTIN, RGB_BRIGHTNESS, 0, 0); // Green
|
rgbLedWrite(RGB_BUILTIN, RGB_BRIGHTNESS, 0, 0); // Red
|
||||||
delay(1000);
|
delay(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -163,13 +168,3 @@ void displaySuccess() {
|
||||||
rgbLedWrite(RGB_BUILTIN, 0, RGB_BRIGHTNESS, 0); // Green
|
rgbLedWrite(RGB_BUILTIN, 0, RGB_BRIGHTNESS, 0); // Green
|
||||||
delay(1000);
|
delay(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
void blink(unsigned int times, unsigned int duration) {
|
|
||||||
for (unsigned int i = 0; i < times; i++)
|
|
||||||
{
|
|
||||||
digitalWrite(LED_PIN, HIGH);
|
|
||||||
delay(duration);
|
|
||||||
digitalWrite(LED_PIN, LOW);
|
|
||||||
delay(duration);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue