mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 08:19:52 +03:00
test flash vs non-flash for json variables
This commit is contained in:
@@ -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<EMSESP_MAX_JSON_SIZE_MEDIUM> 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<JsonObject>());
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
34
src/mqtt.cpp
34
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<EMSESP_MAX_JSON_SIZE_SMALL> 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<EMSESP_MAX_JSON_SIZE_HA_CONFIG> 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");
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user