-
Notifications
You must be signed in to change notification settings - Fork 291
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
Support MQTT retain flag on publishing. #88
base: master
Are you sure you want to change the base?
Support MQTT retain flag on publishing. #88
Conversation
This resolves issue adafruit#20 by allowing the user to specify the retain flag on the publisher object. This flag is useful for slow publishers so that a new subscription will immediately receive the last published message.
In changing to a bool parameter this was missed off the last commit.
Using 43f78c7 library. It seems still unable to read the retained last published value when using io.adafruit.com as broker. I have tried modified Adafruit MQTT Library ESP8266 Example and set the retain flag to be "true" as below Attache the code below: /****************************************************/ /************************* WiFi Access Point *********************************/ #define WLAN_SSID "SSID" //"...your SSID..." /************************* Adafruit.io Setup *********************************/ #define AIO_SERVER "io.adafruit.com" WiFiClient client; Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY); /****************************** Feeds ***************************************/ Adafruit_MQTT_Publish photocell = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/photocell", 0, true); void MQTT_connect(); void setup() { Serial.println(F("Adafruit MQTT demo")); // Connect to WiFi access point. WiFi.begin(WLAN_SSID, WLAN_PASS); Serial.println("WiFi connected");
} uint32_t x; // Now we can publish stuff! // Function to connect and reconnect as necessary to the MQTT server. // Stop if already connected. Serial.print("Connecting to MQTT... "); uint8_t retries = 3; The series monitor show the following respond: Connecting to SSID Sending photocell val 0...OK! Sending photocell val 1...OK! Sending photocell val 2...OK! Sending photocell val 3...OK! Sending photocell val 4...OK! Sending photocell val 5...OK! Sending photocell val 6...OK! Press Reset button on the hardware to restart the hardware**** So it seem still not function properly for this commit??? Connecting to SSID Sending photocell val 0...OK! Sending photocell val 1...OK! Sending photocell val 2...OK! Sending photocell val 3...OK! Sending photocell val 4...OK! |
This resolves issue #20 by allowing the user to specify the retain flag
on the publisher object. This flag is useful for slow publishers so that
a new subscription will immediately receive the last published message.
This change adds a new boolean parameter to the Adafruit_MQTT_Publish constructor to set the retention flag for this publisher instance. To preserve existing compatibility the parameter is defaulted to false. This flag is then propagated to the implementing function Adafruit_MQTT::publishPacket where it is combined into the MQTT_CTRL_PUBLISH flags as a single bit flag.
This has then been confirmed using a Mosquitto MQTT broker to check that resulting messages were
being retained and presented promptly to new subscribers.