Squelette d'application web pour ESP32 avec implémentations de fonctions basiques telles que : -Authentification -Responsive design -Mise à jour OTA -Paramétrage
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

53 lines
1.3 KiB

#include "utils.h"
// Niveau de log par défaut
LogLevel currentLogLevel = LOG_INFO;
String sha256(const String& data) {
byte hash[32];
mbedtls_md_context_t ctx;
mbedtls_md_type_t md_type = MBEDTLS_MD_SHA256;
mbedtls_md_init(&ctx);
mbedtls_md_setup(&ctx, mbedtls_md_info_from_type(md_type), 0);
mbedtls_md_starts(&ctx);
mbedtls_md_update(&ctx, (const unsigned char*)data.c_str(), data.length());
mbedtls_md_finish(&ctx, hash);
mbedtls_md_free(&ctx);
String hashString = "";
for (int i = 0; i < 32; i++) {
char hex[3];
sprintf(hex, "%02x", hash[i]);
hashString += hex;
}
return hashString;
}
String generateSessionId() {
String sessionId = "";
for (int i = 0; i < 32; i++) {
sessionId += String(random(0, 16), HEX);
}
return sessionId;
}
unsigned long getCurrentTime() {
return millis();
}
void logMessage(LogLevel level, const String& message) {
if (level < currentLogLevel) return;
String levelStr;
switch (level) {
case LOG_DEBUG: levelStr = "[DEBUG]"; break;
case LOG_INFO: levelStr = "[INFO]"; break;
case LOG_WARN: levelStr = "[WARN]"; break;
case LOG_ERROR: levelStr = "[ERROR]"; break;
}
Serial.print(levelStr);
Serial.print(" ");
Serial.println(message);
}