petit refacto
This commit is contained in:
parent
d236d3e71c
commit
8300244767
1 changed files with 7 additions and 12 deletions
19
the-cup.ino
19
the-cup.ino
|
|
@ -62,10 +62,11 @@ void loop() {
|
|||
auto client = std::make_unique<BearSSL::WiFiClientSecure>();
|
||||
|
||||
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;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue