Ajout support OTA - 2
This commit is contained in:
1 parent
845205c60d
commit
c3aa7d9dfd
7 files changed
+84
-39
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];
|
||||
};
|
||||
+2
-1
@@ -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);
|
||||
|
||||
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 <EEPROM.h>
|
||||
|
||||
#include "main.h"
|
||||
#include "eeprom.h"
|
||||
#include "wifi.h"
|
||||
|
||||
@@ -17,33 +18,44 @@
|
||||
void ReadConfig() {
|
||||
// Read configuration from EEPROM
|
||||
EEPROM.begin(sizeof(WifiConfig));
|
||||
WifiConfig config;
|
||||
EEPROM.get(0, config);
|
||||
// WifiConfig config;
|
||||
EEPROM.get(0, wifiConfig);
|
||||
|
||||
// Check magic number
|
||||
if (config.magic != 0xDEADBEEF) {
|
||||
if (wifiConfig.magic != 0xDEADBEEF) {
|
||||
Serial.println("EEPROM not initialized, initializing with default values...");
|
||||
// Initialize with default values
|
||||
config.magic = 0xDEADBEEF;
|
||||
strcpy(config.mqtt_server, "undefined");
|
||||
strcpy(config.mqtt_user, "undefined");
|
||||
strcpy(config.mqtt_passw, "undefined");
|
||||
strcpy(config.api_token, "undefined");
|
||||
strcpy(config.ssid, "undefined");
|
||||
strcpy(config.password, "undefined");
|
||||
EEPROM.put(0, config);
|
||||
wifiConfig.magic = 0xDEADBEEF;
|
||||
strcpy(wifiConfig.mqtt_server, "undefined");
|
||||
strcpy(wifiConfig.mqtt_user, "undefined");
|
||||
strcpy(wifiConfig.mqtt_passw, "undefined");
|
||||
strcpy(wifiConfig.api_token, "undefined");
|
||||
strcpy(wifiConfig.ssid, "undefined");
|
||||
strcpy(wifiConfig.password, "undefined");
|
||||
EEPROM.put(0, wifiConfig);
|
||||
EEPROM.commit();
|
||||
}
|
||||
|
||||
// Populate global configuration variables
|
||||
// Assuming you have global variables for these configurations
|
||||
// e.g., globalMqttServer, globalMqttUser, etc.
|
||||
// globalMqttServer = String(config.mqtt_server);
|
||||
// globalMqttUser = String(config.mqtt_user);
|
||||
// globalMqttPassw = String(config.mqtt_passw);
|
||||
// globalApiToken = String(config.api_token);
|
||||
// globalSsid = String(config.ssid);
|
||||
// globalPassword = String(config.password);
|
||||
// globalMqttServer = String(wifiConfig.mqtt_server);
|
||||
// globalMqttUser = String(wifiConfig.mqtt_user);
|
||||
// globalMqttPassw = String(wifiConfig.mqtt_passw);
|
||||
// globalApiToken = String(wifiConfig.api_token);
|
||||
// globalSsid = String(wifiConfig.ssid);
|
||||
// globalPassword = String(wifiConfig.password);
|
||||
|
||||
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 <ArduinoOTA.h>
|
||||
|
||||
#include "main.h"
|
||||
#include "pins.h"
|
||||
#include "wifi.h"
|
||||
#include "mqtt.h"
|
||||
@@ -31,12 +32,7 @@ void setup() {
|
||||
Serial.println("Démarrage...");
|
||||
delay(100);
|
||||
|
||||
// TODO: implement
|
||||
// Read config from EEPROM
|
||||
ReadConfig();
|
||||
//
|
||||
OtaSetup();
|
||||
|
||||
// Configure hardware pins
|
||||
pinMode(Pins::batteryVoltage, INPUT);
|
||||
|
||||
#if defined(DEVICE_ROLE_BOAT)
|
||||
@@ -49,8 +45,15 @@ void setup() {
|
||||
pinMode(Pins::hallRudderSignal, INPUT);
|
||||
#endif
|
||||
|
||||
// Read config from EEPROM
|
||||
ReadConfig();
|
||||
// Connect to Wi-Fi and setup MQTT
|
||||
WifiSetup();
|
||||
setupMQTT();
|
||||
// Setup OTA
|
||||
OtaSetup();
|
||||
|
||||
|
||||
Serial.printf("Stid maritime: role=%s, mode=%s, chip=%06X\n",
|
||||
deviceRole, networkMode, ESP.getChipId());
|
||||
Serial.println("Firmware skeleton ready; motors remain stopped.");
|
||||
@@ -61,6 +64,8 @@ void setup() {
|
||||
}
|
||||
|
||||
void loop() {
|
||||
OtaLoop();
|
||||
loopMQTT();
|
||||
// Keep the initial firmware passive until the command and failsafe layers exist.
|
||||
delay(1000);
|
||||
delay(100);
|
||||
}
|
||||
@@ -7,4 +7,12 @@ void setupMQTT(void) {
|
||||
// Initialisation du client MQTT
|
||||
mqttClient.setServer(mqtt_server, 1883);
|
||||
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
|
||||
* @version 1.0
|
||||
*/
|
||||
#include <arduino.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <WiFiManager.h>
|
||||
|
||||
#include "main.h"
|
||||
|
||||
WifiConfig wifiConfig;
|
||||
|
||||
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>)
|
||||
const char* custom_dropdown_html =
|
||||
@@ -25,6 +42,7 @@ void WifiSetup()
|
||||
"<option value='tmqtt'>Télécommande MQTT</option>"
|
||||
"</select>";
|
||||
|
||||
wifiManager.setPageTitle("Bateau FinistRC - Configuration Wi-Fi et MQTT");
|
||||
// Création du paramètre personnalisé
|
||||
// Syntaxe : WiFiManagerParameter(id, placeholder/label, default_value, length, custom_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_api_token("api", "Clé API", wifiConfig.api_token, 32);
|
||||
|
||||
WiFiManager wifiManager;
|
||||
|
||||
// Associer la fonction de rappel
|
||||
wifiManager.setSaveConfigCallback(saveConfigCallback);
|
||||
|
||||
@@ -48,7 +64,7 @@ void WifiSetup()
|
||||
wifiManager.addParameter(&custom_api_token);
|
||||
|
||||
// Lance le portail
|
||||
if (!wifiManager.autoConnect("FinistRC_Config","Finist29PWD")) {
|
||||
if (!wifiManager.autoConnect(ssid,"FinistRC_2026")) {
|
||||
Serial.println("Échec de connexion ou timeout...");
|
||||
delay(3000);
|
||||
ESP.restart();
|
||||
|
||||
Reference in new issue
Block a user