From b525e5c72021d22fa6380a7b519eec178e31ee0d Mon Sep 17 00:00:00 2001 From: Stephan Hadinger Date: Sun, 18 Oct 2020 20:06:27 +0200 Subject: [PATCH] Reduce code size for fingerprint --- tasmota/my_user_config.h | 4 ++-- tasmota/settings.ino | 15 ++++----------- tasmota/tasmota_globals.h | 4 ++-- 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/tasmota/my_user_config.h b/tasmota/my_user_config.h index 39b946b66..8a490787e 100644 --- a/tasmota/my_user_config.h +++ b/tasmota/my_user_config.h @@ -97,8 +97,8 @@ #define MQTT_USE true // [SetOption3] Select default MQTT use (false = Off, true = On) #define MQTT_HOST "" // [MqttHost] -#define MQTT_FINGERPRINT1 "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00" // [MqttFingerprint1] (auto-learn) -#define MQTT_FINGERPRINT2 "DA 39 A3 EE 5E 6B 4B 0D 32 55 BF EF 95 60 18 90 AF D8 07 09" // [MqttFingerprint2] (invalid) +#define MQTT_FINGERPRINT1 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 // [MqttFingerprint1] (auto-learn) +#define MQTT_FINGERPRINT2 0xDA,0x39,0xA3,0xEE,0x5E,0x6B,0x4B,0x0D,0x32,0x55,0xBF,0xEF,0x95,0x60,0x18,0x90,0xAF,0xD8,0x07,0x09 // [MqttFingerprint2] (invalid) #define MQTT_PORT 1883 // [MqttPort] MQTT port (10123 on CloudMQTT) #define MQTT_USER "DVES_USER" // [MqttUser] MQTT user #define MQTT_PASS "DVES_PASS" // [MqttPassword] MQTT password diff --git a/tasmota/settings.ino b/tasmota/settings.ino index ca0f239ef..18a6f25e8 100644 --- a/tasmota/settings.ino +++ b/tasmota/settings.ino @@ -874,17 +874,10 @@ void SettingsDefaultSet2(void) SettingsUpdateText(SET_STATE_TXT2, MQTT_STATUS_ON); SettingsUpdateText(SET_STATE_TXT3, MQTT_CMND_TOGGLE); SettingsUpdateText(SET_STATE_TXT4, MQTT_CMND_HOLD); - char fingerprint[64]; - strncpy_P(fingerprint, PSTR(MQTT_FINGERPRINT1), sizeof(fingerprint)); - char *p = fingerprint; - for (uint32_t i = 0; i < 20; i++) { - Settings.mqtt_fingerprint[0][i] = strtol(p, &p, 16); - } - strncpy_P(fingerprint, PSTR(MQTT_FINGERPRINT2), sizeof(fingerprint)); - p = fingerprint; - for (uint32_t i = 0; i < 20; i++) { - Settings.mqtt_fingerprint[1][i] = strtol(p, &p, 16); - } + static const uint8_t fingerprint1[] PROGMEM = { MQTT_FINGERPRINT1 }; + static const uint8_t fingerprint2[] PROGMEM = { MQTT_FINGERPRINT2 }; + memcpy_P(Settings.mqtt_fingerprint[0], fingerprint1, sizeof(fingerprint1)); + memcpy_P(Settings.mqtt_fingerprint[1], fingerprint2, sizeof(fingerprint2)); Settings.tele_period = TELE_PERIOD; Settings.mqttlog_level = MQTT_LOG_LEVEL; diff --git a/tasmota/tasmota_globals.h b/tasmota/tasmota_globals.h index f639694fd..b5343af80 100644 --- a/tasmota/tasmota_globals.h +++ b/tasmota/tasmota_globals.h @@ -112,10 +112,10 @@ String EthernetMacAddress(void); #ifndef MQTT_FINGERPRINT1 // Set an all-zeros default fingerprint to activate auto-learning on first connection (AWS IoT) -#define MQTT_FINGERPRINT1 "00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00" +#define MQTT_FINGERPRINT1 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 // [MqttFingerprint1] (auto-learn) #endif #ifndef MQTT_FINGERPRINT2 // SHA1('') -#define MQTT_FINGERPRINT2 "DA 39 A3 EE 5E 6B 4B 0D 32 55 BF EF 95 60 18 90 AF D8 07 09" +#define MQTT_FINGERPRINT2 0xDA,0x39,0xA3,0xEE,0x5E,0x6B,0x4B,0x0D,0x32,0x55,0xBF,0xEF,0x95,0x60,0x18,0x90,0xAF,0xD8,0x07,0x09 // [MqttFingerprint2] (invalid) #endif #ifndef WS2812_LEDS