extract read_card and send_uid functions
This commit is contained in:
parent
8300244767
commit
6719cabaa7
1 changed files with 37 additions and 25 deletions
60
the-cup.ino
60
the-cup.ino
|
|
@ -34,6 +34,9 @@ MFRC522DriverSPI driver_1{ss_1_pin};
|
|||
|
||||
MFRC522 reader{driver_1}; // Create MFRC522 instance.
|
||||
|
||||
void read_card(char reader_uid[]);
|
||||
void send_uid(char reader_uid[]);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
|
||||
|
|
@ -59,40 +62,49 @@ void setup() {
|
|||
}
|
||||
|
||||
void loop() {
|
||||
auto client = std::make_unique<BearSSL::WiFiClientSecure>();
|
||||
|
||||
if (reader.PICC_IsNewCardPresent() && reader.PICC_ReadCardSerial()) {
|
||||
reader.PICC_HaltA();
|
||||
reader.PCD_StopCrypto1();
|
||||
char reader_uid[32] = "";
|
||||
byte_to_string(reader.uid.uidByte, 4, reader_uid);
|
||||
Serial.println(reader_uid);
|
||||
read_card(reader_uid);
|
||||
send_uid(reader_uid);
|
||||
}
|
||||
}
|
||||
|
||||
client->setInsecure();
|
||||
HTTPClient https;
|
||||
Serial.print("[HTTPS] begin...\n");
|
||||
// configure traged server and url
|
||||
https.begin(*client, "https://mood.robiweb.net/rfid_tags"); // HTTP
|
||||
https.addHeader("Content-Type", "application/json");
|
||||
void read_card(char reader_uid[]) {
|
||||
reader.PICC_HaltA();
|
||||
reader.PCD_StopCrypto1();
|
||||
byte_to_string(reader.uid.uidByte, 4, reader_uid);
|
||||
Serial.println(reader_uid);
|
||||
}
|
||||
|
||||
// start connection and send HTTP header and body
|
||||
int httpCode = https.POST("{\"identifier\":\"" + String(reader_uid) + "\"}");
|
||||
Serial.print("httpCode: ");
|
||||
Serial.println(httpCode);
|
||||
void send_uid(char reader_uid[]) {
|
||||
auto client = std::make_unique<BearSSL::WiFiClientSecure>();
|
||||
|
||||
if (httpCode > 0) {
|
||||
if (httpCode == HTTP_CODE_CREATED) {
|
||||
displaySuccess();
|
||||
} else {
|
||||
displayError();
|
||||
}
|
||||
client->setInsecure();
|
||||
HTTPClient https;
|
||||
Serial.print("[HTTPS] begin...\n");
|
||||
// configure traged server and url
|
||||
https.begin(*client, "https://mood.robiweb.net/rfid_tags"); // HTTP
|
||||
https.addHeader("Content-Type", "application/json");
|
||||
|
||||
// start connection and send HTTP header and body
|
||||
int httpCode = https.POST("{\"identifier\":\"" + String(reader_uid) + "\"}");
|
||||
Serial.print("httpCode: ");
|
||||
Serial.println(httpCode);
|
||||
|
||||
if (httpCode > 0) {
|
||||
if (httpCode == HTTP_CODE_CREATED) {
|
||||
displaySuccess();
|
||||
} else {
|
||||
displayError();
|
||||
}
|
||||
|
||||
https.end();
|
||||
Serial.print("[HTTPS] ended...\n");
|
||||
} else {
|
||||
displayError();
|
||||
}
|
||||
|
||||
https.end();
|
||||
Serial.print("[HTTPS] ended...\n");
|
||||
|
||||
}
|
||||
|
||||
void byte_to_string(byte array[], unsigned int len, char buffer[]) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue