Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Accept wildcards in mqtt subscription prefix #1497

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

Open
cvdenzen wants to merge 20 commits into mysensors:development
base: development
Choose a base branch
Loading
from cvdenzen:carl
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
e9446b2
Accept wildcards in mqtt subscription prefix
cvdenzen Aug 16, 2021
45cb263
Accept wildcards in mqtt subscription prefix
cvdenzen Aug 18, 2021
b36c846
Accept wildcards in mqtt subscription prefix
cvdenzen Aug 18, 2021
aeb62d2
Merge remote-tracking branch 'origin/carl' into carl
cvdenzen Aug 22, 2021
4a8bb44
Merge remote-tracking branch 'origin/carl' into carl
cvdenzen Aug 22, 2021
75e131b
Merge remote-tracking branch 'origin/carl' into carl
cvdenzen Aug 22, 2021
23eb210
Merge remote-tracking branch 'origin/carl' into carl
cvdenzen Aug 22, 2021
305992b
Merge branch 'carl' of https://github.com/cvdenzen/MySensors into carl
cvdenzen Aug 22, 2021
2cfe833
Bug fix for GPIO under recent Linux kernel versions
romaricr Mar 12, 2024
3dba00f
Updated for style and minors non functional changes
romaricr Mar 16, 2024
f157ed0
Minor changes
romaricr Mar 16, 2024
72f713a
Merge branch 'development' into carl
cvdenzen Mar 24, 2024
fea7b0d
Makefile.inc under version control
cvdenzen Mar 24, 2024
80987aa
Merge remote-tracking branch 'upstream2/gpio_fix' into carl
cvdenzen Jan 18, 2025
29ecc91
GPIO issues
cvdenzen Jan 30, 2025
55ab7b5
Revert "GPIO issues"
cvdenzen Feb 4, 2025
6f42fbf
GPIO issue 1567
cvdenzen Feb 4, 2025
031957d
Revert "Minor changes"
cvdenzen Feb 4, 2025
3d47095
Revert "Updated for style and minors non functional changes"
cvdenzen Feb 4, 2025
76beb1f
Revert "Bug fix for GPIO under recent Linux kernel versions"
cvdenzen Feb 4, 2025
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: 9 additions & 0 deletions MySensors-Arduino.iml
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager">
<output url="file://$MODULE_DIR$/bin" />
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
3 changes: 1 addition & 2 deletions configure
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -577,10 +577,9 @@ if [ -z "${SOC}" ]; then
info=($(detect_machine))
SOC=${info[0]}
TYPE=${info[1]}
CPU=${info[2]}
printf " ${OK} machine detected: SoC=${SOC}, Type=${TYPE}, CPU=${CPU}.\n"
fi

CPU=$(eval "uname -m 2>/dev/null")
if [ -z "${CPUFLAGS}" ]; then
CPUFLAGS=$(gcc_cpu_flags "${SOC}" "${CPU}")
fi
Expand Down
23 changes: 19 additions & 4 deletions core/MyProtocol.cpp
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,29 @@ bool protocolMQTT2MyMessage(MyMessage &message, char *topic, uint8_t *payload,
const unsigned int length)
{
char *str, *p;
uint8_t index = 0;
int8_t index = -1;
message.setSender(GATEWAY_ADDRESS);
message.setLast(GATEWAY_ADDRESS);
message.setEcho(false);
for (str = strtok_r(topic + strlen(MY_MQTT_SUBSCRIBE_TOPIC_PREFIX) + 1, "/", &p);

// The subscription prefix can contain wildcards, but only the + wildcard.
Copy link
Member

@Yveaux Yveaux Aug 22, 2021
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is only the single-level + wildcard supported?
If we add support for wildcards, users will expect to be able to use multi-level # wildcards too.
If you parse right-to-left for the mysensors message field you could support any wildcard.

mfalkvidd reacted with thumbs up emoji
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The MQTT multi-level wildcard (#) is only allowed at the end of the topic. Because the prefix is always followed by other levels it cannot contain the # wildcard, although "my" code wouldn't complain about it.

The code only checks the number of / characters.
The syntactical check is left to the MQTT broker. That was already the case and I think that is right. I have browsed the MySensors code and checked all code where the PREFIX is used and none of needed a change.

mfalkvidd reacted with thumbs up emoji
// e.g. subscription prefix "+/mysensors", actual prefix "foo/mysensors"
// To fetch only the part after the mqtt prefix, discard as many
// mqtt levels (between / characters) as in the subscription prefix.
// Make a copy of the subscribe prefix because strtok is allowed to change the string.
char subscribeTopicPrefix[strlen(MY_MQTT_SUBSCRIBE_TOPIC_PREFIX) + 1];
strcpy(subscribeTopicPrefix,MY_MQTT_SUBSCRIBE_TOPIC_PREFIX);
char *strPrefix, *savePointerPrefix;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the increase in ram/flash for this change?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The savepointer (4 bytes?) is stored on stack I guess.
The increase in ram (stack use?) for the copy of the prefix string will be the length of the prefix plus 1.
The default value for the prefix is mygateway1-in, length is 13, so it will use 14 bytes on the stack. Your comment made me think about this memory usage. Actually I think malloc/free would be safer. Or maybe choose in runtime between stack and malloc depending on the prefix length? The length of the string is known at compile time, but I don't think that will help. I am not an expert in this subject.

Flash use? Is that the code length? The answer is: I don't know.

I compiled and ran it only on a raspberry pi 2, not on an Arduino.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In core/MyGatewayTransportMQTTClient.cpp, method reconnectMQTT, there is also a local variable inTopic with a length of the prefix plus 10. So I think it is acceptable to have it as a stack variable.

for (str = strtok_r(topic, "/", &p),
strPrefix = strtok_r(subscribeTopicPrefix,"/", &savePointerPrefix);
str && index < 5;
str = strtok_r(NULL, "/", &p), index++
str = strtok_r(NULL, "/", &p),
strPrefix = strtok_r(NULL, "/", &savePointerPrefix)
) {
// Increment index (init value is -1) if we have consumed the mqtt subscription prefix
if (!strPrefix) {
index++;
}
switch (index) {
case 0:
// Node id
Expand Down Expand Up @@ -163,5 +178,5 @@ bool protocolMQTT2MyMessage(MyMessage &message, char *topic, uint8_t *payload,
}
}
// Return true if input valid
return (index == 5);
return (index == 4);
}

AltStyle によって変換されたページ (->オリジナル) /