external sensor MQTT format - #327

This commit is contained in:
Paul
2020-02-18 16:06:24 +01:00
parent fe63fb3fc5
commit 2fa34c369f
4 changed files with 33 additions and 29 deletions

View File

@@ -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) - First implementation of writing to Junker Thermostats (thanks @Neonox31)
- Added model type (Buderus, Sieger, Junkers, Nefit, Bosch, Worcester) to device names - Added model type (Buderus, Sieger, Junkers, Nefit, Bosch, Worcester) to device names
- `boiler wwonetime` command from Telnet - `boiler wwonetime` command from Telnet
- `set bus_id <ID>` to support multiple EMS-ESP circuits. Default is 0x0B to mimic a service key.
### Fixed ### Fixed
- set boiler warm water temp on Junkers/Bosch HT3 - 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 ### Changed
- improved MQTT publishing to stop flooding. `publish_time` must be at least 1 (second) - 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 ### Removed
- `autodetect scan` - `autodetect scan`

View File

@@ -410,14 +410,16 @@ void MyESP::mqttUnsubscribe(const char * topic) {
// Publish using the user's custom retain flag // Publish using the user's custom retain flag
bool MyESP::mqttPublish(const char * topic, const char * payload) { bool MyESP::mqttPublish(const char * topic, const char * payload) {
// use the custom MQTT retain flag
return mqttPublish(topic, payload, _mqtt_retain); return mqttPublish(topic, payload, _mqtt_retain);
} }
// MQTT Publish // MQTT Publish
// returns true if all good // returns true if all good
bool MyESP::mqttPublish(const char * topic, const char * payload, bool retain) { 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 #ifdef MYESP_DEBUG
myDebug_P(PSTR("[MQTT] Sending publish to %s with payload %s"), _mqttTopic(topic), payload); myDebug_P(PSTR("[MQTT] Sending publish to %s with payload %s"), _mqttTopic(topic), payload);
#endif #endif
@@ -428,18 +430,9 @@ bool MyESP::mqttPublish(const char * topic, const char * payload, bool retain) {
return true; return true;
} }
// it failed, try again https://github.com/proddy/EMS-ESP/issues/264 // it failed, we should 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
myDebug_P(PSTR("[MQTT] Error publishing to %s with payload %s [error %d]"), _mqttTopic(topic), payload, packet_id); myDebug_P(PSTR("[MQTT] Error publishing to %s with payload %s [error %d]"), _mqttTopic(topic), payload, packet_id);
_mqtt_publish_fails++; // increment failure counter _mqtt_publish_fails++; // increment failure counter
}
return false; // failed return false; // failed
} }
@@ -1065,8 +1058,7 @@ void MyESP::_telnetCommand(char * commandLine) {
// save everything // save everything
if ((strcmp(ptrToCommandName, "save") == 0) && (wc == 1)) { if ((strcmp(ptrToCommandName, "save") == 0) && (wc == 1)) {
_fs_writeConfig(); saveSettings();
_fs_createCustomConfig();
return; 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 // returns WiFi hostname as a String object
String MyESP::_getESPhostname() { String MyESP::_getESPhostname() {
String hostname; String hostname;

View File

@@ -9,7 +9,7 @@
#ifndef MyESP_h #ifndef MyESP_h
#define MyESP_h #define MyESP_h
#define MYESP_VERSION "1.2.26" #define MYESP_VERSION "1.2.27"
#include <ArduinoJson.h> #include <ArduinoJson.h>
#include <ArduinoOTA.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) #define MYESP_HEARTBEAT_INTERVAL 120000 // in milliseconds, how often the MQTT heartbeat is sent (2 mins)
typedef struct { typedef struct {
bool set; // is it a set command bool set; // is it a set command?
char key[50]; char key[50];
char description[100]; char description[110];
} command_t; } command_t;
typedef enum { MYESP_FSACTION_SET, MYESP_FSACTION_LIST, MYESP_FSACTION_SAVE, MYESP_FSACTION_LOAD } MYESP_FSACTION_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 // FS
void setSettings(fs_loadsave_callback_f loadsave, fs_setlist_callback_f setlist, bool useSerial = true); void setSettings(fs_loadsave_callback_f loadsave, fs_setlist_callback_f setlist, bool useSerial = true);
void saveSettings();
bool fs_saveConfig(JsonObject root); bool fs_saveConfig(JsonObject root);
bool fs_saveCustomConfig(JsonObject root); bool fs_saveCustomConfig(JsonObject root);
bool fs_setSettingValue(char ** setting, const char * value, const char * value_default); bool fs_setSettingValue(char ** setting, const char * value, const char * value_default);

View File

@@ -82,4 +82,7 @@
#define TOPIC_SHOWER_DURATION "duration" // duration of the last shower #define TOPIC_SHOWER_DURATION "duration" // duration of the last shower
// MQTT for External Sensors // 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"