diff --git a/the-cup.ino b/the-cup.ino index a86d51c..4e61b01 100644 --- a/the-cup.ino +++ b/the-cup.ino @@ -13,7 +13,7 @@ #include // https://github.com/tzapu/WiFiManager #include - +#include #include #include @@ -71,29 +71,28 @@ void setup() { } void loop() { - // put your main code here, to run repeatedly: - WiFiClient client; - HTTPClient http; + auto client = std::make_unique(); if (reader.PICC_IsNewCardPresent() && reader.PICC_ReadCardSerial()) { - // Show some details of the PICC (that is: the tag/card). - MFRC522Debug::PrintUID(Serial, reader.uid); // Halt PICC. reader.PICC_HaltA(); // Stop encryption on PCD. reader.PCD_StopCrypto1(); - Serial.print("[HTTP] begin...\n"); + client->setInsecure(); + HTTPClient https; + Serial.print("[HTTPS] begin...\n"); // configure traged server and url - http.begin(client, "http://192.168.1.32:3000/rfid_tags"); // HTTP - http.addHeader("Content-Type", "application/json"); + 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 = http.POST("{\"identifier\":\"" + String(str) + "\"}"); - + 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 @@ -106,7 +105,8 @@ void loop() { displayError(); } - http.end(); + https.end(); + Serial.print("[HTTP] ended...\n"); } } void array_to_string(byte array[], unsigned int len, char buffer[])