From 66233b1749b3c847342befbba3583689f1ad12d2 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Tue, 26 May 2020 17:08:13 +0200 Subject: [PATCH] Add support for full MAC address Add support for unique MQTTClient (and inherited fallback topic) by full Mac address using ``mqttclient DVES_%12X`` (#8300) --- RELEASENOTES.md | 1 + tasmota/CHANGELOG.md | 1 + tasmota/my_user_config.h | 6 +++--- tasmota/support_tasmota.ino | 9 ++++++--- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 2ac283ffb..7fb0366a3 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -62,6 +62,7 @@ The following binary downloads have been compiled with ESP8266/Arduino library c - Add command ``Rule0`` to change global rule parameters - Add command ``Time 4`` to display timestamp using milliseconds (#8537) - Add commands ``LedPwmOn 0..255``, ``LedPwmOff 0..255`` and ``LedPwmMode1 0/1`` to control led brightness by George (#8491) +- Add support for unique MQTTClient (and inherited fallback topic) by full Mac address using ``mqttclient DVES_%12X`` (#8300) - Add more functionality to ``Switchmode`` 11 and 12 (#8450) - Add wildcard pattern ``?`` for JSON matching in rules - Add support for VEML6075 UVA/UVB/UVINDEX Sensor by device111 (#8432) diff --git a/tasmota/CHANGELOG.md b/tasmota/CHANGELOG.md index c7a2866a7..487c94e64 100644 --- a/tasmota/CHANGELOG.md +++ b/tasmota/CHANGELOG.md @@ -10,6 +10,7 @@ - Add commands ``LedPwmOn 0..255``, ``LedPwmOff 0..255`` and ``LedPwmMode1 0/1`` to control led brightness by George (#8491) - Add Three Phase Export Active Energy to SDM630 driver - Add wildcard pattern ``?`` for JSON matching in rules +- Add support for unique MQTTClient (and inherited fallback topic) by full Mac address using ``mqttclient DVES_%12X`` (#8300) ### 8.3.1.1 20200518 diff --git a/tasmota/my_user_config.h b/tasmota/my_user_config.h index 1a65eb571..46d88e0d7 100644 --- a/tasmota/my_user_config.h +++ b/tasmota/my_user_config.h @@ -118,12 +118,12 @@ #define PUB_PREFIX2 "tele" // [Prefix3] Tasmota devices publish telemetry data to %prefix%/%topic% being PUB_PREFIX2/MQTT_TOPIC/UPTIME, POWER and TIME // May be named the same as PUB_PREFIX // %topic% token options (also ButtonTopic and SwitchTopic) -#define MQTT_TOPIC PROJECT "_%06X" // [Topic] unique MQTT device topic including device MAC address +#define MQTT_TOPIC PROJECT "_%06X" // [Topic] unique MQTT device topic including (part of) device MAC address #define MQTT_GRPTOPIC "tasmotas" // [GroupTopic] MQTT Group topic #define MQTT_GROUPTOPIC_FORMAT false // [SetOption75] GroupTopic replaces %topic% (false) or fixed topic cmnd/grouptopic (true) #define MQTT_BUTTON_TOPIC "0" // [ButtonTopic] MQTT button topic, "0" = same as MQTT_TOPIC, set to 'PROJECT "_BTN_%06X"' for unique topic including device MAC address #define MQTT_SWITCH_TOPIC "0" // [SwitchTopic] MQTT button topic, "0" = same as MQTT_TOPIC, set to 'PROJECT "_SW_%06X"' for unique topic including device MAC address -#define MQTT_CLIENT_ID "DVES_%06X" // [MqttClient] Also fall back topic using Chip Id = last 6 characters of MAC address +#define MQTT_CLIENT_ID "DVES_%06X" // [MqttClient] Also fall back topic using last 6 characters of MAC address or use "DVES_%12X" for complete MAC address // -- MQTT - Telemetry ---------------------------- #define TELE_PERIOD 300 // [TelePeriod] Telemetry (0 = disable, 10 - 3600 seconds) @@ -648,7 +648,7 @@ #define USE_ZIGBEE_CHANNEL 11 // Zigbee Channel (11-26) #define USE_ZIGBEE_PRECFGKEY_L 0x0F0D0B0907050301L // note: changing requires to re-pair all devices #define USE_ZIGBEE_PRECFGKEY_H 0x0D0C0A0806040200L // note: changing requires to re-pair all devices - + #define USE_ZIGBEE_COALESCE_ATTR_TIMER 350 // timer to coalesce attribute values (in ms) // -- Other sensors/drivers ----------------------- diff --git a/tasmota/support_tasmota.ino b/tasmota/support_tasmota.ino index a3271131b..03848bf0d 100644 --- a/tasmota/support_tasmota.ino +++ b/tasmota/support_tasmota.ino @@ -41,12 +41,15 @@ char* Format(char* output, const char* input, int size) snprintf_P(tmp, size, PSTR("%s%c0%dd"), output, '%', digits); snprintf_P(output, size, tmp, ESP_getChipId() & 0x1fff); // %04d - short chip ID in dec, like in hostname } else { - snprintf_P(tmp, size, PSTR("%s%c0%dX"), output, '%', digits); - snprintf_P(output, size, tmp, ESP_getChipId()); // %06X - full chip ID in hex + String mac_address = WiFi.macAddress(); + mac_address.replace(":", ""); + if (digits > 12) { digits = 12; } + String mac_part = mac_address.substring(12 - digits); + snprintf_P(output, size, PSTR("%s%s"), output, mac_part.c_str()); // %01X .. %12X - mac address in hex } } else { if (strchr(token, 'd')) { - snprintf_P(output, size, PSTR("%s%d"), output, ESP_getChipId()); // %d - full chip ID in dec + snprintf_P(output, size, PSTR("%s%d"), output, ESP_getChipId()); // %d - full chip ID in dec digits = 8; } }