test flash vs non-flash for json variables

This commit is contained in:
proddy
2020-11-26 23:08:22 +01:00
parent 3f275121cf
commit 8447c961fe
4 changed files with 27 additions and 24 deletions

View File

@@ -342,13 +342,13 @@ void DallasSensor::publish_values(const bool force) {
if (mqtt_format_ == Mqtt::Format::HA) { if (mqtt_format_ == Mqtt::Format::HA) {
if (!(registered_ha_[sensor_no - 1]) || force) { if (!(registered_ha_[sensor_no - 1]) || force) {
StaticJsonDocument<EMSESP_MAX_JSON_SIZE_MEDIUM> config; StaticJsonDocument<EMSESP_MAX_JSON_SIZE_MEDIUM> config;
config["dev_cla"] = F("temperature"); config["dev_cla"] = FJSON("temperature");
char stat_t[50]; char stat_t[50];
snprintf_P(stat_t, sizeof(stat_t), PSTR("%s/dallassensor_data"), System::hostname().c_str()); snprintf_P(stat_t, sizeof(stat_t), PSTR("%s/dallassensor_data"), System::hostname().c_str());
config["stat_t"] = stat_t; config["stat_t"] = stat_t;
config["unit_of_meas"] = F("°C"); config["unit_of_meas"] = FJSON("°C");
char str[50]; char str[50];
snprintf_P(str, sizeof(str), PSTR("{{value_json.sensor%d.temp}}"), sensor_no); 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 sensor_no++; // increment sensor count
} }
doc.shrinkToFit(); // doc.shrinkToFit();
Mqtt::publish(F("dallassensor_data"), doc.as<JsonObject>()); Mqtt::publish(F("dallassensor_data"), doc.as<JsonObject>());
} }

View File

@@ -28,6 +28,9 @@
#define BOOL_FORMAT_TRUEFALSE 2 #define BOOL_FORMAT_TRUEFALSE 2
#define BOOL_FORMAT_NUMBERS 3 #define BOOL_FORMAT_NUMBERS 3
// #define FJSON(x) x
#define FJSON(x) F(x)
namespace emsesp { namespace emsesp {
class Helpers { class Helpers {

View File

@@ -476,7 +476,7 @@ void Mqtt::on_connect() {
if (connectcount_ == 1) { if (connectcount_ == 1) {
// send info topic appended with the version information as JSON // send info topic appended with the version information as JSON
StaticJsonDocument<EMSESP_MAX_JSON_SIZE_SMALL> doc; StaticJsonDocument<EMSESP_MAX_JSON_SIZE_SMALL> doc;
doc["event"] = "start"; doc["event"] = FJSON("start");
doc["version"] = EMSESP_APP_VERSION; doc["version"] = EMSESP_APP_VERSION;
#ifndef EMSESP_STANDALONE #ifndef EMSESP_STANDALONE
doc["ip"] = WiFi.localIP().toString(); doc["ip"] = WiFi.localIP().toString();
@@ -505,20 +505,20 @@ void Mqtt::on_connect() {
void Mqtt::ha_status() { void Mqtt::ha_status() {
StaticJsonDocument<EMSESP_MAX_JSON_SIZE_HA_CONFIG> doc; StaticJsonDocument<EMSESP_MAX_JSON_SIZE_HA_CONFIG> doc;
doc["name"] = F("EMS-ESP status"); doc["name"] = FJSON("EMS-ESP status");
doc["uniq_id"] = F("status"); doc["uniq_id"] = FJSON("status");
doc["~"] = System::hostname(); // ems-esp doc["~"] = System::hostname(); // ems-esp
doc["avty_t"] = F("~/status"); doc["avty_t"] = FJSON("~/status");
doc["json_attr_t"] = F("~/heartbeat"); doc["json_attr_t"] = FJSON("~/heartbeat");
doc["stat_t"] = F("~/heartbeat"); doc["stat_t"] = FJSON("~/heartbeat");
doc["val_tpl"] = F("{{value_json['status']}}"); doc["val_tpl"] = FJSON("{{value_json['status']}}");
doc["ic"] = F("mdi:home-thermometer-outline"); doc["ic"] = FJSON("mdi:home-thermometer-outline");
JsonObject dev = doc.createNestedObject("dev"); JsonObject dev = doc.createNestedObject("dev");
dev["name"] = F("EMS-ESP"); dev["name"] = FJSON("EMS-ESP");
dev["sw"] = EMSESP_APP_VERSION; dev["sw"] = EMSESP_APP_VERSION;
dev["mf"] = F("proddy"); dev["mf"] = FJSON("proddy");
dev["mdl"] = F("EMS-ESP"); dev["mdl"] = FJSON("EMS-ESP");
JsonArray ids = dev.createNestedArray("ids"); JsonArray ids = dev.createNestedArray("ids");
ids.add("ems-esp"); ids.add("ems-esp");
@@ -706,14 +706,14 @@ void Mqtt::register_mqtt_ha_binary_sensor(const __FlashStringHelper * name, cons
EMSESP::webSettingsService.read([&](WebSettings & settings) { EMSESP::webSettingsService.read([&](WebSettings & settings) {
if (settings.bool_format == BOOL_FORMAT_ONOFF) { if (settings.bool_format == BOOL_FORMAT_ONOFF) {
doc[F("payload_on")] = "on"; doc[F("payload_on")] = FJSON("on");
doc[F("payload_off")] = "off"; doc[F("payload_off")] = FJSON("off");
} else if (settings.bool_format == BOOL_FORMAT_TRUEFALSE) { } else if (settings.bool_format == BOOL_FORMAT_TRUEFALSE) {
doc[F("payload_on")] = "true"; doc[F("payload_on")] = FJSON("true");
doc[F("payload_off")] = "false"; doc[F("payload_off")] = FJSON("false");
} else { } else {
doc[F("payload_on")] = "1"; doc[F("payload_on")] = FJSON("1");
doc[F("payload_off")] = "0"; doc[F("payload_off")] = FJSON("0");
} }
}); });

View File

@@ -308,7 +308,7 @@ void System::show_mem(const char * note) {
// send periodic MQTT message with system information // send periodic MQTT message with system information
void System::send_heartbeat() { void System::send_heartbeat() {
// don't send heartbeat if WiFi is not connected // don't send heartbeat if WiFi is not connected
int rssi = wifi_quality(); int8_t rssi = wifi_quality();
if (rssi == -1) { if (rssi == -1) {
return; return;
} }
@@ -323,11 +323,11 @@ void System::send_heartbeat() {
uint8_t ems_status = EMSESP::bus_status(); uint8_t ems_status = EMSESP::bus_status();
if (ems_status == EMSESP::BUS_STATUS_TX_ERRORS) { if (ems_status == EMSESP::BUS_STATUS_TX_ERRORS) {
doc["status"] = "txerror"; doc["status"] = FJSON("txerror");
} else if (ems_status == EMSESP::BUS_STATUS_CONNECTED) { } else if (ems_status == EMSESP::BUS_STATUS_CONNECTED) {
doc["status"] = "connected"; doc["status"] = FJSON("connected");
} else { } else {
doc["status"] = "disconnected"; doc["status"] = FJSON("disconnected");
} }
doc["rssi"] = rssi; doc["rssi"] = rssi;