use https

This commit is contained in:
Christophe Robillard 2025-09-26 11:31:14 +02:00
parent 03955c4480
commit 5c91330629

View file

@ -13,7 +13,7 @@
#include <WiFiManager.h> // https://github.com/tzapu/WiFiManager
#include <ESP8266HTTPClient.h>
#include <WiFiClientSecureBearSSL.h>
#include <WiFiClient.h>
#include <MFRC522v2.h>
@ -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<BearSSL::WiFiClientSecure>();
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[])