From 35e1ff1e17ae8a6c9e9a051698eec7ad0d32e77d Mon Sep 17 00:00:00 2001 From: stefan123t Date: Sun, 10 Jul 2022 22:56:32 +0200 Subject: [PATCH] add dnsname option for mqtt server #88 adds 28 chars to eeprom --- tools/esp8266/app.cpp | 24 ++++++------------------ tools/esp8266/defines.h | 2 +- 2 files changed, 7 insertions(+), 19 deletions(-) diff --git a/tools/esp8266/app.cpp b/tools/esp8266/app.cpp index 62036c1f1..8f164f1a3 100644 --- a/tools/esp8266/app.cpp +++ b/tools/esp8266/app.cpp @@ -124,7 +124,7 @@ void app::setup(uint32_t timeout) { // mqtt - uint8_t mqttAddr[MQTT_ADDR_LEN]; + char mqttAddr[MQTT_ADDR_LEN]; uint16_t mqttPort; char mqttUser[MQTT_USER_LEN]; char mqttPwd[MQTT_PWD_LEN]; @@ -136,9 +136,6 @@ void app::setup(uint32_t timeout) { //mEep->read(ADDR_MQTT_INTERVAL, &mMqttInterval); mEep->read(ADDR_MQTT_PORT, &mqttPort); - char addr[16] = {0}; - sprintf(addr, "%d.%d.%d.%d", mqttAddr[0], mqttAddr[1], mqttAddr[2], mqttAddr[3]); - if(mqttAddr[0] > 0) { mMqttActive = true; if(mMqttInterval < 1) @@ -150,8 +147,7 @@ void app::setup(uint32_t timeout) { if(0 == mqttPort) mqttPort = 1883; - - mMqtt.setup(addr, mqttTopic, mqttUser, mqttPwd, mqttPort); + mMqtt.setup(mqttAddr, mqttTopic, mqttUser, mqttPwd, mqttPort); mMqttTicker = 0; mSerialTicker = 0; @@ -573,14 +569,12 @@ void app::showSetup(void) { mEep->read(ADDR_SER_DEBUG, &tmp); html.replace(F("{SER_DBG_CB}"), (tmp == 0x01) ? "checked" : ""); - uint8_t mqttAddr[MQTT_ADDR_LEN] = {0}; + char mqttAddr[MQTT_ADDR_LEN] = {0}; uint16_t mqttPort; mEep->read(ADDR_MQTT_ADDR, mqttAddr, MQTT_ADDR_LEN); mEep->read(ADDR_MQTT_PORT, &mqttPort); - char addr[16] = {0}; - sprintf(addr, "%d.%d.%d.%d", mqttAddr[0], mqttAddr[1], mqttAddr[2], mqttAddr[3]); - html.replace(F("{MQTT_ADDR}"), String(addr)); + html.replace(F("{MQTT_ADDR}"), String(mqttAddr)); html.replace(F("{MQTT_PORT}"), String(mMqtt.getPort())); html.replace(F("{MQTT_USER}"), String(mMqtt.getUser())); html.replace(F("{MQTT_PWD}"), String(mMqtt.getPwd())); @@ -835,18 +829,12 @@ void app::saveValues(bool webSend = true) { mEep->write(ADDR_RF24_AMP_PWR, mSys->Radio.AmplifierPower); // mqtt - uint8_t mqttAddr[MQTT_ADDR_LEN] = {0}; + char mqttAddr[MQTT_ADDR_LEN] = {0}; uint16_t mqttPort; char mqttUser[MQTT_USER_LEN]; char mqttPwd[MQTT_PWD_LEN]; char mqttTopic[MQTT_TOPIC_LEN]; - mWeb->arg("mqttAddr").toCharArray(buf, 20); - i = 0; - p = strtok(buf, "."); - while(NULL != p) { - mqttAddr[i++] = atoi(p); - p = strtok(NULL, "."); - } + mWeb->arg("mqttAddr").toCharArray(mqttAddr, MQTT_ADDR_LEN); mWeb->arg("mqttUser").toCharArray(mqttUser, MQTT_USER_LEN); mWeb->arg("mqttPwd").toCharArray(mqttPwd, MQTT_PWD_LEN); mWeb->arg("mqttTopic").toCharArray(mqttTopic, MQTT_TOPIC_LEN); diff --git a/tools/esp8266/defines.h b/tools/esp8266/defines.h index 22a651609..56604da2d 100644 --- a/tools/esp8266/defines.h +++ b/tools/esp8266/defines.h @@ -50,7 +50,7 @@ typedef struct { #define RF24_AMP_PWR_LEN 1 -#define MQTT_ADDR_LEN 4 // IP +#define MQTT_ADDR_LEN 32 // DNS Name #define MQTT_USER_LEN 16 #define MQTT_PWD_LEN 32 #define MQTT_TOPIC_LEN 32