From eaeb9dcfe926980874c1af74a9c004d55d49fea6 Mon Sep 17 00:00:00 2001 From: Christophe Robillard Date: Tue, 23 Dec 2025 18:45:04 +0100 Subject: [PATCH] show debug only if flag --- the-cup.ino | 44 +++++++++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/the-cup.ino b/the-cup.ino index d009988..323e4d9 100644 --- a/the-cup.ino +++ b/the-cup.ino @@ -69,10 +69,12 @@ void read_card(char reader_uid[]); void send_uid(char reader_uid[]); void setup() { - Serial.begin(115200); - while (!Serial) delay(10); - Serial.print("Nb cycles: "); - Serial.println(nbCycles++); + #ifdef DEBUG + Serial.begin(115200); + while (!Serial) delay(10); + Serial.print("Nb cycles: "); + Serial.println(nbCycles++); + #endif pinMode(RC522_POWER_PIN, OUTPUT); digitalWrite(RC522_POWER_PIN, HIGH); @@ -96,7 +98,9 @@ void readCard(char reader_uid[]) { reader.PICC_HaltA(); reader.PCD_StopCrypto1(); byte_to_string(reader.uid.uidByte, 4, reader_uid); - Serial.println(reader_uid); + #ifdef DEBUG + Serial.println(reader_uid); + #endif displaySuccess(); } @@ -111,42 +115,56 @@ void connectToWifi() { res = wm.autoConnect("KLUK"); // password protected ap if(!res) { - Serial.println("Failed to connect"); + #ifdef DEBUG + Serial.println("Failed to connect"); + #endif displayError(); // ESP.restart(); } else { //if you get here you have connected to the WiFi + #ifdef DEBUG Serial.println("connected...yeey :)"); + #endif } } void postUid(char reader_uid[]) { NetworkClientSecure *client = new NetworkClientSecure; client->setCACert(rootCACertificate); HTTPClient https; - Serial.print("[HTTPS] begin...\n"); + #ifdef DEBUG + Serial.print("[HTTPS] begin...\n"); + #endif // configure traged server and url https.begin("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); + #ifdef DEBUG + Serial.print("httpCode: "); + Serial.println(httpCode); + #endif if (httpCode > 0) { if (httpCode == HTTP_CODE_CREATED) { } else { - Serial.println("Remote error while sending uid"); + #ifdef DEBUG + Serial.println("Remote error while sending uid"); + #endif displayError(); } } else { - Serial.print("Remote error while sending uid"); - displayError(); + #ifdef DEBUG + Serial.print("Remote error while sending uid"); + #endif + displayError(); } https.end(); - Serial.print("[HTTPS] ended...\n"); + #ifdef DEBUG + Serial.print("[HTTPS] ended...\n"); + #endif } void byte_to_string(byte array[], unsigned int len, char buffer[]) {