mirror of
https://github.com/letscontrolit/ESPEasy.git
synced 2026-07-28 04:07:47 +00:00
+2
-2
@@ -132,7 +132,7 @@ void callback(char* c_topic, byte* b_payload, unsigned int length) {
|
||||
bool MQTTConnect(int controller_idx)
|
||||
{
|
||||
++mqtt_reconnect_count;
|
||||
ControllerSettingsStruct ControllerSettings;
|
||||
MakeControllerSettings(ControllerSettings);
|
||||
LoadControllerSettings(controller_idx, ControllerSettings);
|
||||
if (!ControllerSettings.checkHostReachable(true))
|
||||
return false;
|
||||
@@ -316,7 +316,7 @@ void processMQTTdelayQueue() {
|
||||
\*********************************************************************************************/
|
||||
void MQTTStatus(String& status)
|
||||
{
|
||||
ControllerSettingsStruct ControllerSettings;
|
||||
MakeControllerSettings(ControllerSettings);
|
||||
int enabledMqttController = firstEnabledMQTTController();
|
||||
if (enabledMqttController >= 0) {
|
||||
LoadControllerSettings(enabledMqttController, ControllerSettings);
|
||||
|
||||
@@ -1058,6 +1058,11 @@ private:
|
||||
|
||||
};
|
||||
|
||||
typedef std::shared_ptr<ControllerSettingsStruct> ControllerSettingsStruct_ptr_type;
|
||||
#define MakeControllerSettings(T) ControllerSettingsStruct_ptr_type ControllerSettingsStruct_ptr(new ControllerSettingsStruct());\
|
||||
ControllerSettingsStruct& T = *ControllerSettingsStruct_ptr;
|
||||
|
||||
|
||||
|
||||
/*********************************************************************************************\
|
||||
* NotificationSettingsStruct
|
||||
|
||||
+1
-1
@@ -850,7 +850,7 @@ void ResetFactory(void)
|
||||
SaveSettings();
|
||||
|
||||
#if DEFAULT_CONTROLLER
|
||||
ControllerSettingsStruct ControllerSettings;
|
||||
MakeControllerSettings(ControllerSettings);
|
||||
strcpy_P(ControllerSettings.Subscribe, PSTR(DEFAULT_SUB));
|
||||
strcpy_P(ControllerSettings.Publish, PSTR(DEFAULT_PUB));
|
||||
strcpy_P(ControllerSettings.MQTTLwtTopic, PSTR(DEFAULT_MQTT_LWT_TOPIC));
|
||||
|
||||
+32
-27
@@ -1041,17 +1041,22 @@ void handle_config() {
|
||||
addLog(LOG_LEVEL_INFO, F("Unit Name changed."));
|
||||
MQTTclient_should_reconnect = true;
|
||||
}
|
||||
strncpy(Settings.Name, name.c_str(), sizeof(Settings.Name));
|
||||
// Unit name
|
||||
safe_strncpy(Settings.Name, name.c_str(), sizeof(Settings.Name));
|
||||
Settings.appendUnitToHostname(isFormItemChecked(F("appendunittohostname")));
|
||||
//strncpy(SecuritySettings.Password, password.c_str(), sizeof(SecuritySettings.Password));
|
||||
|
||||
// Password
|
||||
copyFormPassword(F("password"), SecuritySettings.Password, sizeof(SecuritySettings.Password));
|
||||
strncpy(SecuritySettings.WifiSSID, ssid.c_str(), sizeof(SecuritySettings.WifiSSID));
|
||||
//strncpy(SecuritySettings.WifiKey, key.c_str(), sizeof(SecuritySettings.WifiKey));
|
||||
|
||||
// SSID 1
|
||||
safe_strncpy(SecuritySettings.WifiSSID, ssid.c_str(), sizeof(SecuritySettings.WifiSSID));
|
||||
copyFormPassword(F("key"), SecuritySettings.WifiKey, sizeof(SecuritySettings.WifiKey));
|
||||
strncpy(SecuritySettings.WifiSSID2, ssid2.c_str(), sizeof(SecuritySettings.WifiSSID2));
|
||||
//strncpy(SecuritySettings.WifiKey2, key2.c_str(), sizeof(SecuritySettings.WifiKey2));
|
||||
|
||||
// SSID 2
|
||||
safe_strncpy(SecuritySettings.WifiSSID2, ssid2.c_str(), sizeof(SecuritySettings.WifiSSID2));
|
||||
copyFormPassword(F("key2"), SecuritySettings.WifiKey2, sizeof(SecuritySettings.WifiKey2));
|
||||
//strncpy(SecuritySettings.WifiAPKey, apkey.c_str(), sizeof(SecuritySettings.WifiAPKey));
|
||||
|
||||
// Access point password.
|
||||
copyFormPassword(F("apkey"), SecuritySettings.WifiAPKey, sizeof(SecuritySettings.WifiAPKey));
|
||||
|
||||
|
||||
@@ -1192,7 +1197,7 @@ void handle_controllers() {
|
||||
//submitted data
|
||||
if (protocol != -1 && !controllerNotSet)
|
||||
{
|
||||
ControllerSettingsStruct ControllerSettings;
|
||||
MakeControllerSettings(ControllerSettings);
|
||||
//submitted changed protocol
|
||||
if (Settings.Protocol[controllerindex] != protocol)
|
||||
{
|
||||
@@ -1210,11 +1215,11 @@ void handle_controllers() {
|
||||
// ControllerSettings.MaxQueueDepth = 0;
|
||||
if (Protocol[ProtocolIndex].usesTemplate)
|
||||
CPlugin_ptr[ProtocolIndex](CPLUGIN_PROTOCOL_TEMPLATE, &TempEvent, dummyString);
|
||||
strncpy(ControllerSettings.Subscribe, TempEvent.String1.c_str(), sizeof(ControllerSettings.Subscribe));
|
||||
strncpy(ControllerSettings.Publish, TempEvent.String2.c_str(), sizeof(ControllerSettings.Publish));
|
||||
strncpy(ControllerSettings.MQTTLwtTopic, TempEvent.String3.c_str(), sizeof(ControllerSettings.MQTTLwtTopic));
|
||||
strncpy(ControllerSettings.LWTMessageConnect, TempEvent.String4.c_str(), sizeof(ControllerSettings.LWTMessageConnect));
|
||||
strncpy(ControllerSettings.LWTMessageDisconnect, TempEvent.String5.c_str(), sizeof(ControllerSettings.LWTMessageDisconnect));
|
||||
safe_strncpy(ControllerSettings.Subscribe, TempEvent.String1.c_str(), sizeof(ControllerSettings.Subscribe));
|
||||
safe_strncpy(ControllerSettings.Publish, TempEvent.String2.c_str(), sizeof(ControllerSettings.Publish));
|
||||
safe_strncpy(ControllerSettings.MQTTLwtTopic, TempEvent.String3.c_str(), sizeof(ControllerSettings.MQTTLwtTopic));
|
||||
safe_strncpy(ControllerSettings.LWTMessageConnect, TempEvent.String4.c_str(), sizeof(ControllerSettings.LWTMessageConnect));
|
||||
safe_strncpy(ControllerSettings.LWTMessageDisconnect, TempEvent.String5.c_str(), sizeof(ControllerSettings.LWTMessageDisconnect));
|
||||
TempEvent.String1 = "";
|
||||
TempEvent.String2 = "";
|
||||
TempEvent.String3 = "";
|
||||
@@ -1245,7 +1250,7 @@ void handle_controllers() {
|
||||
ControllerSettings.UseDNS = usedns.toInt();
|
||||
if (ControllerSettings.UseDNS)
|
||||
{
|
||||
strncpy(ControllerSettings.HostName, controllerhostname.c_str(), sizeof(ControllerSettings.HostName));
|
||||
safe_strncpy(ControllerSettings.HostName, controllerhostname.c_str(), sizeof(ControllerSettings.HostName));
|
||||
IPAddress IP;
|
||||
WiFi.hostByName(ControllerSettings.HostName, IP);
|
||||
for (byte x = 0; x < 4; x++)
|
||||
@@ -1259,14 +1264,14 @@ void handle_controllers() {
|
||||
//copy settings to struct
|
||||
Settings.ControllerEnabled[controllerindex] = isFormItemChecked(F("controllerenabled"));
|
||||
ControllerSettings.Port = controllerport;
|
||||
strncpy(SecuritySettings.ControllerUser[controllerindex], controlleruser.c_str(), sizeof(SecuritySettings.ControllerUser[0]));
|
||||
//strncpy(SecuritySettings.ControllerPassword[controllerindex], controllerpassword.c_str(), sizeof(SecuritySettings.ControllerPassword[0]));
|
||||
safe_strncpy(SecuritySettings.ControllerUser[controllerindex], controlleruser.c_str(), sizeof(SecuritySettings.ControllerUser[0]));
|
||||
//safe_strncpy(SecuritySettings.ControllerPassword[controllerindex], controllerpassword.c_str(), sizeof(SecuritySettings.ControllerPassword[0]));
|
||||
copyFormPassword(F("controllerpassword"), SecuritySettings.ControllerPassword[controllerindex], sizeof(SecuritySettings.ControllerPassword[0]));
|
||||
strncpy(ControllerSettings.Subscribe, controllersubscribe.c_str(), sizeof(ControllerSettings.Subscribe));
|
||||
strncpy(ControllerSettings.Publish, controllerpublish.c_str(), sizeof(ControllerSettings.Publish));
|
||||
strncpy(ControllerSettings.MQTTLwtTopic, MQTTLwtTopic.c_str(), sizeof(ControllerSettings.MQTTLwtTopic));
|
||||
strncpy(ControllerSettings.LWTMessageConnect, lwtmessageconnect.c_str(), sizeof(ControllerSettings.LWTMessageConnect));
|
||||
strncpy(ControllerSettings.LWTMessageDisconnect, lwtmessagedisconnect.c_str(), sizeof(ControllerSettings.LWTMessageDisconnect));
|
||||
safe_strncpy(ControllerSettings.Subscribe, controllersubscribe.c_str(), sizeof(ControllerSettings.Subscribe));
|
||||
safe_strncpy(ControllerSettings.Publish, controllerpublish.c_str(), sizeof(ControllerSettings.Publish));
|
||||
safe_strncpy(ControllerSettings.MQTTLwtTopic, MQTTLwtTopic.c_str(), sizeof(ControllerSettings.MQTTLwtTopic));
|
||||
safe_strncpy(ControllerSettings.LWTMessageConnect, lwtmessageconnect.c_str(), sizeof(ControllerSettings.LWTMessageConnect));
|
||||
safe_strncpy(ControllerSettings.LWTMessageDisconnect, lwtmessagedisconnect.c_str(), sizeof(ControllerSettings.LWTMessageDisconnect));
|
||||
ControllerSettings.MinimalTimeBetweenMessages = minimumsendinterval;
|
||||
ControllerSettings.MaxQueueDepth = maxqueuedepth;
|
||||
ControllerSettings.MaxRetry = maxretry;
|
||||
@@ -1289,7 +1294,7 @@ void handle_controllers() {
|
||||
TXBuffer += F("<table class='multirow' border=1px frame='box' rules='all'><TR><TH style='width:70px;'>");
|
||||
TXBuffer += F("<TH style='width:50px;'>Nr<TH style='width:100px;'>Enabled<TH>Protocol<TH>Host<TH>Port");
|
||||
|
||||
ControllerSettingsStruct ControllerSettings;
|
||||
MakeControllerSettings(ControllerSettings);
|
||||
for (byte x = 0; x < CONTROLLER_MAX; x++)
|
||||
{
|
||||
LoadControllerSettings(x, ControllerSettings);
|
||||
@@ -1347,7 +1352,7 @@ void handle_controllers() {
|
||||
|
||||
if (Settings.Protocol[controllerindex])
|
||||
{
|
||||
ControllerSettingsStruct ControllerSettings;
|
||||
MakeControllerSettings(ControllerSettings);
|
||||
LoadControllerSettings(controllerindex, ControllerSettings);
|
||||
byte choice = ControllerSettings.UseDNS;
|
||||
String options[2];
|
||||
@@ -3012,7 +3017,7 @@ void copyFormPassword(const String& id, char* pPassword, int maxlength)
|
||||
String password = WebServer.arg(id);
|
||||
if (password == F("*****")) //no change?
|
||||
return;
|
||||
strncpy(pPassword, password.c_str(), maxlength);
|
||||
safe_strncpy(pPassword, password.c_str(), maxlength);
|
||||
}
|
||||
|
||||
void addFormIPBox(const String& label, const String& id, const byte ip[4])
|
||||
@@ -4973,8 +4978,8 @@ void handle_setup() {
|
||||
// if ssid config not set and params are both provided
|
||||
if (status == 0 && ssid.length() != 0 /*&& strcasecmp(SecuritySettings.WifiSSID, "ssid") == 0 */)
|
||||
{
|
||||
strncpy(SecuritySettings.WifiKey, password.c_str(), sizeof(SecuritySettings.WifiKey));
|
||||
strncpy(SecuritySettings.WifiSSID, ssid.c_str(), sizeof(SecuritySettings.WifiSSID));
|
||||
safe_strncpy(SecuritySettings.WifiKey, password.c_str(), sizeof(SecuritySettings.WifiKey));
|
||||
safe_strncpy(SecuritySettings.WifiSSID, ssid.c_str(), sizeof(SecuritySettings.WifiSSID));
|
||||
wifiSetupConnect = true;
|
||||
if (loglevelActiveFor(LOG_LEVEL_INFO)) {
|
||||
String reconnectlog = F("WIFI : Credentials Changed, retry connection. SSID: ");
|
||||
@@ -5037,7 +5042,7 @@ void handle_setup() {
|
||||
if (refreshCount > 0)
|
||||
{
|
||||
status = 0;
|
||||
// strncpy(SecuritySettings.WifiSSID, "ssid", sizeof(SecuritySettings.WifiSSID));
|
||||
// safe_strncpy(SecuritySettings.WifiSSID, "ssid", sizeof(SecuritySettings.WifiSSID));
|
||||
// SecuritySettings.WifiKey[0] = 0;
|
||||
TXBuffer += F("<a class='button' href='setup'>Back to Setup</a><BR><BR>");
|
||||
}
|
||||
|
||||
+1
-1
@@ -33,7 +33,7 @@ boolean CPlugin_001(byte function, struct EventStruct *event, String& string)
|
||||
|
||||
case CPLUGIN_INIT:
|
||||
{
|
||||
ControllerSettingsStruct ControllerSettings;
|
||||
MakeControllerSettings(ControllerSettings);
|
||||
LoadControllerSettings(event->ControllerIndex, ControllerSettings);
|
||||
C001_DelayHandler.configureControllerSettings(ControllerSettings);
|
||||
break;
|
||||
|
||||
+2
-2
@@ -35,7 +35,7 @@ boolean CPlugin_002(byte function, struct EventStruct *event, String& string)
|
||||
|
||||
case CPLUGIN_INIT:
|
||||
{
|
||||
ControllerSettingsStruct ControllerSettings;
|
||||
MakeControllerSettings(ControllerSettings);
|
||||
LoadControllerSettings(event->ControllerIndex, ControllerSettings);
|
||||
MQTTDelayHandler.configureControllerSettings(ControllerSettings);
|
||||
break;
|
||||
@@ -145,7 +145,7 @@ boolean CPlugin_002(byte function, struct EventStruct *event, String& string)
|
||||
{
|
||||
if (event->idx != 0)
|
||||
{
|
||||
ControllerSettingsStruct ControllerSettings;
|
||||
MakeControllerSettings(ControllerSettings);
|
||||
LoadControllerSettings(event->ControllerIndex, ControllerSettings);
|
||||
/*
|
||||
if (!ControllerSettings.checkHostReachable(true)) {
|
||||
|
||||
+1
-1
@@ -32,7 +32,7 @@ boolean CPlugin_003(byte function, struct EventStruct *event, String& string)
|
||||
|
||||
case CPLUGIN_INIT:
|
||||
{
|
||||
ControllerSettingsStruct ControllerSettings;
|
||||
MakeControllerSettings(ControllerSettings);
|
||||
LoadControllerSettings(event->ControllerIndex, ControllerSettings);
|
||||
C003_DelayHandler.configureControllerSettings(ControllerSettings);
|
||||
break;
|
||||
|
||||
+1
-1
@@ -32,7 +32,7 @@ boolean CPlugin_004(byte function, struct EventStruct *event, String& string)
|
||||
|
||||
case CPLUGIN_INIT:
|
||||
{
|
||||
ControllerSettingsStruct ControllerSettings;
|
||||
MakeControllerSettings(ControllerSettings);
|
||||
LoadControllerSettings(event->ControllerIndex, ControllerSettings);
|
||||
C004_DelayHandler.configureControllerSettings(ControllerSettings);
|
||||
break;
|
||||
|
||||
+2
-2
@@ -33,7 +33,7 @@ boolean CPlugin_005(byte function, struct EventStruct *event, String& string)
|
||||
|
||||
case CPLUGIN_INIT:
|
||||
{
|
||||
ControllerSettingsStruct ControllerSettings;
|
||||
MakeControllerSettings(ControllerSettings);
|
||||
LoadControllerSettings(event->ControllerIndex, ControllerSettings);
|
||||
MQTTDelayHandler.configureControllerSettings(ControllerSettings);
|
||||
break;
|
||||
@@ -92,7 +92,7 @@ boolean CPlugin_005(byte function, struct EventStruct *event, String& string)
|
||||
|
||||
case CPLUGIN_PROTOCOL_SEND:
|
||||
{
|
||||
ControllerSettingsStruct ControllerSettings;
|
||||
MakeControllerSettings(ControllerSettings);
|
||||
LoadControllerSettings(event->ControllerIndex, ControllerSettings);
|
||||
if (!ControllerSettings.checkHostReachable(true)) {
|
||||
success = false;
|
||||
|
||||
+2
-2
@@ -33,7 +33,7 @@ boolean CPlugin_006(byte function, struct EventStruct *event, String& string)
|
||||
|
||||
case CPLUGIN_INIT:
|
||||
{
|
||||
ControllerSettingsStruct ControllerSettings;
|
||||
MakeControllerSettings(ControllerSettings);
|
||||
LoadControllerSettings(event->ControllerIndex, ControllerSettings);
|
||||
MQTTDelayHandler.configureControllerSettings(ControllerSettings);
|
||||
break;
|
||||
@@ -90,7 +90,7 @@ boolean CPlugin_006(byte function, struct EventStruct *event, String& string)
|
||||
success = false;
|
||||
break;
|
||||
}
|
||||
ControllerSettingsStruct ControllerSettings;
|
||||
MakeControllerSettings(ControllerSettings);
|
||||
LoadControllerSettings(event->ControllerIndex, ControllerSettings);
|
||||
|
||||
statusLED(true);
|
||||
|
||||
+1
-1
@@ -32,7 +32,7 @@ boolean CPlugin_007(byte function, struct EventStruct *event, String& string)
|
||||
|
||||
case CPLUGIN_INIT:
|
||||
{
|
||||
ControllerSettingsStruct ControllerSettings;
|
||||
MakeControllerSettings(ControllerSettings);
|
||||
LoadControllerSettings(event->ControllerIndex, ControllerSettings);
|
||||
C007_DelayHandler.configureControllerSettings(ControllerSettings);
|
||||
break;
|
||||
|
||||
+2
-2
@@ -34,7 +34,7 @@ boolean CPlugin_008(byte function, struct EventStruct *event, String& string)
|
||||
|
||||
case CPLUGIN_INIT:
|
||||
{
|
||||
ControllerSettingsStruct ControllerSettings;
|
||||
MakeControllerSettings(ControllerSettings);
|
||||
LoadControllerSettings(event->ControllerIndex, ControllerSettings);
|
||||
C008_DelayHandler.configureControllerSettings(ControllerSettings);
|
||||
break;
|
||||
@@ -55,7 +55,7 @@ boolean CPlugin_008(byte function, struct EventStruct *event, String& string)
|
||||
if (ExtraTaskSettings.TaskIndex != event->TaskIndex)
|
||||
PluginCall(PLUGIN_GET_DEVICEVALUENAMES, event, dummyString);
|
||||
|
||||
ControllerSettingsStruct ControllerSettings;
|
||||
MakeControllerSettings(ControllerSettings);
|
||||
LoadControllerSettings(event->ControllerIndex, ControllerSettings);
|
||||
|
||||
for (byte x = 0; x < valueCount; x++)
|
||||
|
||||
+1
-1
@@ -62,7 +62,7 @@ boolean CPlugin_009(byte function, struct EventStruct *event, String& string)
|
||||
if (ExtraTaskSettings.TaskIndex != event->TaskIndex)
|
||||
PluginCall(PLUGIN_GET_DEVICEVALUENAMES, event, dummyString);
|
||||
|
||||
ControllerSettingsStruct ControllerSettings;
|
||||
MakeControllerSettings(ControllerSettings);
|
||||
LoadControllerSettings(event->ControllerIndex, ControllerSettings);
|
||||
|
||||
for (byte x = 0; x < valueCount; x++)
|
||||
|
||||
+1
-1
@@ -45,7 +45,7 @@ boolean CPlugin_010(byte function, struct EventStruct *event, String& string)
|
||||
if (ExtraTaskSettings.TaskIndex != event->TaskIndex)
|
||||
PluginCall(PLUGIN_GET_DEVICEVALUENAMES, event, dummyString);
|
||||
|
||||
ControllerSettingsStruct ControllerSettings;
|
||||
MakeControllerSettings(ControllerSettings);
|
||||
LoadControllerSettings(event->ControllerIndex, ControllerSettings);
|
||||
|
||||
for (byte x = 0; x < valueCount; x++)
|
||||
|
||||
+1
-1
@@ -147,7 +147,7 @@ boolean Create_schedule_HTTP_C011(struct EventStruct *event)
|
||||
if (!WiFiConnected(100)) {
|
||||
return false;
|
||||
}
|
||||
ControllerSettingsStruct ControllerSettings;
|
||||
MakeControllerSettings(ControllerSettings);
|
||||
LoadControllerSettings(event->ControllerIndex, ControllerSettings);
|
||||
|
||||
C011_ConfigStruct customConfig;
|
||||
|
||||
+2
-2
@@ -40,7 +40,7 @@ boolean CPlugin_012(byte function, struct EventStruct *event, String& string)
|
||||
if (ExtraTaskSettings.TaskIndex != event->TaskIndex)
|
||||
PluginCall(PLUGIN_GET_DEVICEVALUENAMES, event, dummyString);
|
||||
|
||||
ControllerSettingsStruct ControllerSettings;
|
||||
MakeControllerSettings(ControllerSettings);
|
||||
LoadControllerSettings(event->ControllerIndex, ControllerSettings);
|
||||
|
||||
for (byte x = 0; x < valueCount; x++)
|
||||
@@ -81,7 +81,7 @@ bool do_process_c012_delay_queue(int controller_number, const C012_queue_element
|
||||
|
||||
boolean Blynk_get(const String& command, byte controllerIndex, float *data )
|
||||
{
|
||||
ControllerSettingsStruct ControllerSettings;
|
||||
MakeControllerSettings(ControllerSettings);
|
||||
LoadControllerSettings(controllerIndex, ControllerSettings);
|
||||
|
||||
if ((SecuritySettings.ControllerPassword[controllerIndex][0] == 0)) {
|
||||
|
||||
@@ -338,7 +338,7 @@ ControllerDelayHandlerStruct<MQTT_queue_element> MQTTDelayHandler;
|
||||
void process_c##NNN##_delay_queue() { \
|
||||
C##NNN##_queue_element element; \
|
||||
if (!C##NNN##_DelayHandler.getNext(element)) return; \
|
||||
ControllerSettingsStruct ControllerSettings; \
|
||||
MakeControllerSettings(ControllerSettings); \
|
||||
LoadControllerSettings(element.controller_idx, ControllerSettings); \
|
||||
C##NNN##_DelayHandler.configureControllerSettings(ControllerSettings); \
|
||||
if (!WiFiConnected(100)) { \
|
||||
|
||||
@@ -392,7 +392,7 @@ boolean MQTTConnect_037()
|
||||
Plugin_037_update_connect_status();
|
||||
return false; // Not connected, so no use in wasting time to connect to a host.
|
||||
}
|
||||
ControllerSettingsStruct ControllerSettings;
|
||||
MakeControllerSettings(ControllerSettings);
|
||||
LoadControllerSettings(enabledMqttController, ControllerSettings);
|
||||
if (ControllerSettings.UseDNS) {
|
||||
MQTTclient_037->setServer(ControllerSettings.getHost().c_str(), ControllerSettings.Port);
|
||||
|
||||
Reference in New Issue
Block a user