extract read_card and send_uid functions

This commit is contained in:
Christophe Robillard 2025-11-08 11:10:37 +01:00
parent 8300244767
commit 6719cabaa7

View file

@ -34,6 +34,9 @@ MFRC522DriverSPI driver_1{ss_1_pin};
MFRC522 reader{driver_1}; // Create MFRC522 instance. MFRC522 reader{driver_1}; // Create MFRC522 instance.
void read_card(char reader_uid[]);
void send_uid(char reader_uid[]);
void setup() { void setup() {
Serial.begin(115200); Serial.begin(115200);
@ -59,14 +62,23 @@ void setup() {
} }
void loop() { void loop() {
auto client = std::make_unique<BearSSL::WiFiClientSecure>();
if (reader.PICC_IsNewCardPresent() && reader.PICC_ReadCardSerial()) { if (reader.PICC_IsNewCardPresent() && reader.PICC_ReadCardSerial()) {
char reader_uid[32] = "";
read_card(reader_uid);
send_uid(reader_uid);
}
}
void read_card(char reader_uid[]) {
reader.PICC_HaltA(); reader.PICC_HaltA();
reader.PCD_StopCrypto1(); reader.PCD_StopCrypto1();
char reader_uid[32] = "";
byte_to_string(reader.uid.uidByte, 4, reader_uid); byte_to_string(reader.uid.uidByte, 4, reader_uid);
Serial.println(reader_uid); Serial.println(reader_uid);
}
void send_uid(char reader_uid[]) {
auto client = std::make_unique<BearSSL::WiFiClientSecure>();
client->setInsecure(); client->setInsecure();
HTTPClient https; HTTPClient https;
@ -92,7 +104,7 @@ void loop() {
https.end(); https.end();
Serial.print("[HTTPS] ended...\n"); Serial.print("[HTTPS] ended...\n");
}
} }
void byte_to_string(byte array[], unsigned int len, char buffer[]) { void byte_to_string(byte array[], unsigned int len, char buffer[]) {