From 72aa161dddab0b9a293fe921b7f8e526e02ab73f Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Wed, 11 Dec 2019 10:49:57 +0100 Subject: [PATCH] Extent statistics --- tasmota/settings.ino | 41 ---------------- tasmota/support_command.ino | 2 +- tasmota/support_statistics.ino | 88 ++++++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+), 42 deletions(-) create mode 100644 tasmota/support_statistics.ino diff --git a/tasmota/settings.ino b/tasmota/settings.ino index 4768ca24b..cc6066c5a 100644 --- a/tasmota/settings.ino +++ b/tasmota/settings.ino @@ -630,47 +630,6 @@ void SettingsSdkErase(void) delay(1000); } -String SettingsCharUsage(void) -{ - uint32_t str_len = 0; - uint32_t str_size = 0; - - for (uint32_t i = 0; i < 2; i++) { - str_len += strlen(Settings.sta_ssid[i]); str_size += sizeof(Settings.sta_ssid[i]); - str_len += strlen(Settings.sta_pwd[i]); str_size += sizeof(Settings.sta_pwd[i]); - } - for (uint32_t i = 0; i < 3; i++) { - str_len += strlen(Settings.mqtt_prefix[i]); str_size += sizeof(Settings.mqtt_prefix[i]); - str_len += strlen(Settings.ntp_server[i]); str_size += sizeof(Settings.ntp_server[i]); - } - for (uint32_t i = 0; i < 4; i++) { - str_len += strlen(Settings.state_text[i]); str_size += sizeof(Settings.state_text[i]); - str_len += strlen(Settings.friendlyname[i]); str_size += sizeof(Settings.friendlyname[i]); - } - for (uint32_t i = 0; i < MAX_RULE_MEMS; i++) { - str_len += strlen(Settings.mems[i]); str_size += sizeof(Settings.mems[i]); - } - - str_len += strlen(Settings.ota_url); str_size += sizeof(Settings.ota_url); - str_len += strlen(Settings.hostname); str_size += sizeof(Settings.hostname); - str_len += strlen(Settings.syslog_host); str_size += sizeof(Settings.syslog_host); - str_len += strlen(Settings.mqtt_host); str_size += sizeof(Settings.mqtt_host); - str_len += strlen(Settings.mqtt_client); str_size += sizeof(Settings.mqtt_client); - str_len += strlen(Settings.mqtt_user); str_size += sizeof(Settings.mqtt_user); - str_len += strlen(Settings.mqtt_pwd); str_size += sizeof(Settings.mqtt_pwd); - str_len += strlen(Settings.mqtt_topic); str_size += sizeof(Settings.mqtt_topic); - str_len += strlen(Settings.button_topic); str_size += sizeof(Settings.button_topic); - str_len += strlen(Settings.switch_topic); str_size += sizeof(Settings.switch_topic); - str_len += strlen(Settings.mqtt_grptopic); str_size += sizeof(Settings.mqtt_grptopic); - str_len += strlen(Settings.web_password); str_size += sizeof(Settings.web_password); - str_len += strlen(Settings.mqtt_fulltopic); str_size += sizeof(Settings.mqtt_fulltopic); - str_len += strlen(Settings.cors_domain); str_size += sizeof(Settings.cors_domain); - - char data[30]; - snprintf_P(data, sizeof(data), PSTR(",\"CR\":\"%d/%d\""), str_len, str_size); // Char Usage Ratio - return String(data); -} - /********************************************************************************************/ void SettingsDefault(void) diff --git a/tasmota/support_command.ino b/tasmota/support_command.ino index b1c8512a4..ec8de9126 100644 --- a/tasmota/support_command.ino +++ b/tasmota/support_command.ino @@ -385,7 +385,7 @@ void CmndStatus(void) my_version, my_image, GetBuildDateAndTime().c_str(), ESP.getBootVersion(), ESP.getSdkVersion(), GetDeviceHardware().c_str(), - SettingsCharUsage().c_str()); + GetStatistics().c_str()); MqttPublishPrefixTopic_P(option, PSTR(D_CMND_STATUS "2")); } diff --git a/tasmota/support_statistics.ino b/tasmota/support_statistics.ino new file mode 100644 index 000000000..3239c5b93 --- /dev/null +++ b/tasmota/support_statistics.ino @@ -0,0 +1,88 @@ +/* + support_statistics.ino - gather statistics for Tasmota + + Copyright (C) 2019 Theo Arends + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#define USE_STATS_CODE + +#ifdef USE_STATS_CODE +/*********************************************************************************************\ + * Gather statistics +\*********************************************************************************************/ + +struct STATS { +// uint32_t str_size = 1151; // Total number of characters reserved as char array in Settings + uint32_t str_len = 0; // Total number of characters used within char array + uint32_t str_char = 0; // Total number of character '|' within all char arrays +} Stats; + +void StatisticsChar(const char* text) +{ + uint32_t len = strlen(text); + Stats.str_len += len; + for (uint32_t i = 0; i < len; i++) { + if ('|' == text[i]) { // Text string separator as currently used in GetTextIndexed() + Stats.str_char++; + } + } +} + +String GetStatistics(void) +{ + for (uint32_t i = 0; i < 2; i++) { + StatisticsChar(Settings.sta_ssid[i]); + StatisticsChar(Settings.sta_pwd[i]); + } + for (uint32_t i = 0; i < 3; i++) { + StatisticsChar(Settings.mqtt_prefix[i]); + StatisticsChar(Settings.ntp_server[i]); + } + for (uint32_t i = 0; i < 4; i++) { + StatisticsChar(Settings.state_text[i]); + StatisticsChar(Settings.friendlyname[i]); + } + for (uint32_t i = 0; i < MAX_RULE_MEMS; i++) { + StatisticsChar(Settings.mems[i]); + } + StatisticsChar(Settings.ota_url); + StatisticsChar(Settings.hostname); + StatisticsChar(Settings.syslog_host); + StatisticsChar(Settings.mqtt_host); + StatisticsChar(Settings.mqtt_client); + StatisticsChar(Settings.mqtt_user); + StatisticsChar(Settings.mqtt_pwd); + StatisticsChar(Settings.mqtt_topic); + StatisticsChar(Settings.button_topic); + StatisticsChar(Settings.switch_topic); + StatisticsChar(Settings.mqtt_grptopic); + StatisticsChar(Settings.web_password); + StatisticsChar(Settings.mqtt_fulltopic); + StatisticsChar(Settings.cors_domain); + + char data[40]; + snprintf_P(data, sizeof(data), PSTR(",\"CR\":\"%d/1151/%d\""), Stats.str_len, Stats.str_char); // Char Usage Ratio + return String(data); +} + +#else + +String GetStatistics(void) +{ + return String(""); +} + +#endif // USE_STATS_CODE \ No newline at end of file