137 lines
3.3 KiB
Arduino
137 lines
3.3 KiB
Arduino
|
|
#include "Wire.h"
|
||
|
|
#include "XL9535_driver.h"
|
||
|
|
#include "esp_lcd_panel_io.h"
|
||
|
|
#include "esp_lcd_panel_ops.h"
|
||
|
|
#include "esp_lcd_panel_rgb.h"
|
||
|
|
#include "esp_lcd_panel_vendor.h"
|
||
|
|
#include "current_img.h"
|
||
|
|
#include "pin_config.h"
|
||
|
|
#include <Arduino.h>
|
||
|
|
#include <SPIFFS.h>
|
||
|
|
#include <WiFi.h>
|
||
|
|
#include <AsyncTCP.h>
|
||
|
|
#include <ESPAsyncWebSrv.h>
|
||
|
|
|
||
|
|
const char* ssid = "Box-gut-2.4G";
|
||
|
|
const char* password = "Rut@b@g@93";
|
||
|
|
AsyncWebServer server(80);
|
||
|
|
|
||
|
|
void connectToWiFi() {
|
||
|
|
WiFi.begin(ssid, password);
|
||
|
|
|
||
|
|
Serial.print("Connexion en cours au réseau Wi-Fi...");
|
||
|
|
while (WiFi.status() != WL_CONNECTED) {
|
||
|
|
delay(1000);
|
||
|
|
Serial.print(".");
|
||
|
|
}
|
||
|
|
Serial.println("\nConnecté au réseau Wi-Fi");
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
void traiterEntreeJson(char* entreeJson) {
|
||
|
|
char *token = strtok(const_cast<char*>(entreeJson), ",");
|
||
|
|
|
||
|
|
File fichier = SPIFFS.open("/new_img.h", "a"); // Ouvre le fichier en mode ajout
|
||
|
|
fichier.print("const uint16_t image_data[] = {");
|
||
|
|
while (token != NULL) {
|
||
|
|
String objet = String(token);
|
||
|
|
|
||
|
|
objet.replace("[", "");
|
||
|
|
objet.replace("]", "");
|
||
|
|
objet.replace("{", "");
|
||
|
|
objet.replace("}", "");
|
||
|
|
objet.replace("\"", "");
|
||
|
|
int index = objet.indexOf(':');
|
||
|
|
String cle = objet.substring(0, index);
|
||
|
|
int valeur = objet.substring(index + 1).toInt();
|
||
|
|
|
||
|
|
for (int i = 0; i < valeur; i++) {
|
||
|
|
fichier.print(cle);
|
||
|
|
fichier.print(',');
|
||
|
|
}
|
||
|
|
|
||
|
|
token = strtok(NULL, ",");
|
||
|
|
}
|
||
|
|
fichier.print("};");
|
||
|
|
fichier.close(); // Ferme le fichier
|
||
|
|
|
||
|
|
File f = SPIFFS.open("/new_img.h", "r");
|
||
|
|
if (!f) {
|
||
|
|
Serial.println("Erreur lors de l'ouverture du fichier en lecture.");
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
// Lire le contenu du fichier
|
||
|
|
while (f.available()) {
|
||
|
|
char c = f.read();
|
||
|
|
Serial.print(c);
|
||
|
|
}
|
||
|
|
f.close(); // Ferme le fichier
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
void setupSPIFFS() {
|
||
|
|
if (SPIFFS.begin()) {
|
||
|
|
Serial.println("Système de fichiers SPIFFS monté avec succès");
|
||
|
|
} else {
|
||
|
|
Serial.println("Erreur lors du montage du système de fichiers SPIFFS");
|
||
|
|
}
|
||
|
|
if (SPIFFS.exists("/new_img.h")) {
|
||
|
|
|
||
|
|
|
||
|
|
if (SPIFFS.remove("/current_img.h")) {
|
||
|
|
Serial.println("Le fichier a été supprimé avec succès.");
|
||
|
|
} else {
|
||
|
|
Serial.println("Erreur lors de la suppression du fichier.");
|
||
|
|
}
|
||
|
|
|
||
|
|
if (SPIFFS.rename("/new_img.h", "/current_img.h")) {
|
||
|
|
Serial.println("Le fichier a été renommé avec succès.");
|
||
|
|
esp_restart();
|
||
|
|
} else {
|
||
|
|
Serial.println("Erreur lors du renommage du fichier.");
|
||
|
|
}
|
||
|
|
|
||
|
|
} else {
|
||
|
|
Serial.println("Le fichier spécifique n'existe pas.");
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
void setup()
|
||
|
|
{
|
||
|
|
|
||
|
|
// put your setup code here, to run once:
|
||
|
|
Serial.begin(115200);
|
||
|
|
setupSPIFFS();
|
||
|
|
connectToWiFi();
|
||
|
|
|
||
|
|
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
|
||
|
|
request->send(SPIFFS, "/index.html");
|
||
|
|
});
|
||
|
|
|
||
|
|
server.on("/imageData", HTTP_POST, [](AsyncWebServerRequest *request){
|
||
|
|
// Obtenir le corps de la requête JSON
|
||
|
|
|
||
|
|
String jsonData = request->arg("divText");
|
||
|
|
const char* jsonDataChar = jsonData.c_str();
|
||
|
|
Serial.println(jsonDataChar);
|
||
|
|
|
||
|
|
// Envoyez une réponse au client
|
||
|
|
request->send(200, "text/plain", "Données JSON reçues avec succès !");
|
||
|
|
});
|
||
|
|
|
||
|
|
|
||
|
|
server.begin();
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
void loop()
|
||
|
|
{
|
||
|
|
}
|