mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 15:59:52 +03:00
move generateClientId()
This commit is contained in:
@@ -16,6 +16,14 @@ MqttSettingsService::MqttSettingsService(AsyncWebServer * server, FS * fs, Secur
|
|||||||
addUpdateHandler([this] { onConfigUpdated(); }, false);
|
addUpdateHandler([this] { onConfigUpdated(); }, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static String generateClientId() {
|
||||||
|
#ifdef EMSESP_STANDALONE
|
||||||
|
return "ems-esp";
|
||||||
|
#else
|
||||||
|
return "esp32-" + String(static_cast<uint32_t>(ESP.getEfuseMac()), HEX);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
MqttSettingsService::~MqttSettingsService() {
|
MqttSettingsService::~MqttSettingsService() {
|
||||||
delete _mqttClient;
|
delete _mqttClient;
|
||||||
}
|
}
|
||||||
@@ -255,7 +263,7 @@ StateUpdateResult MqttSettings::update(JsonObject root, MqttSettings & settings)
|
|||||||
newSettings.base = root["base"] | FACTORY_MQTT_BASE;
|
newSettings.base = root["base"] | FACTORY_MQTT_BASE;
|
||||||
newSettings.username = root["username"] | FACTORY_MQTT_USERNAME;
|
newSettings.username = root["username"] | FACTORY_MQTT_USERNAME;
|
||||||
newSettings.password = root["password"] | FACTORY_MQTT_PASSWORD;
|
newSettings.password = root["password"] | FACTORY_MQTT_PASSWORD;
|
||||||
newSettings.clientId = root["client_id"] | FACTORY_MQTT_CLIENT_ID;
|
newSettings.clientId = root["client_id"] | generateClientId();
|
||||||
newSettings.keepAlive = static_cast<uint16_t>(root["keep_alive"] | FACTORY_MQTT_KEEP_ALIVE);
|
newSettings.keepAlive = static_cast<uint16_t>(root["keep_alive"] | FACTORY_MQTT_KEEP_ALIVE);
|
||||||
newSettings.cleanSession = root["clean_session"] | FACTORY_MQTT_CLEAN_SESSION;
|
newSettings.cleanSession = root["clean_session"] | FACTORY_MQTT_CLEAN_SESSION;
|
||||||
newSettings.mqtt_qos = static_cast<uint8_t>(root["mqtt_qos"] | EMSESP_DEFAULT_MQTT_QOS);
|
newSettings.mqtt_qos = static_cast<uint8_t>(root["mqtt_qos"] | EMSESP_DEFAULT_MQTT_QOS);
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
#include "StatefulService.h"
|
#include "StatefulService.h"
|
||||||
#include "HttpEndpoint.h"
|
#include "HttpEndpoint.h"
|
||||||
#include "FSPersistence.h"
|
#include "FSPersistence.h"
|
||||||
#include "ESPUtils.h"
|
|
||||||
|
|
||||||
#include <espMqttClient.h>
|
#include <espMqttClient.h>
|
||||||
|
|
||||||
@@ -39,13 +38,6 @@
|
|||||||
#define FACTORY_MQTT_PASSWORD ""
|
#define FACTORY_MQTT_PASSWORD ""
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef FACTORY_MQTT_CLIENT_ID
|
|
||||||
#define FACTORY_MQTT_CLIENT_ID generateClientId()
|
|
||||||
static String generateClientId() {
|
|
||||||
return ESPUtils::defaultDeviceValue("esp32-");
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef FACTORY_MQTT_KEEP_ALIVE
|
#ifndef FACTORY_MQTT_KEEP_ALIVE
|
||||||
#define FACTORY_MQTT_KEEP_ALIVE 16
|
#define FACTORY_MQTT_KEEP_ALIVE 16
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -3,16 +3,11 @@
|
|||||||
|
|
||||||
#include "Features.h"
|
#include "Features.h"
|
||||||
#include "ArduinoJsonJWT.h"
|
#include "ArduinoJsonJWT.h"
|
||||||
#include "ESPUtils.h"
|
|
||||||
|
|
||||||
#include <ESPAsyncWebServer.h>
|
#include <ESPAsyncWebServer.h>
|
||||||
#include <AsyncJson.h>
|
#include <AsyncJson.h>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
|
||||||
#ifndef FACTORY_JWT_SECRET
|
|
||||||
#define FACTORY_JWT_SECRET ESPUtils::defaultDeviceValue()
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define ACCESS_TOKEN_PARAMATER "access_token"
|
#define ACCESS_TOKEN_PARAMATER "access_token"
|
||||||
|
|
||||||
#define AUTHORIZATION_HEADER "Authorization"
|
#define AUTHORIZATION_HEADER "Authorization"
|
||||||
|
|||||||
Reference in New Issue
Block a user