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 send_uid(char reader_uid[]);
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
#ifdef DEBUG
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
while (!Serial) delay(10);
|
while (!Serial) delay(10);
|
||||||
Serial.print("Nb cycles: ");
|
Serial.print("Nb cycles: ");
|
||||||
Serial.println(nbCycles++);
|
Serial.println(nbCycles++);
|
||||||
|
#endif
|
||||||
|
|
||||||
pinMode(RC522_POWER_PIN, OUTPUT);
|
pinMode(RC522_POWER_PIN, OUTPUT);
|
||||||
digitalWrite(RC522_POWER_PIN, HIGH);
|
digitalWrite(RC522_POWER_PIN, HIGH);
|
||||||
|
|
@ -96,7 +98,9 @@ void readCard(char reader_uid[]) {
|
||||||
reader.PICC_HaltA();
|
reader.PICC_HaltA();
|
||||||
reader.PCD_StopCrypto1();
|
reader.PCD_StopCrypto1();
|
||||||
byte_to_string(reader.uid.uidByte, 4, reader_uid);
|
byte_to_string(reader.uid.uidByte, 4, reader_uid);
|
||||||
|
#ifdef DEBUG
|
||||||
Serial.println(reader_uid);
|
Serial.println(reader_uid);
|
||||||
|
#endif
|
||||||
displaySuccess();
|
displaySuccess();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -111,42 +115,56 @@ void connectToWifi() {
|
||||||
res = wm.autoConnect("KLUK"); // password protected ap
|
res = wm.autoConnect("KLUK"); // password protected ap
|
||||||
|
|
||||||
if(!res) {
|
if(!res) {
|
||||||
|
#ifdef DEBUG
|
||||||
Serial.println("Failed to connect");
|
Serial.println("Failed to connect");
|
||||||
|
#endif
|
||||||
displayError();
|
displayError();
|
||||||
// ESP.restart();
|
// ESP.restart();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//if you get here you have connected to the WiFi
|
//if you get here you have connected to the WiFi
|
||||||
|
#ifdef DEBUG
|
||||||
Serial.println("connected...yeey :)");
|
Serial.println("connected...yeey :)");
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void postUid(char reader_uid[]) {
|
void postUid(char reader_uid[]) {
|
||||||
NetworkClientSecure *client = new NetworkClientSecure;
|
NetworkClientSecure *client = new NetworkClientSecure;
|
||||||
client->setCACert(rootCACertificate);
|
client->setCACert(rootCACertificate);
|
||||||
HTTPClient https;
|
HTTPClient https;
|
||||||
|
#ifdef DEBUG
|
||||||
Serial.print("[HTTPS] begin...\n");
|
Serial.print("[HTTPS] begin...\n");
|
||||||
|
#endif
|
||||||
// configure traged server and url
|
// configure traged server and url
|
||||||
https.begin("https://mood.robiweb.net/rfid_tags"); // HTTP
|
https.begin("https://mood.robiweb.net/rfid_tags"); // HTTP
|
||||||
https.addHeader("Content-Type", "application/json");
|
https.addHeader("Content-Type", "application/json");
|
||||||
|
|
||||||
// start connection and send HTTP header and body
|
// start connection and send HTTP header and body
|
||||||
int httpCode = https.POST("{\"identifier\":\"" + String(reader_uid) + "\"}");
|
int httpCode = https.POST("{\"identifier\":\"" + String(reader_uid) + "\"}");
|
||||||
|
#ifdef DEBUG
|
||||||
Serial.print("httpCode: ");
|
Serial.print("httpCode: ");
|
||||||
Serial.println(httpCode);
|
Serial.println(httpCode);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (httpCode > 0) {
|
if (httpCode > 0) {
|
||||||
if (httpCode == HTTP_CODE_CREATED) {
|
if (httpCode == HTTP_CODE_CREATED) {
|
||||||
} else {
|
} else {
|
||||||
|
#ifdef DEBUG
|
||||||
Serial.println("Remote error while sending uid");
|
Serial.println("Remote error while sending uid");
|
||||||
|
#endif
|
||||||
displayError();
|
displayError();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
#ifdef DEBUG
|
||||||
Serial.print("Remote error while sending uid");
|
Serial.print("Remote error while sending uid");
|
||||||
|
#endif
|
||||||
displayError();
|
displayError();
|
||||||
}
|
}
|
||||||
|
|
||||||
https.end();
|
https.end();
|
||||||
|
#ifdef DEBUG
|
||||||
Serial.print("[HTTPS] ended...\n");
|
Serial.print("[HTTPS] ended...\n");
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void byte_to_string(byte array[], unsigned int len, char buffer[]) {
|
void byte_to_string(byte array[], unsigned int len, char buffer[]) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue