mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 08:19:52 +03:00
external sensor MQTT format - #327
This commit is contained in:
@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
- First implementation of writing to Junker Thermostats (thanks @Neonox31)
|
||||
- Added model type (Buderus, Sieger, Junkers, Nefit, Bosch, Worcester) to device names
|
||||
- `boiler wwonetime` command from Telnet
|
||||
- `set bus_id <ID>` to support multiple EMS-ESP circuits. Default is 0x0B to mimic a service key.
|
||||
|
||||
### Fixed
|
||||
- set boiler warm water temp on Junkers/Bosch HT3
|
||||
@@ -23,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
### Changed
|
||||
- improved MQTT publishing to stop flooding. `publish_time` must be at least 1 (second)
|
||||
- External sensors (like dallas) are sent as a nested MQTT topic including their unqiue identifier
|
||||
|
||||
### Removed
|
||||
- `autodetect scan`
|
||||
|
||||
@@ -410,14 +410,16 @@ void MyESP::mqttUnsubscribe(const char * topic) {
|
||||
|
||||
// Publish using the user's custom retain flag
|
||||
bool MyESP::mqttPublish(const char * topic, const char * payload) {
|
||||
// use the custom MQTT retain flag
|
||||
return mqttPublish(topic, payload, _mqtt_retain);
|
||||
}
|
||||
|
||||
// MQTT Publish
|
||||
// returns true if all good
|
||||
bool MyESP::mqttPublish(const char * topic, const char * payload, bool retain) {
|
||||
if (mqttClient.connected() && (strlen(topic) > 0)) {
|
||||
if (!mqttClient.connected() || !_hasValue(topic) || !_hasValue(payload)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef MYESP_DEBUG
|
||||
myDebug_P(PSTR("[MQTT] Sending publish to %s with payload %s"), _mqttTopic(topic), payload);
|
||||
#endif
|
||||
@@ -428,18 +430,9 @@ bool MyESP::mqttPublish(const char * topic, const char * payload, bool retain) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// it failed, try again https://github.com/proddy/EMS-ESP/issues/264
|
||||
delay(100); // this is blocking and probably not a good idea
|
||||
packet_id = mqttClient.publish(_mqttTopic(topic), _mqtt_qos, retain, payload);
|
||||
if (packet_id) {
|
||||
_addMQTTLog(topic, payload, MYESP_MQTTLOGTYPE_PUBLISH); // add to the log
|
||||
return true; // ok this time
|
||||
}
|
||||
|
||||
// it didn't work again, will return false
|
||||
// it failed, we should try again https://github.com/proddy/EMS-ESP/issues/264
|
||||
myDebug_P(PSTR("[MQTT] Error publishing to %s with payload %s [error %d]"), _mqttTopic(topic), payload, packet_id);
|
||||
_mqtt_publish_fails++; // increment failure counter
|
||||
}
|
||||
|
||||
return false; // failed
|
||||
}
|
||||
@@ -1065,8 +1058,7 @@ void MyESP::_telnetCommand(char * commandLine) {
|
||||
|
||||
// save everything
|
||||
if ((strcmp(ptrToCommandName, "save") == 0) && (wc == 1)) {
|
||||
_fs_writeConfig();
|
||||
_fs_createCustomConfig();
|
||||
saveSettings();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1098,6 +1090,12 @@ void MyESP::_telnetCommand(char * commandLine) {
|
||||
}
|
||||
}
|
||||
|
||||
// public function so clients can save config
|
||||
void MyESP::saveSettings() {
|
||||
_fs_writeConfig();
|
||||
_fs_createCustomConfig();
|
||||
}
|
||||
|
||||
// returns WiFi hostname as a String object
|
||||
String MyESP::_getESPhostname() {
|
||||
String hostname;
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#ifndef MyESP_h
|
||||
#define MyESP_h
|
||||
|
||||
#define MYESP_VERSION "1.2.26"
|
||||
#define MYESP_VERSION "1.2.27"
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <ArduinoOTA.h>
|
||||
@@ -215,9 +215,9 @@ static_assert(sizeof(RtcmemData) <= (RTCMEM_BLOCKS * 4u), "RTCMEM struct is too
|
||||
#define MYESP_HEARTBEAT_INTERVAL 120000 // in milliseconds, how often the MQTT heartbeat is sent (2 mins)
|
||||
|
||||
typedef struct {
|
||||
bool set; // is it a set command
|
||||
bool set; // is it a set command?
|
||||
char key[50];
|
||||
char description[100];
|
||||
char description[110];
|
||||
} command_t;
|
||||
|
||||
typedef enum { MYESP_FSACTION_SET, MYESP_FSACTION_LIST, MYESP_FSACTION_SAVE, MYESP_FSACTION_LOAD } MYESP_FSACTION_t;
|
||||
@@ -302,6 +302,7 @@ class MyESP {
|
||||
|
||||
// FS
|
||||
void setSettings(fs_loadsave_callback_f loadsave, fs_setlist_callback_f setlist, bool useSerial = true);
|
||||
void saveSettings();
|
||||
bool fs_saveConfig(JsonObject root);
|
||||
bool fs_saveCustomConfig(JsonObject root);
|
||||
bool fs_setSettingValue(char ** setting, const char * value, const char * value_default);
|
||||
|
||||
@@ -82,4 +82,7 @@
|
||||
#define TOPIC_SHOWER_DURATION "duration" // duration of the last shower
|
||||
|
||||
// MQTT for External Sensors
|
||||
#define TOPIC_EXTERNAL_SENSORS "sensors" // for sending sensor values to MQTT
|
||||
#define TOPIC_EXTERNAL_SENSORS "sensors" // topic for sending sensor values to MQTT
|
||||
#define PAYLOAD_EXTERNAL_SENSOR_NUM "sensor" // which sensor #
|
||||
#define PAYLOAD_EXTERNAL_SENSOR_ID "id"
|
||||
#define PAYLOAD_EXTERNAL_SENSOR_TEMP "temp"
|
||||
|
||||
Reference in New Issue
Block a user