Version OK avec Mqtt

This commit is contained in:
2026-03-16 11:20:10 +01:00
commit aa06085f5b
18 changed files with 1395 additions and 0 deletions

7
include/main.h Normal file
View File

@@ -0,0 +1,7 @@
//GPIO12 // Relay
//GPIO13 // LED
#define LED_PIN 13
#define RELAY_PIN 12

12
include/mqtt_handler.h Normal file
View File

@@ -0,0 +1,12 @@
#pragma once
#include <Arduino.h>
#include <PubSubClient.h>
#include "thermostat.h"
extern float currentTemp; // Global temperature variable updated by MQTT callback
bool mqtt_connect(PubSubClient& client);
void mqtt_loop(PubSubClient& client);
void mqtt_publish_state(PubSubClient& client, ThermostatMode mode, float targetTemp, bool heating);
void mqtt_callback(char* topic, byte* payload, unsigned int length);

8
include/preset.h Normal file
View File

@@ -0,0 +1,8 @@
#pragma once
#include <Arduino.h>
#include "thermostat.h"
void load_presets();
void save_presets();
float get_preset_temp(ThermostatMode mode);
void set_preset_temp(ThermostatMode mode, float temp);

21
include/thermostat.h Normal file
View File

@@ -0,0 +1,21 @@
#pragma once
#include <Arduino.h>
enum ThermostatMode { MODE_OFF, MODE_CONFORT, MODE_ECO, MODE_BOOST, MODE_HORS_GEL };
class Thermostat {
public:
Thermostat();
void setMode(ThermostatMode mode);
void setTemperature(float temp);
void setPresetTemp(ThermostatMode mode, float temp);
void update(float currentTemp);
bool isHeating() const;
ThermostatMode getMode() const;
float getTargetTemp() const;
private:
ThermostatMode mode;
float presetTemps[5];
float targetTemp;
bool heating;
};

32
include/web_config.h Normal file
View File

@@ -0,0 +1,32 @@
#pragma once
#include <Arduino.h>
void setup_web_config();
void handle_web_config();
bool should_save_config();
void save_config();
void load_config();
#define CFG_STRLEN 64
/**
* Config struct for EEPROM storage.
*/
struct ConfigData
{
char wifi_ssid[CFG_STRLEN]; // Wifi SSID
char wifi_pass[CFG_STRLEN]; // Wifi Password
char mqtt_server[CFG_STRLEN]; // MQTT Server
char mqtt_user[CFG_STRLEN]; // MQTT User
char mqtt_pass[CFG_STRLEN]; // MQTT Password
char temp_sensor_id[CFG_STRLEN]; // Temperature Sensor ID
char mqtt_device_id[CFG_STRLEN]; // MQTT Device ID
char mqtt_temp_topic[CFG_STRLEN]; // MQTT Temperature Topic
int mqtt_port; // MQTT Port
float preset_confort; // Confort Mode Temperature
float preset_eco; // Eco Mode Temperature
float preset_boost; // Boost Mode Temperature
float preset_hors_gel; // Hors Gel Mode Temperature
};
extern ConfigData config;

2
include/web_routes.h Normal file
View File

@@ -0,0 +1,2 @@
#pragma once
void setup_web_routes();

View File

@@ -0,0 +1,4 @@
#include <ESPAsyncWebServer.h>
// Declare a global server instance on port 80
extern AsyncWebServer server;