Initial commit
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
#include <Arduino.h>
|
||||
#include <WiFi.h>
|
||||
#include <ESPAsyncWebSrv.h>
|
||||
#include <SPIFFS.h>
|
||||
#include <esp_system.h>
|
||||
|
||||
const char* ssid = "Box-gut-2.4G";
|
||||
const char* password = "Rut@b@g@93";
|
||||
AsyncWebServer server(80);
|
||||
File imageFile;
|
||||
|
||||
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");
|
||||
Serial.print("Adresse IP : ");
|
||||
Serial.println(WiFi.localIP());
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
|
||||
setupSPIFFS();
|
||||
|
||||
connectToWiFi();
|
||||
|
||||
server.on("/", HTTP_GET, [](AsyncWebServerRequest * request) {
|
||||
request->send(SPIFFS, "/index.html");
|
||||
});
|
||||
server.on("/sendImageChunk", HTTP_POST, [](AsyncWebServerRequest * request) {
|
||||
if (!request->hasParam("imageChunk", true)) {
|
||||
request->send(400, "text/plain", "Erreur : aucun paquet reçu.");
|
||||
return;
|
||||
}
|
||||
|
||||
String imageChunk = request->getParam("imageChunk", true)->value();
|
||||
//Serial.println(imageChunk);
|
||||
|
||||
if (imageChunk == "Begin") {
|
||||
imageFile = SPIFFS.open("/current_img.h", "w");
|
||||
imageFile.print("const uint16_t image_data[] = {");
|
||||
Serial.println("debut de l'ecriture du fichier");
|
||||
} else if (imageChunk == "End") {
|
||||
imageFile = SPIFFS.open("/current_img.h", "a");
|
||||
imageFile.print("};");
|
||||
imageFile.close();
|
||||
Serial.println("Fichier current_img.h fermé avec succès.");
|
||||
esp_restart();
|
||||
} else {
|
||||
imageFile = SPIFFS.open("/current_img.h", "a");
|
||||
imageFile.print(imageChunk);
|
||||
}
|
||||
imageFile.close(); // Fermez le fichier ici
|
||||
imageChunk = String();
|
||||
imageFile = File();
|
||||
request->send(200, "text/plain", "Paquet reçu et ajouté !");
|
||||
|
||||
});
|
||||
|
||||
server.begin();
|
||||
}
|
||||
void loop() {
|
||||
// Laissez cette fonction vide, car nous n'avons pas besoin de boucler ici.
|
||||
}
|
||||
Reference in New Issue
Block a user