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

Add support for retain flag when publishing #216

Merged
merged 8 commits into from
Nov 11, 2022

Conversation

ben-willmore
Copy link

@ben-willmore ben-willmore commented Nov 2, 2022

This is an updated version of https://github.com/Fapiko/Adafruit_MQTT_Library/tree/retain-flag which uses function overloading instead of optional parameters, as suggested in #169. This would also resolve #20 and #161.

// Example usage
Adafruit_MQTT_Client mqtt(&client, MQTT_SERVER, MQTT_SERVERPORT, MQTT_USERNAME, MQTT_KEY);

Adafruit_MQTT_Publish feed1 = Adafruit_MQTT_Publish(&mqtt, "/feeds/feed1");
feed1.publish("retain", true); // retain
feed1.publish("discard", false); // don't retain
feed1.publish("discard"); // don't retain

Adafruit_MQTT_Publish feed2 = Adafruit_MQTT_Publish(&mqtt, "/feeds/feed2");
feed2.publish(1, true); // retain
feed2.publish(0, false); // don't retain
feed2.publish(0); // don't retain

Adafruit_MQTT_Publish feed3 = Adafruit_MQTT_Publish(&mqtt, "/feeds/feed3");
feed3.publish(1.0, true); // retain
feed3.publish(0.0, false); // don't retain
feed3.publish(0.0); // don't retain

mqtt.publish("/feeds/feed4", "retain", true); // retain
mqtt.publish("/feeds/feed4", "discard", false); // don't retain
mqtt.publish("/feeds/feed4", "discard"); // don't retain

@brentru
Copy link
Member

brentru commented Nov 8, 2022

@ben-willmore Thank you for the PR. Are you interested in possibly adding an example, similar to the one you have above but within examples/, to serve as documentation for example usage?

@brentru brentru self-requested a review November 8, 2022 16:26
@ben-willmore
Copy link
Author

Sure, I will push an example when I get a chance (probably a couple of days).

@brentru brentru merged commit 18af1b6 into adafruit:master Nov 11, 2022
@brentru
Copy link
Member

brentru commented Nov 11, 2022

@ben-willmore Thank you for the Pull Request!

@ben-willmore
Copy link
Author

@brentru Thank you too for working on it, I'm pleased to see this feature get merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support Retain for Publish
3 participants