Browse Source

Allow {hostname} and {mac} placeholder for mqtt user and client_id fields (#1338)

alexa
Xose Pérez 6 years ago
parent
commit
7eef56071d
14 changed files with 15953 additions and 15929 deletions
  1. BIN
      code/espurna/data/index.all.html.gz
  2. BIN
      code/espurna/data/index.light.html.gz
  3. BIN
      code/espurna/data/index.rfbridge.html.gz
  4. BIN
      code/espurna/data/index.rfm69.html.gz
  5. BIN
      code/espurna/data/index.sensor.html.gz
  6. BIN
      code/espurna/data/index.small.html.gz
  7. +18
    -7
      code/espurna/mqtt.ino
  8. +3134
    -3132
      code/espurna/static/index.all.html.gz.h
  9. +2984
    -2983
      code/espurna/static/index.light.html.gz.h
  10. +2001
    -2000
      code/espurna/static/index.rfbridge.html.gz.h
  11. +3332
    -3331
      code/espurna/static/index.rfm69.html.gz.h
  12. +2521
    -2519
      code/espurna/static/index.sensor.html.gz.h
  13. +1957
    -1956
      code/espurna/static/index.small.html.gz.h
  14. +6
    -1
      code/html/index.html

BIN
code/espurna/data/index.all.html.gz View File


BIN
code/espurna/data/index.light.html.gz View File


BIN
code/espurna/data/index.rfbridge.html.gz View File


BIN
code/espurna/data/index.rfm69.html.gz View File


BIN
code/espurna/data/index.sensor.html.gz View File


BIN
code/espurna/data/index.small.html.gz View File


+ 18
- 7
code/espurna/mqtt.ino View File

@ -98,10 +98,14 @@ void _mqttConnect() {
if (_mqtt_will) free(_mqtt_will); if (_mqtt_will) free(_mqtt_will);
if (_mqtt_clientid) free(_mqtt_clientid); if (_mqtt_clientid) free(_mqtt_clientid);
_mqtt_user = strdup(getSetting("mqttUser", MQTT_USER).c_str());
String user = getSetting("mqttUser", MQTT_USER);
_mqttPlaceholders(&user);
_mqtt_user = strdup(user.c_str());
_mqtt_pass = strdup(getSetting("mqttPassword", MQTT_PASS).c_str()); _mqtt_pass = strdup(getSetting("mqttPassword", MQTT_PASS).c_str());
_mqtt_will = strdup(mqttTopic(MQTT_TOPIC_STATUS, false).c_str()); _mqtt_will = strdup(mqttTopic(MQTT_TOPIC_STATUS, false).c_str());
_mqtt_clientid = strdup(getSetting("mqttClientID", getIdentifier()).c_str());
String clientid = getSetting("mqttClientID", getIdentifier());
_mqttPlaceholders(&clientid);
_mqtt_clientid = strdup(clientid.c_str());
DEBUG_MSG_P(PSTR("[MQTT] Connecting to broker at %s:%d\n"), host, port); DEBUG_MSG_P(PSTR("[MQTT] Connecting to broker at %s:%d\n"), host, port);
@ -211,6 +215,17 @@ void _mqttConnect() {
} }
void _mqttPlaceholders(String *text) {
text->replace("{hostname}", getSetting("hostname"));
text->replace("{magnitude}", "#");
String mac = WiFi.macAddress();
mac.replace(":", "");
text->replace("{mac}", mac);
}
void _mqttConfigure() { void _mqttConfigure() {
// Get base topic // Get base topic
@ -218,12 +233,8 @@ void _mqttConfigure() {
if (_mqtt_topic.endsWith("/")) _mqtt_topic.remove(_mqtt_topic.length()-1); if (_mqtt_topic.endsWith("/")) _mqtt_topic.remove(_mqtt_topic.length()-1);
// Placeholders // Placeholders
_mqtt_topic.replace("{hostname}", getSetting("hostname"));
_mqtt_topic.replace("{magnitude}", "#");
_mqttPlaceholders(&_mqtt_topic);
if (_mqtt_topic.indexOf("#") == -1) _mqtt_topic = _mqtt_topic + "/#"; if (_mqtt_topic.indexOf("#") == -1) _mqtt_topic = _mqtt_topic + "/#";
String mac = WiFi.macAddress();
mac.replace(":", "");
_mqtt_topic.replace("{mac}", mac);
// Getters and setters // Getters and setters
_mqtt_setter = getSetting("mqttSetter", MQTT_SETTER); _mqtt_setter = getSetting("mqttSetter", MQTT_SETTER);


+ 3134
- 3132
code/espurna/static/index.all.html.gz.h
File diff suppressed because it is too large
View File


+ 2984
- 2983
code/espurna/static/index.light.html.gz.h
File diff suppressed because it is too large
View File


+ 2001
- 2000
code/espurna/static/index.rfbridge.html.gz.h
File diff suppressed because it is too large
View File


+ 3332
- 3331
code/espurna/static/index.rfm69.html.gz.h
File diff suppressed because it is too large
View File


+ 2521
- 2519
code/espurna/static/index.sensor.html.gz.h
File diff suppressed because it is too large
View File


+ 1957
- 1956
code/espurna/static/index.small.html.gz.h
File diff suppressed because it is too large
View File


+ 6
- 1
code/html/index.html View File

@ -814,6 +814,11 @@
<div class="pure-g"> <div class="pure-g">
<label class="pure-u-1 pure-u-lg-1-4">MQTT User</label> <label class="pure-u-1 pure-u-lg-1-4">MQTT User</label>
<input class="pure-u-1 pure-u-lg-1-4" name="mqttUser" type="text" tabindex="23" placeholder="Leave blank if no user" autocomplete="off" /> <input class="pure-u-1 pure-u-lg-1-4" name="mqttUser" type="text" tabindex="23" placeholder="Leave blank if no user" autocomplete="off" />
<div class="pure-u-0 pure-u-lg-1-2"></div>
<div class="pure-u-0 pure-u-lg-1-4"></div>
<div class="pure-u-1 pure-u-lg-3-4 hint">
You can use the following placeholders: {hostname}, {mac}
</div>
</div> </div>
<div class="pure-g"> <div class="pure-g">
@ -828,7 +833,7 @@
<div class="pure-u-0 pure-u-lg-1-2"></div> <div class="pure-u-0 pure-u-lg-1-2"></div>
<div class="pure-u-0 pure-u-lg-1-4"></div> <div class="pure-u-0 pure-u-lg-1-4"></div>
<div class="pure-u-1 pure-u-lg-3-4 hint"> <div class="pure-u-1 pure-u-lg-3-4 hint">
If left empty the firmware will generate a client ID based on the serial number of the chip.
If left empty the firmware will generate a client ID based on the serial number of the chip. You can use the following placeholders: {hostname}, {mac}
</div> </div>
</div> </div>


Loading…
Cancel
Save