use https
This commit is contained in:
parent
03955c4480
commit
5c91330629
1 changed files with 12 additions and 12 deletions
24
the-cup.ino
24
the-cup.ino
|
|
@ -13,7 +13,7 @@
|
||||||
|
|
||||||
#include <WiFiManager.h> // https://github.com/tzapu/WiFiManager
|
#include <WiFiManager.h> // https://github.com/tzapu/WiFiManager
|
||||||
#include <ESP8266HTTPClient.h>
|
#include <ESP8266HTTPClient.h>
|
||||||
|
#include <WiFiClientSecureBearSSL.h>
|
||||||
#include <WiFiClient.h>
|
#include <WiFiClient.h>
|
||||||
|
|
||||||
#include <MFRC522v2.h>
|
#include <MFRC522v2.h>
|
||||||
|
|
@ -71,29 +71,28 @@ void setup() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
// put your main code here, to run repeatedly:
|
auto client = std::make_unique<BearSSL::WiFiClientSecure>();
|
||||||
WiFiClient client;
|
|
||||||
HTTPClient http;
|
|
||||||
|
|
||||||
if (reader.PICC_IsNewCardPresent() && reader.PICC_ReadCardSerial()) {
|
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.
|
// Halt PICC.
|
||||||
reader.PICC_HaltA();
|
reader.PICC_HaltA();
|
||||||
// Stop encryption on PCD.
|
// Stop encryption on PCD.
|
||||||
reader.PCD_StopCrypto1();
|
reader.PCD_StopCrypto1();
|
||||||
|
|
||||||
Serial.print("[HTTP] begin...\n");
|
client->setInsecure();
|
||||||
|
HTTPClient https;
|
||||||
|
Serial.print("[HTTPS] begin...\n");
|
||||||
// configure traged server and url
|
// configure traged server and url
|
||||||
http.begin(client, "http://192.168.1.32:3000/rfid_tags"); // HTTP
|
https.begin(*client, "https://mood.robiweb.net/rfid_tags"); // HTTP
|
||||||
http.addHeader("Content-Type", "application/json");
|
https.addHeader("Content-Type", "application/json");
|
||||||
|
|
||||||
char str[32] = "";
|
char str[32] = "";
|
||||||
array_to_string(reader.uid.uidByte, 4, str); //Insert (byte array, length, char array for output)
|
array_to_string(reader.uid.uidByte, 4, str); //Insert (byte array, length, char array for output)
|
||||||
Serial.println(str); //Print the output uid string
|
Serial.println(str); //Print the output uid string
|
||||||
// start connection and send HTTP header and body
|
// 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
|
// httpCode will be negative on error
|
||||||
if (httpCode > 0) {
|
if (httpCode > 0) {
|
||||||
// HTTP header has been send and Server response header has been handled
|
// HTTP header has been send and Server response header has been handled
|
||||||
|
|
@ -106,7 +105,8 @@ void loop() {
|
||||||
displayError();
|
displayError();
|
||||||
}
|
}
|
||||||
|
|
||||||
http.end();
|
https.end();
|
||||||
|
Serial.print("[HTTP] ended...\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void array_to_string(byte array[], unsigned int len, char buffer[])
|
void array_to_string(byte array[], unsigned int len, char buffer[])
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue