Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c3aa7d9dfd |
No files matched your search
@@ -0,0 +1,9 @@
|
|||||||
|
struct WifiConfig {
|
||||||
|
long magic;
|
||||||
|
char mqtt_server[40];
|
||||||
|
char mqtt_user[32];
|
||||||
|
char mqtt_passw[32];
|
||||||
|
char api_token[32];
|
||||||
|
char ssid[32];
|
||||||
|
char password[32];
|
||||||
|
};
|
||||||
@@ -1 +1,2 @@
|
|||||||
void setupMQTT(void);
|
void setupMQTT(void);
|
||||||
|
void loopMQTT(void);
|
||||||
+4
-10
@@ -1,12 +1,6 @@
|
|||||||
|
#include "main.h"
|
||||||
|
|
||||||
|
|
||||||
|
extern WifiConfig wifiConfig;
|
||||||
|
|
||||||
void WifiSetup(void);
|
void WifiSetup(void);
|
||||||
|
|
||||||
struct WifiConfig {
|
|
||||||
long magic;
|
|
||||||
char mqtt_server[40];
|
|
||||||
char mqtt_user[32];
|
|
||||||
char mqtt_passw[32];
|
|
||||||
char api_token[32];
|
|
||||||
char ssid[32];
|
|
||||||
char password[32];
|
|
||||||
};
|
|
||||||
+29
-17
@@ -1,6 +1,7 @@
|
|||||||
#include <arduino.h>
|
#include <arduino.h>
|
||||||
#include <EEPROM.h>
|
#include <EEPROM.h>
|
||||||
|
|
||||||
|
#include "main.h"
|
||||||
#include "eeprom.h"
|
#include "eeprom.h"
|
||||||
#include "wifi.h"
|
#include "wifi.h"
|
||||||
|
|
||||||
@@ -17,33 +18,44 @@
|
|||||||
void ReadConfig() {
|
void ReadConfig() {
|
||||||
// Read configuration from EEPROM
|
// Read configuration from EEPROM
|
||||||
EEPROM.begin(sizeof(WifiConfig));
|
EEPROM.begin(sizeof(WifiConfig));
|
||||||
WifiConfig config;
|
// WifiConfig config;
|
||||||
EEPROM.get(0, config);
|
EEPROM.get(0, wifiConfig);
|
||||||
|
|
||||||
// Check magic number
|
// Check magic number
|
||||||
if (config.magic != 0xDEADBEEF) {
|
if (wifiConfig.magic != 0xDEADBEEF) {
|
||||||
Serial.println("EEPROM not initialized, initializing with default values...");
|
Serial.println("EEPROM not initialized, initializing with default values...");
|
||||||
// Initialize with default values
|
// Initialize with default values
|
||||||
config.magic = 0xDEADBEEF;
|
wifiConfig.magic = 0xDEADBEEF;
|
||||||
strcpy(config.mqtt_server, "undefined");
|
strcpy(wifiConfig.mqtt_server, "undefined");
|
||||||
strcpy(config.mqtt_user, "undefined");
|
strcpy(wifiConfig.mqtt_user, "undefined");
|
||||||
strcpy(config.mqtt_passw, "undefined");
|
strcpy(wifiConfig.mqtt_passw, "undefined");
|
||||||
strcpy(config.api_token, "undefined");
|
strcpy(wifiConfig.api_token, "undefined");
|
||||||
strcpy(config.ssid, "undefined");
|
strcpy(wifiConfig.ssid, "undefined");
|
||||||
strcpy(config.password, "undefined");
|
strcpy(wifiConfig.password, "undefined");
|
||||||
EEPROM.put(0, config);
|
EEPROM.put(0, wifiConfig);
|
||||||
EEPROM.commit();
|
EEPROM.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Populate global configuration variables
|
// Populate global configuration variables
|
||||||
// Assuming you have global variables for these configurations
|
// Assuming you have global variables for these configurations
|
||||||
// e.g., globalMqttServer, globalMqttUser, etc.
|
// e.g., globalMqttServer, globalMqttUser, etc.
|
||||||
// globalMqttServer = String(config.mqtt_server);
|
// globalMqttServer = String(wifiConfig.mqtt_server);
|
||||||
// globalMqttUser = String(config.mqtt_user);
|
// globalMqttUser = String(wifiConfig.mqtt_user);
|
||||||
// globalMqttPassw = String(config.mqtt_passw);
|
// globalMqttPassw = String(wifiConfig.mqtt_passw);
|
||||||
// globalApiToken = String(config.api_token);
|
// globalApiToken = String(wifiConfig.api_token);
|
||||||
// globalSsid = String(config.ssid);
|
// globalSsid = String(wifiConfig.ssid);
|
||||||
// globalPassword = String(config.password);
|
// globalPassword = String(wifiConfig.password);
|
||||||
|
|
||||||
Serial.println("Configuration loaded from EEPROM.");
|
Serial.println("Configuration loaded from EEPROM.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* saveConfig() - Save configuration to EEPROM
|
||||||
|
*
|
||||||
|
* save the current configuration structure to EEPROM.
|
||||||
|
*/
|
||||||
|
void SaveConfig() {
|
||||||
|
EEPROM.put(0, wifiConfig);
|
||||||
|
EEPROM.commit();
|
||||||
|
Serial.println("Configuration saved to EEPROM.");
|
||||||
|
}
|
||||||
+12
-7
@@ -4,6 +4,7 @@
|
|||||||
#include <WiFiUdp.h>
|
#include <WiFiUdp.h>
|
||||||
#include <ArduinoOTA.h>
|
#include <ArduinoOTA.h>
|
||||||
|
|
||||||
|
#include "main.h"
|
||||||
#include "pins.h"
|
#include "pins.h"
|
||||||
#include "wifi.h"
|
#include "wifi.h"
|
||||||
#include "mqtt.h"
|
#include "mqtt.h"
|
||||||
@@ -31,12 +32,7 @@ void setup() {
|
|||||||
Serial.println("Démarrage...");
|
Serial.println("Démarrage...");
|
||||||
delay(100);
|
delay(100);
|
||||||
|
|
||||||
// TODO: implement
|
// Configure hardware pins
|
||||||
// Read config from EEPROM
|
|
||||||
ReadConfig();
|
|
||||||
//
|
|
||||||
OtaSetup();
|
|
||||||
|
|
||||||
pinMode(Pins::batteryVoltage, INPUT);
|
pinMode(Pins::batteryVoltage, INPUT);
|
||||||
|
|
||||||
#if defined(DEVICE_ROLE_BOAT)
|
#if defined(DEVICE_ROLE_BOAT)
|
||||||
@@ -49,8 +45,15 @@ void setup() {
|
|||||||
pinMode(Pins::hallRudderSignal, INPUT);
|
pinMode(Pins::hallRudderSignal, INPUT);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Read config from EEPROM
|
||||||
|
ReadConfig();
|
||||||
|
// Connect to Wi-Fi and setup MQTT
|
||||||
WifiSetup();
|
WifiSetup();
|
||||||
setupMQTT();
|
setupMQTT();
|
||||||
|
// Setup OTA
|
||||||
|
OtaSetup();
|
||||||
|
|
||||||
|
|
||||||
Serial.printf("Stid maritime: role=%s, mode=%s, chip=%06X\n",
|
Serial.printf("Stid maritime: role=%s, mode=%s, chip=%06X\n",
|
||||||
deviceRole, networkMode, ESP.getChipId());
|
deviceRole, networkMode, ESP.getChipId());
|
||||||
Serial.println("Firmware skeleton ready; motors remain stopped.");
|
Serial.println("Firmware skeleton ready; motors remain stopped.");
|
||||||
@@ -61,6 +64,8 @@ void setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
OtaLoop();
|
||||||
|
loopMQTT();
|
||||||
// Keep the initial firmware passive until the command and failsafe layers exist.
|
// Keep the initial firmware passive until the command and failsafe layers exist.
|
||||||
delay(1000);
|
delay(100);
|
||||||
}
|
}
|
||||||
@@ -8,3 +8,11 @@ void setupMQTT(void) {
|
|||||||
mqttClient.setServer(mqtt_server, 1883);
|
mqttClient.setServer(mqtt_server, 1883);
|
||||||
mqttClient.setCallback(mqttCallback);
|
mqttClient.setCallback(mqttCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void loopMQTT(void) {
|
||||||
|
// Vérifier la connexion MQTT
|
||||||
|
if (!mqttClient.connected()) {
|
||||||
|
reconnectMQTT();
|
||||||
|
}
|
||||||
|
mqttClient.loop();
|
||||||
|
}
|
||||||
+20
-4
@@ -10,10 +10,27 @@
|
|||||||
* @date 2024-06-15
|
* @date 2024-06-15
|
||||||
* @version 1.0
|
* @version 1.0
|
||||||
*/
|
*/
|
||||||
|
#include <arduino.h>
|
||||||
|
#include <ESP8266WiFi.h>
|
||||||
|
#include <WiFiManager.h>
|
||||||
|
|
||||||
|
#include "main.h"
|
||||||
|
|
||||||
|
WifiConfig wifiConfig;
|
||||||
|
|
||||||
void WifiSetup()
|
void WifiSetup()
|
||||||
{
|
{
|
||||||
static WifiConfig wifiConfig;
|
WiFiManager wifiManager;
|
||||||
|
// Lire 2 derniers digits de la MAC pour créer un nom unique
|
||||||
|
uint8_t mac[6];
|
||||||
|
char ssid[32];
|
||||||
|
|
||||||
|
WiFi.macAddress(mac);
|
||||||
|
|
||||||
|
// Nom du module sur le réseau (Optionnel)
|
||||||
|
strcpy(ssid, "Finist-RC-");
|
||||||
|
sprintf(ssid + strlen(ssid), "%02X%02X", mac[4], mac[5]);
|
||||||
|
|
||||||
|
|
||||||
// Définition du code HTML personnalisé pour la liste déroulante (<select>)
|
// Définition du code HTML personnalisé pour la liste déroulante (<select>)
|
||||||
const char* custom_dropdown_html =
|
const char* custom_dropdown_html =
|
||||||
@@ -25,6 +42,7 @@ void WifiSetup()
|
|||||||
"<option value='tmqtt'>Télécommande MQTT</option>"
|
"<option value='tmqtt'>Télécommande MQTT</option>"
|
||||||
"</select>";
|
"</select>";
|
||||||
|
|
||||||
|
wifiManager.setPageTitle("Bateau FinistRC - Configuration Wi-Fi et MQTT");
|
||||||
// Création du paramètre personnalisé
|
// Création du paramètre personnalisé
|
||||||
// Syntaxe : WiFiManagerParameter(id, placeholder/label, default_value, length, custom_html)
|
// Syntaxe : WiFiManagerParameter(id, placeholder/label, default_value, length, custom_html)
|
||||||
WiFiManagerParameter custom_device_mode("device_mode", "Mode", "bauto", 40, custom_dropdown_html);
|
WiFiManagerParameter custom_device_mode("device_mode", "Mode", "bauto", 40, custom_dropdown_html);
|
||||||
@@ -35,8 +53,6 @@ void WifiSetup()
|
|||||||
WiFiManagerParameter custom_mqtt_passw("mqtt", "Mot de passe MQTT", wifiConfig.mqtt_passw, 32);
|
WiFiManagerParameter custom_mqtt_passw("mqtt", "Mot de passe MQTT", wifiConfig.mqtt_passw, 32);
|
||||||
WiFiManagerParameter custom_api_token("api", "Clé API", wifiConfig.api_token, 32);
|
WiFiManagerParameter custom_api_token("api", "Clé API", wifiConfig.api_token, 32);
|
||||||
|
|
||||||
WiFiManager wifiManager;
|
|
||||||
|
|
||||||
// Associer la fonction de rappel
|
// Associer la fonction de rappel
|
||||||
wifiManager.setSaveConfigCallback(saveConfigCallback);
|
wifiManager.setSaveConfigCallback(saveConfigCallback);
|
||||||
|
|
||||||
@@ -48,7 +64,7 @@ void WifiSetup()
|
|||||||
wifiManager.addParameter(&custom_api_token);
|
wifiManager.addParameter(&custom_api_token);
|
||||||
|
|
||||||
// Lance le portail
|
// Lance le portail
|
||||||
if (!wifiManager.autoConnect("FinistRC_Config","Finist29PWD")) {
|
if (!wifiManager.autoConnect(ssid,"FinistRC_2026")) {
|
||||||
Serial.println("Échec de connexion ou timeout...");
|
Serial.println("Échec de connexion ou timeout...");
|
||||||
delay(3000);
|
delay(3000);
|
||||||
ESP.restart();
|
ESP.restart();
|
||||||
|
|||||||
Reference in new issue
Block a user