From 5040bae41905157d388f480f7c79591b49085059 Mon Sep 17 00:00:00 2001 From: Christophe Robillard Date: Thu, 6 Nov 2025 16:47:34 +0100 Subject: [PATCH] indentation with 2 spaces --- the-cup.ino | 150 ++++++++++++++++++++++++++-------------------------- 1 file changed, 75 insertions(+), 75 deletions(-) diff --git a/the-cup.ino b/the-cup.ino index d1f7782..b2c8324 100644 --- a/the-cup.ino +++ b/the-cup.ino @@ -1,4 +1,4 @@ - /* Pin layout used: +/* Pin layout used: * ----------------------------------------------------------------------------------------- * MFRC522 ESP8266 * Reader/PCD Feather Huzzah @@ -35,97 +35,97 @@ MFRC522DriverSPI driver_1{ss_1_pin}; MFRC522 reader{driver_1}; // Create MFRC522 instance. void setup() { - // WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP - // it is a good practice to make sure your code sets wifi mode how you want it. + // WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP + // it is a good practice to make sure your code sets wifi mode how you want it. - // put your setup code here, to run once: - Serial.begin(115200); + // put your setup code here, to run once: + Serial.begin(115200); - pinMode(LED_PIN, OUTPUT); + pinMode(LED_PIN, OUTPUT); + displaySuccess(); + + //WiFiManager, Local intialization. Once its business is done, there is no need to keep it around + WiFiManager wm; + + // reset settings - wipe stored credentials for testing + // these are stored by the esp library + // wm.resetSettings(); + + // Automatically connect using saved credentials, + // if connection fails, it starts an access point with the specified name ( "AutoConnectAP"), + // if empty will auto generate SSID, if password is blank it will be anonymous AP (wm.autoConnect()) + // then goes into a blocking loop awaiting configuration and will return success result + + bool res; + // res = wm.autoConnect(); // auto generated AP name from chipid + // res = wm.autoConnect("AutoConnectAP"); // anonymous ap + res = wm.autoConnect("KLUK"); // password protected ap + + if(!res) { + Serial.println("Failed to connect"); + displayError(); + // ESP.restart(); + } + else { + //if you get here you have connected to the WiFi + Serial.println("connected...yeey :)"); displaySuccess(); + } - //WiFiManager, Local intialization. Once its business is done, there is no need to keep it around - WiFiManager wm; - - // reset settings - wipe stored credentials for testing - // these are stored by the esp library - // wm.resetSettings(); - - // Automatically connect using saved credentials, - // if connection fails, it starts an access point with the specified name ( "AutoConnectAP"), - // if empty will auto generate SSID, if password is blank it will be anonymous AP (wm.autoConnect()) - // then goes into a blocking loop awaiting configuration and will return success result - - bool res; - // res = wm.autoConnect(); // auto generated AP name from chipid - // res = wm.autoConnect("AutoConnectAP"); // anonymous ap - res = wm.autoConnect("KLUK"); // password protected ap - - if(!res) { - Serial.println("Failed to connect"); - displayError(); - // ESP.restart(); - } - else { - //if you get here you have connected to the WiFi - Serial.println("connected...yeey :)"); - displaySuccess(); - } - - reader.PCD_Init(); // Init each MFRC522 card. + reader.PCD_Init(); // Init each MFRC522 card. } void loop() { - auto client = std::make_unique(); + auto client = std::make_unique(); - if (reader.PICC_IsNewCardPresent() && reader.PICC_ReadCardSerial()) { - // Halt PICC. - reader.PICC_HaltA(); - // Stop encryption on PCD. - reader.PCD_StopCrypto1(); + if (reader.PICC_IsNewCardPresent() && reader.PICC_ReadCardSerial()) { + // Halt PICC. + reader.PICC_HaltA(); + // Stop encryption on PCD. + reader.PCD_StopCrypto1(); - 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"); + 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"); - 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) + "\"}"); - Serial.print("httpCode: "); - Serial.print(httpCode); - // httpCode will be negative on error - 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 { - displayError(); - } + 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) + "\"}"); + Serial.print("httpCode: "); + Serial.print(httpCode); + // httpCode will be negative on error + 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 { displayError(); } - - https.end(); - Serial.print("[HTTPS] ended...\n"); + } else { + displayError(); } + + https.end(); + Serial.print("[HTTPS] ended...\n"); + } } void array_to_string(byte array[], unsigned int len, char buffer[]) { - for (unsigned int i = 0; i < len; i++) - { - byte nib1 = (array[i] >> 4) & 0x0F; - byte nib2 = (array[i] >> 0) & 0x0F; - buffer[i*2+0] = nib1 < 0xA ? '0' + nib1 : 'A' + nib1 - 0xA; - buffer[i*2+1] = nib2 < 0xA ? '0' + nib2 : 'A' + nib2 - 0xA; - } - buffer[len*2] = '\0'; + for (unsigned int i = 0; i < len; i++) + { + byte nib1 = (array[i] >> 4) & 0x0F; + byte nib2 = (array[i] >> 0) & 0x0F; + buffer[i*2+0] = nib1 < 0xA ? '0' + nib1 : 'A' + nib1 - 0xA; + buffer[i*2+1] = nib2 < 0xA ? '0' + nib2 : 'A' + nib2 - 0xA; + } + buffer[len*2] = '\0'; } void displayError() {