Browse Source

add dnsname option for mqtt server #88 adds 28 chars to eeprom

pull/98/head
stefan123t 3 years ago
parent
commit
35e1ff1e17
  1. 24
      tools/esp8266/app.cpp
  2. 2
      tools/esp8266/defines.h

24
tools/esp8266/app.cpp

@ -124,7 +124,7 @@ void app::setup(uint32_t timeout) {
// mqtt // mqtt
uint8_t mqttAddr[MQTT_ADDR_LEN]; char mqttAddr[MQTT_ADDR_LEN];
uint16_t mqttPort; uint16_t mqttPort;
char mqttUser[MQTT_USER_LEN]; char mqttUser[MQTT_USER_LEN];
char mqttPwd[MQTT_PWD_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_INTERVAL, &mMqttInterval);
mEep->read(ADDR_MQTT_PORT, &mqttPort); 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) { if(mqttAddr[0] > 0) {
mMqttActive = true; mMqttActive = true;
if(mMqttInterval < 1) if(mMqttInterval < 1)
@ -150,8 +147,7 @@ void app::setup(uint32_t timeout) {
if(0 == mqttPort) if(0 == mqttPort)
mqttPort = 1883; mqttPort = 1883;
mMqtt.setup(mqttAddr, mqttTopic, mqttUser, mqttPwd, mqttPort);
mMqtt.setup(addr, mqttTopic, mqttUser, mqttPwd, mqttPort);
mMqttTicker = 0; mMqttTicker = 0;
mSerialTicker = 0; mSerialTicker = 0;
@ -573,14 +569,12 @@ void app::showSetup(void) {
mEep->read(ADDR_SER_DEBUG, &tmp); mEep->read(ADDR_SER_DEBUG, &tmp);
html.replace(F("{SER_DBG_CB}"), (tmp == 0x01) ? "checked" : ""); 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; uint16_t mqttPort;
mEep->read(ADDR_MQTT_ADDR, mqttAddr, MQTT_ADDR_LEN); mEep->read(ADDR_MQTT_ADDR, mqttAddr, MQTT_ADDR_LEN);
mEep->read(ADDR_MQTT_PORT, &mqttPort); mEep->read(ADDR_MQTT_PORT, &mqttPort);
char addr[16] = {0}; html.replace(F("{MQTT_ADDR}"), String(mqttAddr));
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_PORT}"), String(mMqtt.getPort())); html.replace(F("{MQTT_PORT}"), String(mMqtt.getPort()));
html.replace(F("{MQTT_USER}"), String(mMqtt.getUser())); html.replace(F("{MQTT_USER}"), String(mMqtt.getUser()));
html.replace(F("{MQTT_PWD}"), String(mMqtt.getPwd())); 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); mEep->write(ADDR_RF24_AMP_PWR, mSys->Radio.AmplifierPower);
// mqtt // mqtt
uint8_t mqttAddr[MQTT_ADDR_LEN] = {0}; char mqttAddr[MQTT_ADDR_LEN] = {0};
uint16_t mqttPort; uint16_t mqttPort;
char mqttUser[MQTT_USER_LEN]; char mqttUser[MQTT_USER_LEN];
char mqttPwd[MQTT_PWD_LEN]; char mqttPwd[MQTT_PWD_LEN];
char mqttTopic[MQTT_TOPIC_LEN]; char mqttTopic[MQTT_TOPIC_LEN];
mWeb->arg("mqttAddr").toCharArray(buf, 20); mWeb->arg("mqttAddr").toCharArray(mqttAddr, MQTT_ADDR_LEN);
i = 0;
p = strtok(buf, ".");
while(NULL != p) {
mqttAddr[i++] = atoi(p);
p = strtok(NULL, ".");
}
mWeb->arg("mqttUser").toCharArray(mqttUser, MQTT_USER_LEN); mWeb->arg("mqttUser").toCharArray(mqttUser, MQTT_USER_LEN);
mWeb->arg("mqttPwd").toCharArray(mqttPwd, MQTT_PWD_LEN); mWeb->arg("mqttPwd").toCharArray(mqttPwd, MQTT_PWD_LEN);
mWeb->arg("mqttTopic").toCharArray(mqttTopic, MQTT_TOPIC_LEN); mWeb->arg("mqttTopic").toCharArray(mqttTopic, MQTT_TOPIC_LEN);

2
tools/esp8266/defines.h

@ -50,7 +50,7 @@ typedef struct {
#define RF24_AMP_PWR_LEN 1 #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_USER_LEN 16
#define MQTT_PWD_LEN 32 #define MQTT_PWD_LEN 32
#define MQTT_TOPIC_LEN 32 #define MQTT_TOPIC_LEN 32

Loading…
Cancel
Save