From 8447c961febb122778d03896671f5019085701a1 Mon Sep 17 00:00:00 2001 From: proddy Date: Thu, 26 Nov 2020 23:08:22 +0100 Subject: [PATCH] test flash vs non-flash for json variables --- src/dallassensor.cpp | 6 +++--- src/helpers.h | 3 +++ src/mqtt.cpp | 34 +++++++++++++++++----------------- src/system.cpp | 8 ++++---- 4 files changed, 27 insertions(+), 24 deletions(-) diff --git a/src/dallassensor.cpp b/src/dallassensor.cpp index 741c22101..68fe8824e 100644 --- a/src/dallassensor.cpp +++ b/src/dallassensor.cpp @@ -342,13 +342,13 @@ void DallasSensor::publish_values(const bool force) { if (mqtt_format_ == Mqtt::Format::HA) { if (!(registered_ha_[sensor_no - 1]) || force) { StaticJsonDocument config; - config["dev_cla"] = F("temperature"); + config["dev_cla"] = FJSON("temperature"); char stat_t[50]; snprintf_P(stat_t, sizeof(stat_t), PSTR("%s/dallassensor_data"), System::hostname().c_str()); config["stat_t"] = stat_t; - config["unit_of_meas"] = F("°C"); + config["unit_of_meas"] = FJSON("°C"); char str[50]; snprintf_P(str, sizeof(str), PSTR("{{value_json.sensor%d.temp}}"), sensor_no); @@ -375,7 +375,7 @@ void DallasSensor::publish_values(const bool force) { sensor_no++; // increment sensor count } - doc.shrinkToFit(); + // doc.shrinkToFit(); Mqtt::publish(F("dallassensor_data"), doc.as()); } diff --git a/src/helpers.h b/src/helpers.h index b20c3771c..0c50c5034 100644 --- a/src/helpers.h +++ b/src/helpers.h @@ -28,6 +28,9 @@ #define BOOL_FORMAT_TRUEFALSE 2 #define BOOL_FORMAT_NUMBERS 3 +// #define FJSON(x) x +#define FJSON(x) F(x) + namespace emsesp { class Helpers { diff --git a/src/mqtt.cpp b/src/mqtt.cpp index b18a7052b..62ab7fd58 100644 --- a/src/mqtt.cpp +++ b/src/mqtt.cpp @@ -476,7 +476,7 @@ void Mqtt::on_connect() { if (connectcount_ == 1) { // send info topic appended with the version information as JSON StaticJsonDocument doc; - doc["event"] = "start"; + doc["event"] = FJSON("start"); doc["version"] = EMSESP_APP_VERSION; #ifndef EMSESP_STANDALONE doc["ip"] = WiFi.localIP().toString(); @@ -505,20 +505,20 @@ void Mqtt::on_connect() { void Mqtt::ha_status() { StaticJsonDocument doc; - doc["name"] = F("EMS-ESP status"); - doc["uniq_id"] = F("status"); + doc["name"] = FJSON("EMS-ESP status"); + doc["uniq_id"] = FJSON("status"); doc["~"] = System::hostname(); // ems-esp - doc["avty_t"] = F("~/status"); - doc["json_attr_t"] = F("~/heartbeat"); - doc["stat_t"] = F("~/heartbeat"); - doc["val_tpl"] = F("{{value_json['status']}}"); - doc["ic"] = F("mdi:home-thermometer-outline"); + doc["avty_t"] = FJSON("~/status"); + doc["json_attr_t"] = FJSON("~/heartbeat"); + doc["stat_t"] = FJSON("~/heartbeat"); + doc["val_tpl"] = FJSON("{{value_json['status']}}"); + doc["ic"] = FJSON("mdi:home-thermometer-outline"); JsonObject dev = doc.createNestedObject("dev"); - dev["name"] = F("EMS-ESP"); + dev["name"] = FJSON("EMS-ESP"); dev["sw"] = EMSESP_APP_VERSION; - dev["mf"] = F("proddy"); - dev["mdl"] = F("EMS-ESP"); + dev["mf"] = FJSON("proddy"); + dev["mdl"] = FJSON("EMS-ESP"); JsonArray ids = dev.createNestedArray("ids"); ids.add("ems-esp"); @@ -706,14 +706,14 @@ void Mqtt::register_mqtt_ha_binary_sensor(const __FlashStringHelper * name, cons EMSESP::webSettingsService.read([&](WebSettings & settings) { if (settings.bool_format == BOOL_FORMAT_ONOFF) { - doc[F("payload_on")] = "on"; - doc[F("payload_off")] = "off"; + doc[F("payload_on")] = FJSON("on"); + doc[F("payload_off")] = FJSON("off"); } else if (settings.bool_format == BOOL_FORMAT_TRUEFALSE) { - doc[F("payload_on")] = "true"; - doc[F("payload_off")] = "false"; + doc[F("payload_on")] = FJSON("true"); + doc[F("payload_off")] = FJSON("false"); } else { - doc[F("payload_on")] = "1"; - doc[F("payload_off")] = "0"; + doc[F("payload_on")] = FJSON("1"); + doc[F("payload_off")] = FJSON("0"); } }); diff --git a/src/system.cpp b/src/system.cpp index f6a35a64e..bd5418d09 100644 --- a/src/system.cpp +++ b/src/system.cpp @@ -308,7 +308,7 @@ void System::show_mem(const char * note) { // send periodic MQTT message with system information void System::send_heartbeat() { // don't send heartbeat if WiFi is not connected - int rssi = wifi_quality(); + int8_t rssi = wifi_quality(); if (rssi == -1) { return; } @@ -323,11 +323,11 @@ void System::send_heartbeat() { uint8_t ems_status = EMSESP::bus_status(); if (ems_status == EMSESP::BUS_STATUS_TX_ERRORS) { - doc["status"] = "txerror"; + doc["status"] = FJSON("txerror"); } else if (ems_status == EMSESP::BUS_STATUS_CONNECTED) { - doc["status"] = "connected"; + doc["status"] = FJSON("connected"); } else { - doc["status"] = "disconnected"; + doc["status"] = FJSON("disconnected"); } doc["rssi"] = rssi;