diff --git a/the-cup.ino b/the-cup.ino index 82dc3ac..4f1bbea 100644 --- a/the-cup.ino +++ b/the-cup.ino @@ -62,10 +62,11 @@ void loop() { auto client = std::make_unique(); if (reader.PICC_IsNewCardPresent() && reader.PICC_ReadCardSerial()) { - // Halt PICC. reader.PICC_HaltA(); - // Stop encryption on PCD. reader.PCD_StopCrypto1(); + char reader_uid[32] = ""; + byte_to_string(reader.uid.uidByte, 4, reader_uid); + Serial.println(reader_uid); client->setInsecure(); HTTPClient https; @@ -74,18 +75,12 @@ void loop() { https.begin(*client, "https://mood.robiweb.net/rfid_tags"); // HTTP https.addHeader("Content-Type", "application/json"); - char str[32] = ""; - array_to_string(reader.uid.uidByte, 4, str); //Insert (byte array, length, char array for output) - Serial.println(str); //Print the output uid string // start connection and send HTTP header and body - int httpCode = https.POST("{\"identifier\":\"" + String(str) + "\"}"); + int httpCode = https.POST("{\"identifier\":\"" + String(reader_uid) + "\"}"); Serial.print("httpCode: "); - Serial.print(httpCode); - // httpCode will be negative on error + Serial.println(httpCode); + if (httpCode > 0) { - // HTTP header has been send and Server response header has been handled - // file found at server - // if (httpCode == HTTP_CODE_OK) { if (httpCode == HTTP_CODE_CREATED) { displaySuccess(); } else { @@ -100,7 +95,7 @@ void loop() { } } -void array_to_string(byte array[], unsigned int len, char buffer[]) { +void byte_to_string(byte array[], unsigned int len, char buffer[]) { for (unsigned int i = 0; i < len; i++) { byte nib1 = (array[i] >> 4) & 0x0F;