Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MQTT] Controller improvements #4770

Open
wants to merge 46 commits into
base: mega
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
7f4fa7b
[MQTT] Controller improvements
tonhuisman Aug 18, 2023
7fa8319
Merge branch 'mega' of https://github.com/letscontrolit/ESPEasy into …
tonhuisman Aug 26, 2023
70a99eb
Merge branch 'mega' of https://github.com/letscontrolit/ESPEasy into …
tonhuisman Aug 31, 2023
1f2b98f
Merge branch 'mega' into feature/MQTT-controller-cmd-improvements
tonhuisman Sep 6, 2023
7528480
Merge branch 'feature/MQTT-controller-cmd-improvements' of https://gi…
tonhuisman Sep 6, 2023
8765c20
Merge branch 'mega' into feature/MQTT-controller-cmd-improvements
tonhuisman Sep 9, 2023
b5161be
Merge branch 'feature/MQTT-controller-cmd-improvements' of https://gi…
tonhuisman Sep 10, 2023
1839456
[P086] Format source using uncrustify
tonhuisman Sep 10, 2023
df0fb7a
[MQTT] Add support for P086 events to all MQTT Controllers
tonhuisman Sep 16, 2023
95236d3
[MQTT] Only handle plugin if plugin included
tonhuisman Sep 16, 2023
8a9dfa6
Merge branch 'mega' into feature/MQTT-controller-cmd-improvements
tonhuisman Sep 19, 2023
5a377a6
Merge branch 'mega' of https://github.com/letscontrolit/ESPEasy into …
tonhuisman Sep 29, 2023
c46a8f4
Merge branch 'mega' into feature/MQTT-controller-cmd-improvements
tonhuisman Oct 4, 2023
05d99fa
Merge branch 'mega' of https://github.com/letscontrolit/ESPEasy into …
tonhuisman Oct 11, 2023
7b85651
Merge branch 'mega' of https://github.com/letscontrolit/ESPEasy into …
tonhuisman Oct 30, 2023
92a50d1
[C014] Use getHostname() for %sysname%, some code optimization
tonhuisman Oct 30, 2023
2de6997
Merge branch 'mega' of https://github.com/letscontrolit/ESPEasy into …
tonhuisman Feb 16, 2024
16c31cf
Merge branch 'mega' into feature/MQTT-controller-cmd-improvements
tonhuisman Mar 2, 2024
4dea3a1
[C014] Process %sysname% via parseSystemVariables(), logging improvem…
tonhuisman Mar 2, 2024
175ee1e
Merge branch 'mega' of https://github.com/letscontrolit/ESPEasy into …
tonhuisman Mar 24, 2024
8991cf1
Merge branch 'mega' into feature/MQTT-controller-cmd-improvements
TD-er Mar 30, 2024
d950e53
Merge branch 'feature/MQTT-controller-cmd-improvements' of https://gi…
tonhuisman Mar 30, 2024
4dea9b9
Merge branch 'mega' into feature/MQTT-controller-cmd-improvements
TD-er May 1, 2024
dc07fd9
Merge branch 'mega' into feature/MQTT-controller-cmd-improvements
tonhuisman May 8, 2024
d4c6828
Merge branch 'mega' into feature/MQTT-controller-cmd-improvements
tonhuisman May 24, 2024
05c2de5
Merge branch 'feature/MQTT-controller-cmd-improvements' of https://gi…
tonhuisman May 24, 2024
d944777
[Controllers] Minor improvements and corrections
tonhuisman May 24, 2024
4bb1d38
[C004] Some string optimization
tonhuisman May 29, 2024
4886924
[C004] Add documentation and examples
tonhuisman May 29, 2024
8dd13be
Merge branch 'mega' of https://github.com/letscontrolit/ESPEasy into …
tonhuisman May 29, 2024
ec36a96
Merge branch 'mega' of https://github.com/letscontrolit/ESPEasy into …
tonhuisman May 31, 2024
e3fac16
Merge branch 'mega' of https://github.com/letscontrolit/ESPEasy into …
tonhuisman Jun 22, 2024
671916e
[C007] Emoncms: add configurable url (Controller Publish)
tonhuisman Jun 22, 2024
307bea9
Merge branch 'mega' of https://github.com/letscontrolit/ESPEasy into …
tonhuisman Jul 5, 2024
60af4a6
[Coo4] Fix merge conflict issue
tonhuisman Jul 5, 2024
ecba48b
Merge branch 'mega' into feature/MQTT-controller-cmd-improvements
tonhuisman Jul 28, 2024
d57db07
Merge branch 'mega' of https://github.com/letscontrolit/ESPEasy into …
tonhuisman Sep 25, 2024
bc7d41d
Merge branch 'mega' of https://github.com/letscontrolit/ESPEasy into …
tonhuisman Sep 27, 2024
e6b2df3
Merge branch 'mega' into feature/MQTT-controller-cmd-improvements
TD-er Oct 2, 2024
7047020
Merge branch 'mega' into feature/MQTT-controller-cmd-improvements
TD-er Oct 3, 2024
1050b7f
Merge branch 'mega' into feature/MQTT-controller-cmd-improvements
TD-er Oct 7, 2024
85c1d62
Merge branch 'mega' into feature/MQTT-controller-cmd-improvements
tonhuisman Nov 2, 2024
c1013dd
Merge branch 'mega' of https://github.com/letscontrolit/ESPEasy into …
tonhuisman Nov 10, 2024
3a8e46d
Merge branch 'mega' of https://github.com/letscontrolit/ESPEasy into …
tonhuisman Nov 13, 2024
8ff6c04
Merge branch 'mega' of https://github.com/letscontrolit/ESPEasy into …
tonhuisman Nov 13, 2024
c6bc9f9
Merge mega and fix merge conflict
tonhuisman Dec 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/_C005.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,10 @@ bool C005_parse_command(struct EventStruct *event) {
if (validFloatFromString(event->String2, value_f) &&
validIntFromString(lastPartTopic, lastPartTopic_int)) {
const int prevLastindex = event->String1.lastIndexOf('/', lastindex - 1);
cmd = event->String1.substring(prevLastindex + 1, lastindex);
cmd += ',';
cmd += lastPartTopic_int;
cmd += ',';
cmd += event->String2; // Just use the original format
cmd = strformat(F("%s,%d,%s"),
event->String1.substring(prevLastindex + 1, lastindex).c_str(),
lastPartTopic_int,
event->String2.c_str()); // Just use the original format
validTopic = true;
}
}
Expand Down
21 changes: 14 additions & 7 deletions src/_C014.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
// #######################################################################################################

