Initial commit
This commit is contained in:
78
Esp32_Client/Esp32_Client.ino
Normal file
78
Esp32_Client/Esp32_Client.ino
Normal file
@@ -0,0 +1,78 @@
|
||||
#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 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()
|
||||
{
|
||||
|
||||
Serial.begin(115200);
|
||||
setupSPIFFS();
|
||||
connectToWiFi();
|
||||
|
||||
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
|
||||
request->send(SPIFFS, "/index.html");
|
||||
});
|
||||
|
||||
server.on("/onmessage", HTTP_POST, [](AsyncWebServerRequest *request){
|
||||
// Obtenir le corps de la requête JSON
|
||||
|
||||
String message = request->getParam("message", true)->value();;
|
||||
Serial.println(message);
|
||||
|
||||
request->send(200, "text/plain", "Données JSON reçues avec succès !");
|
||||
});
|
||||
|
||||
|
||||
server.begin();
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
}
|
||||
Reference in New Issue
Block a user