Browse Source

Force MQTT root topic to have a trailing slash, removing it from the subtopics

fastled
Xose Pérez 7 years ago
parent
commit
9c6ae488ca
5 changed files with 84 additions and 83 deletions
  1. +16
    -16
      code/espurna/config/general.h
  2. BIN
      code/espurna/data/index.html.gz
  3. +1
    -0
      code/espurna/mqtt.ino
  4. +60
    -60
      code/espurna/static/index.html.gz.h
  5. +7
    -7
      code/html/index.html

+ 16
- 16
code/espurna/config/general.h View File

@ -146,22 +146,22 @@
#define MQTT_SKIP_RETAINED 1
#define MQTT_SKIP_TIME 1000
#define MQTT_TOPIC_ACTION "/action"
#define MQTT_TOPIC_RELAY "/relay"
#define MQTT_TOPIC_LED "/led"
#define MQTT_TOPIC_COLOR "/color"
#define MQTT_TOPIC_BUTTON "/button"
#define MQTT_TOPIC_IP "/ip"
#define MQTT_TOPIC_VERSION "/version"
#define MQTT_TOPIC_UPTIME "/uptime"
#define MQTT_TOPIC_FREEHEAP "/freeheap"
#define MQTT_TOPIC_VCC "/vcc"
#define MQTT_TOPIC_STATUS "/status"
#define MQTT_TOPIC_MAC "/mac"
#define MQTT_TOPIC_RSSI "/rssi"
#define MQTT_TOPIC_APP "/app"
#define MQTT_TOPIC_INTERVAL "/interval"
#define MQTT_TOPIC_HOSTNAME "/hostname"
#define MQTT_TOPIC_ACTION "action"
#define MQTT_TOPIC_RELAY "relay"
#define MQTT_TOPIC_LED "led"
#define MQTT_TOPIC_COLOR "color"
#define MQTT_TOPIC_BUTTON "button"
#define MQTT_TOPIC_IP "ip"
#define MQTT_TOPIC_VERSION "version"
#define MQTT_TOPIC_UPTIME "uptime"
#define MQTT_TOPIC_FREEHEAP "freeheap"
#define MQTT_TOPIC_VCC "vcc"
#define MQTT_TOPIC_STATUS "status"
#define MQTT_TOPIC_MAC "mac"
#define MQTT_TOPIC_RSSI "rssi"
#define MQTT_TOPIC_APP "app"
#define MQTT_TOPIC_INTERVAL "interval"
#define MQTT_TOPIC_HOSTNAME "hostname"
// Periodic reports
#define MQTT_REPORT_STATUS 1


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


+ 1
- 0
code/espurna/mqtt.ino View File

@ -47,6 +47,7 @@ void buildTopics() {
// Replace identifier
mqttTopic = getSetting("mqttTopic", MQTT_TOPIC);
mqttTopic.replace("{identifier}", getSetting("hostname"));
if (!mqttTopic.endsWith("/")) mqttTopic = mqttTopic + "/";
}
bool mqttForward() {


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


+ 7
- 7
code/html/index.html View File

@ -445,13 +445,13 @@
<input class="pure-u-1 pure-u-md-3-4" name="mqttTopic" type="text" size="20" tabindex="25" />
<div class="pure-u-0 pure-u-md-1-4">&nbsp;</div>
<div class="pure-u-1 pure-u-md-3-4 hint">
This is the root topic for this device. The {identifier} placeholder will be replaces by the device hostname.<br />
- <strong>&lt;root&gt;/relay/#</strong> Send a 0 or a 1 as a payload to this topic to switch it on or off. You can also send a 2 to toggle its current state. Replace # with the switch ID (starting from 0). If the board has only one switch it will be 0.<br />
- <strong>&lt;root&gt;/led/#</strong> Send a 0 or a 1 as a payload to this topic to set the onboard LED to the given state, send a 3 to turn it back to WIFI indicator. Replace # with the LED ID (starting from 0). If the board has only one LED it will be 0.<br />
- <strong>&lt;root&gt;/button/#</strong> For each button in the board subscribe to this topic to know when it is pressed (payload 1) or released (payload 0).<br />
- <strong>&lt;root&gt;/ip</strong> The device will report to this topic its IP.<br />
- <strong>&lt;root&gt;/version</strong> The device will report to this topic its firmware version on boot.<br />
- <strong>&lt;root&gt;/status</strong> The device will report a 1 to this topic every few minutes. Upon MQTT disconnecting this will be set to 0.
This is the root topic for this device. A trailing slash will be added if not preset. The {identifier} placeholder will be replaces by the device hostname.<br />
- <strong>&lt;root/&gt;relay/#</strong> Send a 0 or a 1 as a payload to this topic to switch it on or off. You can also send a 2 to toggle its current state. Replace # with the switch ID (starting from 0). If the board has only one switch it will be 0.<br />
<span class="module module-color">- <strong>&lt;root&gt;color</strong> The device will report the current color in #RRGGBB format to this topic. You can also set the color using this same topic.<br /></span>
- <strong>&lt;root/&gt;led/#</strong> Send a 0 or a 1 as a payload to this topic to set the onboard LED to the given state, send a 3 to turn it back to WIFI indicator. Replace # with the LED ID (starting from 0). If the board has only one LED it will be 0.<br />
- <strong>&lt;root/&gt;button/#</strong> For each button in the board subscribe to this topic to know when it is pressed (payload 1) or released (payload 0).<br />
- <strong>&lt;root/&gt;status</strong> The device will report a 1 to this topic every few minutes. Upon MQTT disconnecting this will be set to 0.<br />
- Other values reported (depending on the build) are: <strong>firmware</strong> and <strong>version</strong>, <strong>hostname</strong>, <strong>IP</strong>, <strong>MAC</strong>, signal strenth (<strong>RSSI</strong>), <strong>uptime</strong> (in seconds), <strong>free heap</strong> and <strong>power supply</strong>.
</div>
</div>


Loading…
Cancel
Save