Initialisation depot
This commit is contained in:
23
README.md
Normal file
23
README.md
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
# ESP32 Thermostat Configuration System
|
||||||
|
|
||||||
|
Ce projet PlatformIO pour ESP32-WRoom propose :
|
||||||
|
- Un serveur Web pour configurer un thermostat interne
|
||||||
|
- Stockage des paramètres (WiFi, MQTT, consignes) en EEPROM
|
||||||
|
- Portail captif pour configuration initiale ou en cas de perte WiFi
|
||||||
|
- Code organisé en plusieurs fichiers .cpp/.h pour la maintenabilité
|
||||||
|
|
||||||
|
## Structure suggérée
|
||||||
|
- src/main.cpp
|
||||||
|
- src/eeprom_manager.cpp/h
|
||||||
|
- src/wifi_manager.cpp/h
|
||||||
|
- src/web_server.cpp/h
|
||||||
|
- src/mqtt_manager.cpp/h
|
||||||
|
- src/thermostat.cpp/h
|
||||||
|
|
||||||
|
## Instructions
|
||||||
|
1. Flasher sur ESP32-WRoom
|
||||||
|
2. Accéder au portail captif pour configurer le WiFi/MQTT si nécessaire
|
||||||
|
3. Accéder au serveur Web pour configurer le thermostat
|
||||||
|
|
||||||
|
---
|
||||||
|
Remplacez les placeholders par vos paramètres réels.
|
||||||
5
platformio.ini
Normal file
5
platformio.ini
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
[env:esp32dev]
|
||||||
|
platform = espressif32
|
||||||
|
board = esp32dev
|
||||||
|
framework = arduino
|
||||||
|
monitor_speed = 115200
|
||||||
14
src/eeprom_manager.cpp
Normal file
14
src/eeprom_manager.cpp
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
#include "eeprom_manager.h"
|
||||||
|
|
||||||
|
void EEPROMManager::begin() {
|
||||||
|
EEPROM.begin(512);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EEPROMManager::saveConfig() {
|
||||||
|
// TODO: Sauvegarder la configuration
|
||||||
|
}
|
||||||
|
|
||||||
|
void EEPROMManager::loadConfig() {
|
||||||
|
//
|
||||||
|
|
||||||
|
}
|
||||||
9
src/eeprom_manager.h
Normal file
9
src/eeprom_manager.h
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <EEPROM.h>
|
||||||
|
|
||||||
|
class EEPROMManager {
|
||||||
|
public:
|
||||||
|
static void begin();
|
||||||
|
static void saveConfig();
|
||||||
|
static void loadConfig();
|
||||||
|
};
|
||||||
67
src/main.cpp
Normal file
67
src/main.cpp
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
#include "eeprom_manager.h"
|
||||||
|
#include "wifi_manager.h"
|
||||||
|
#include "web_server.h"
|
||||||
|
#include "mqtt_manager.h"
|
||||||
|
#include "thermostat.h"
|
||||||
|
|
||||||
|
// Modes allowed by thermostat
|
||||||
|
enum Mode {
|
||||||
|
MODE_OFF, MODE_ECO, MODE_COMFORT, MODE_HORSGEL, MODE_MANUAL
|
||||||
|
};
|
||||||
|
|
||||||
|
// Configuration structure, stored in EEPROM
|
||||||
|
struct Config {
|
||||||
|
int Initialized; // Flag to check if config is initialized 0=>not initialized, 1=initialized
|
||||||
|
char ssid[32];
|
||||||
|
char password[32];
|
||||||
|
char mqttServer[64];
|
||||||
|
char mqttUser[32];
|
||||||
|
char mqttPassword[32];
|
||||||
|
int mqttPort;
|
||||||
|
Mode mode;
|
||||||
|
} config;
|
||||||
|
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
// wait for monitor to open (time to manually open the serial monitor after reset )
|
||||||
|
delay(5000);
|
||||||
|
Serial.begin(115200);
|
||||||
|
Serial.println("Starting ESP Thermostat...");
|
||||||
|
// Read configuration from EEPROM
|
||||||
|
EEPROMManager::loadConfig(config);
|
||||||
|
if (config.Initialized == 0) {
|
||||||
|
Serial.println("No configuration found, initializing with default values...");
|
||||||
|
// Set default configuration
|
||||||
|
config.Initialized = 1; // Mark as initialized
|
||||||
|
strcpy(config.ssid, "ThermostatWiFi");
|
||||||
|
strcpy(config.password, "");
|
||||||
|
strcpy(config.mqttServer, "mqtt.example.com");
|
||||||
|
strcpy(config.mqttUser, "mqtt_user");
|
||||||
|
strcpy(config.mqttPassword, "mqtt_password");
|
||||||
|
config.mqttPort = 1883;
|
||||||
|
config.mode = MODE_ECO; // Default mode
|
||||||
|
// Save default configuration to EEPROM
|
||||||
|
EEPROMManager::saveConfig(config);
|
||||||
|
} else {
|
||||||
|
Serial.println("Configuration loaded from EEPROM:");
|
||||||
|
Serial.print("SSID: ");
|
||||||
|
Serial.println(config.ssid);
|
||||||
|
Serial.print("MQTT Server: ");
|
||||||
|
Serial.println(config.mqttServer);
|
||||||
|
}
|
||||||
|
// Initialisation des modules
|
||||||
|
EEPROMManager::begin();
|
||||||
|
WiFiManager::begin();
|
||||||
|
WebServerManager::begin();
|
||||||
|
MQTTManager::begin();
|
||||||
|
Thermostat::begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
// Boucle principale
|
||||||
|
WiFiManager::handle();
|
||||||
|
WebServerManager::handle();
|
||||||
|
MQTTManager::handle();
|
||||||
|
Thermostat::handle();
|
||||||
|
}
|
||||||
9
src/mqtt_manager.cpp
Normal file
9
src/mqtt_manager.cpp
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#include "mqtt_manager.h"
|
||||||
|
|
||||||
|
void MQTTManager::begin() {
|
||||||
|
// TODO: Initialiser MQTT
|
||||||
|
}
|
||||||
|
|
||||||
|
void MQTTManager::handle() {
|
||||||
|
// TODO: Gérer la communication MQTT
|
||||||
|
}
|
||||||
8
src/mqtt_manager.h
Normal file
8
src/mqtt_manager.h
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <PubSubClient.h>
|
||||||
|
|
||||||
|
class MQTTManager {
|
||||||
|
public:
|
||||||
|
static void begin();
|
||||||
|
static void handle();
|
||||||
|
};
|
||||||
9
src/thermostat.cpp
Normal file
9
src/thermostat.cpp
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#include "thermostat.h"
|
||||||
|
|
||||||
|
void Thermostat::begin() {
|
||||||
|
// TODO: Initialiser le thermostat
|
||||||
|
}
|
||||||
|
|
||||||
|
void Thermostat::handle() {
|
||||||
|
// TODO: Gérer la logique du thermostat
|
||||||
|
}
|
||||||
7
src/thermostat.h
Normal file
7
src/thermostat.h
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
class Thermostat {
|
||||||
|
public:
|
||||||
|
static void begin();
|
||||||
|
static void handle();
|
||||||
|
};
|
||||||
9
src/web_server.cpp
Normal file
9
src/web_server.cpp
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#include "web_server.h"
|
||||||
|
|
||||||
|
void WebServerManager::begin() {
|
||||||
|
// TODO: Initialiser le serveur Web
|
||||||
|
}
|
||||||
|
|
||||||
|
void WebServerManager::handle() {
|
||||||
|
// TODO: Gérer les requêtes Web
|
||||||
|
}
|
||||||
8
src/web_server.h
Normal file
8
src/web_server.h
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <WebServer.h>
|
||||||
|
|
||||||
|
class WebServerManager {
|
||||||
|
public:
|
||||||
|
static void begin();
|
||||||
|
static void handle();
|
||||||
|
};
|
||||||
13
src/wifi_manager.cpp
Normal file
13
src/wifi_manager.cpp
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#include "wifi_manager.h"
|
||||||
|
|
||||||
|
void WiFiManager::begin() {
|
||||||
|
// TODO: Initialiser le WiFi
|
||||||
|
}
|
||||||
|
|
||||||
|
void WiFiManager::handle() {
|
||||||
|
// TODO: Gérer la connexion WiFi
|
||||||
|
}
|
||||||
|
|
||||||
|
void WiFiManager::startCaptivePortal() {
|
||||||
|
// TODO: Démarrer le portail captif
|
||||||
|
}
|
||||||
9
src/wifi_manager.h
Normal file
9
src/wifi_manager.h
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <WiFi.h>
|
||||||
|
|
||||||
|
class WiFiManager {
|
||||||
|
public:
|
||||||
|
static void begin();
|
||||||
|
static void handle();
|
||||||
|
static void startCaptivePortal();
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user