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

Conversation

@cvdenzen
Copy link

@cvdenzen cvdenzen commented Aug 16, 2021

No description provided.

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
if (!strPrefix) {
index++;
}
//GATEWAY_DEBUG(PSTR("GWT:TPS:Index=%d, mqttstr=%s, prefixtoken=%s\n"), index, str,strPrefix);
Copy link
Member

Choose a reason for hiding this comment

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

Remove dead code

// 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.

Copy link
Member

@Yveaux Yveaux left a comment

Choose a reason for hiding this comment

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

See comments

cvdenzen and others added 16 commits August 22, 2021 21:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@Yveaux Yveaux Yveaux requested changes

@tekka007 tekka007 Awaiting requested review from tekka007

@henrikekblad henrikekblad Awaiting requested review from henrikekblad

@marceloaqno marceloaqno Awaiting requested review from marceloaqno

@scalz scalz Awaiting requested review from scalz

@tbowmo tbowmo Awaiting requested review from tbowmo

@user2684 user2684 Awaiting requested review from user2684

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

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