show debug only if flag
This commit is contained in:
parent
b8ca5971c4
commit
eaeb9dcfe9
1 changed files with 31 additions and 13 deletions
18
the-cup.ino
18
the-cup.ino
|
|
@ -69,10 +69,12 @@ void read_card(char reader_uid[]);
|
|||
void send_uid(char reader_uid[]);
|
||||
|
||||
void setup() {
|
||||
#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);
|
||||
#ifdef DEBUG
|
||||
Serial.println(reader_uid);
|
||||
#endif
|
||||
displaySuccess();
|
||||
}
|
||||
|
||||
|
|
@ -111,42 +115,56 @@ void connectToWifi() {
|
|||
res = wm.autoConnect("KLUK"); // password protected ap
|
||||
|
||||
if(!res) {
|
||||
#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;
|
||||
#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) + "\"}");
|
||||
#ifdef DEBUG
|
||||
Serial.print("httpCode: ");
|
||||
Serial.println(httpCode);
|
||||
#endif
|
||||
|
||||
if (httpCode > 0) {
|
||||
if (httpCode == HTTP_CODE_CREATED) {
|
||||
} else {
|
||||
#ifdef DEBUG
|
||||
Serial.println("Remote error while sending uid");
|
||||
#endif
|
||||
displayError();
|
||||
}
|
||||
} else {
|
||||
#ifdef DEBUG
|
||||
Serial.print("Remote error while sending uid");
|
||||
#endif
|
||||
displayError();
|
||||
}
|
||||
|
||||
https.end();
|
||||
#ifdef DEBUG
|
||||
Serial.print("[HTTPS] ended...\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
void byte_to_string(byte array[], unsigned int len, char buffer[]) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue