updated DeviceName handling

This commit is contained in:
2024-05-31 12:49:06 +02:00
parent a22f71649a
commit 52026296f2
6 changed files with 21 additions and 11 deletions

View File

@@ -84,7 +84,8 @@ void setup()
system_update_cpu_freq(SYS_CPU_80MHZ);
// Generate a unique device name based on ESP chip ID
snprintf(globals.DeviceName, 32, HOST_NAME, ESP.getChipId());
strncpy(globals.DeviceName, HOST_NAME, sizeof(globals.DeviceName));
snprintf(globals.DeviceNameId, sizeof(globals.DeviceNameId), "%s_%08X", globals.DeviceName, ESP.getChipId());
// Disable WiFi persistent storage
WiFi.persistent(false);
@@ -95,7 +96,7 @@ void setup()
#ifdef FEATURE_ENABLE_WIFI_CLIENT
// Configure WiFi settings for client mode if enabled
WiFi.mode(WIFI_STA);
WiFi.setHostname(globals.DeviceName);
WiFi.setHostname(globals.DeviceNameId);
wifiMulti.addAP(QUOTE(WIFI_SSID_CLIENT), QUOTE(WIFI_PASSWORD_CLIENT));
tmrWiFiMaintainConnection.start();
#else
@@ -108,7 +109,7 @@ void setup()
Serial.setDebugOutput(false);
Serial.print("\n\n-------------------START-------------------\n");
Serial.print(globals.DeviceName);
Serial.print(globals.DeviceNameId);
Serial.print("\nby Hiabuto Defense\n");
// Initialize EEPROM, load configuration, and persistence data from EEPROM
@@ -150,7 +151,7 @@ void setup()
// Set up OTA updates
ArduinoOTA.setPort(8266);
ArduinoOTA.setHostname(globals.DeviceName);
ArduinoOTA.setHostname(globals.DeviceNameId);
ArduinoOTA.setPassword(QUOTE(ADMIN_PASSWORD));
ArduinoOTA.onStart([]()
@@ -583,7 +584,7 @@ void toggleWiFiAP(bool shutdown)
// Start WiFi in Access Point (AP) mode
WiFi.mode(WIFI_AP);
WiFi.softAPConfig(IPAddress(WIFI_AP_IP_GW), IPAddress(WIFI_AP_IP_GW), IPAddress(255, 255, 255, 0));
WiFi.softAP(globals.DeviceName, QUOTE(WIFI_AP_PASSWORD));
WiFi.softAP(globals.DeviceNameId, QUOTE(WIFI_AP_PASSWORD));
// Stop WiFi maintenance connection ticker if enabled and display debug messages
#ifdef FEATURE_ENABLE_WIFI_CLIENT

View File

@@ -71,7 +71,7 @@ void initWebUI()
}
// Initialize mDNS and add service
MDNS.begin(globals.DeviceName);
MDNS.begin(globals.DeviceNameId);
MDNS.addService("http", "tcp", 80);
// Set up WebSocket event handler and attach to web server
@@ -342,7 +342,7 @@ void WebServerEEJSON_Callback(AsyncWebServerRequest *request)
char buffer[16];
info["DeviceName"] = globals.DeviceName;
info["DeviceNameId"] = globals.DeviceNameId;
sprintf(buffer, "%d.%02d", constants.Required_Flash_Version_major, constants.Required_Flash_Version_minor);
info["FW-Version"] = buffer;
info["FS-Version"] = globals.FlashVersion;
@@ -653,6 +653,7 @@ void Websocket_RefreshClientData_Static(uint32_t client_id, bool send_mapping)
if (send_mapping)
{
const char mapping[] = "MAPPING_STATIC:"
"devicename;"
"active_faction_on_reboot;"
"batteryType;"
"name_faction1;"
@@ -669,6 +670,7 @@ void Websocket_RefreshClientData_Static(uint32_t client_id, bool send_mapping)
String temp = "STATIC:";
temp.concat(String(globals.DeviceName) + ";");
temp.concat(String(ConfigData.active_faction_on_reboot) + ";");
temp.concat(String(ConfigData.batteryType) + ";");
temp.concat(String(ConfigData.Faction_1_Name) + ";");