/** Changelog:
* 2023-10-30 tonhuisman: Fix using getHostname() instead of getName() for %sysname%. This might break some configurations!
* minor improvements
* 2023-08-18 tonhuisman: Clean up source to improve resource usage
* 2023-03-15 tonhuisman: Replace use of deprecated DummyValueSet with TaskValueSet
* 2023-03 Changelog started
Expand Down Expand Up @@ -51,6 +53,7 @@
# define CPLUGIN_014_SYSTEM_DEVICE "SYSTEM" // name for system device Plugin for cmd and GIO values
# define CPLUGIN_014_CMD_VALUE "cmd" // name for command value
# define CPLUGIN_014_GPIO_VALUE "gpio" // name for gpio value i.e. "gpio1"
# define CPLUGIN_014_GPIO_VALUE_LEN 4 // length of GPIO to avoid creating a String to get the length
# define CPLUGIN_014_CMD_VALUE_NAME "Command" // human readabele name for command value

# define CPLUGIN_014_GPIO_COMMAND "gpio" // name for gpio command
Expand All @@ -63,7 +66,7 @@ String CPlugin_014_pubname;
bool CPlugin_014_mqtt_retainFlag = false;

void C014_replaceSysname(String& var) {
var.replace(F("%sysname%"), Settings.getName());
var.replace(F("%sysname%"), Settings.getHostname()); // Used to be getName(), but that doesn't include the UnitNr when configured
tonhuisman marked this conversation as resolved.
Show resolved Hide resolved
}

bool CPlugin_014_sendMQTTdevice(String tmppubname,
Expand Down Expand Up @@ -385,6 +388,7 @@ bool CPlugin_014(CPlugin::Function function, struct EventStruct *event, String&
for (taskIndex_t x = 0; x < TASKS_MAX; x++)
{
const pluginID_t pluginID = Settings.getPluginID_for_task(x);

if (validPluginID_fullcheck(pluginID))
{
LoadTaskSettings(x);
Expand All @@ -401,6 +405,7 @@ bool CPlugin_014(CPlugin::Function function, struct EventStruct *event, String&
if (!Device[DeviceIndex].SendDataOption) // check if device is not sending data = assume that it can receive.
{
constexpr pluginID_t HOMIE_RECEIVER_PLUGIN_ID(86);

if (pluginID == HOMIE_RECEIVER_PLUGIN_ID)
{
for (uint8_t varNr = 0; varNr < valueCount; varNr++) {
Expand Down Expand Up @@ -497,6 +502,7 @@ bool CPlugin_014(CPlugin::Function function, struct EventStruct *event, String&
for (uint8_t varNr = 0; varNr < valueCount; varNr++)
{
const pluginID_t pluginID = Settings.getPluginID_for_task(x);

if (validPluginID_fullcheck(pluginID))
{
if (ExtraTaskSettings.TaskDeviceValueNames[varNr][0] != 0) // do not send if Value Name is empty!
Expand All @@ -520,6 +526,7 @@ bool CPlugin_014(CPlugin::Function function, struct EventStruct *event, String&
errorCounter);

constexpr pluginID_t DUMMY_PLUGIN_ID(33);

if (pluginID == DUMMY_PLUGIN_ID) { // Dummy Device can send AND receive Data
CPlugin_014_sendMQTTnode(nodename,
deviceName,
Expand Down Expand Up @@ -712,17 +719,17 @@ bool CPlugin_014(CPlugin::Function function, struct EventStruct *event, String&
log = strformat(F("C014 : MQTT received: /set: N: %s V: %s"), nodeName.c_str(), valueName.c_str());
}

if (equals(nodeName, F(CPLUGIN_014_SYSTEM_DEVICE))) // msg to a system device
if (equals(nodeName, F(CPLUGIN_014_SYSTEM_DEVICE))) // msg to a system device
{
if (valueName.startsWith(F(CPLUGIN_014_GPIO_VALUE))) // msg to to set gpio values
if (valueName.startsWith(F(CPLUGIN_014_GPIO_VALUE))) // msg to to set gpio values
{
const size_t gpio_value_tag_length = String(F(CPLUGIN_014_GPIO_VALUE)).length(); // FIXME use fixed length or constexpr
constexpr size_t gpio_value_tag_length = CPLUGIN_014_GPIO_VALUE_LEN; // now uses fixed length or constexpr

cmd = concat(F("GPIO,"), valueName.substring(gpio_value_tag_length).toInt()); // get the GPIO
cmd = concat(F("GPIO,"), valueName.substring(gpio_value_tag_length).toInt()); // get the GPIO
cmd += ',';

if (equals(event->String2, F("true")) || equals(event->String2, '1')) { // Homie spec says it should be 'true' or
cmd += '1'; // 'false'...
if (equals(event->String2, F("true")) || equals(event->String2, '1')) { // Homie spec says it should be 'true' or
cmd += '1'; // 'false'...
} else {
cmd += '0';
}
Expand Down