-
-
Notifications
You must be signed in to change notification settings - Fork 118
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
Give an example of publish with retained bit set #68
Comments
@raenrfm |
This is the modified callback function correct? But how is it used in the sketch? Is it just the client.publish(topic,payload); command? Do I have to pass anything else in this command or is modifying the callback function enough? |
@raenrfm |
But how is it used in the sketch? Can you just show me a sketch that publishes with the retained bit set to true? I want my MQTT server to retain values even if they have been read by one device. I want the value to stay in the server until a new value replaces it. That is what the retained message is for. |
yes, you set "retain = true" like this |
@hirotakaster I've studied the source code but can't get this to work either, tried casting input values to different types without success. Particle compile service returns this:
|
Use case for me is setting up an remote switch integration with Home Assistant (docs). The retain flag is used to feed back status after switching on/off. Example |
Darn.. the curse of posting questions. After looking one more time at the source I noticed the small type difference of the payload, this works for me now:
Ping @raenrfm in case you haven't solved it |
Ok so the addition of the (uint8_t*) is what solved the issue?
On Fri, Dec 1, 2017, 5:53 PM Simon Hellbe, ***@***.***> wrote:
Darn.. the curse of posting questions. After looking one more time at the
source I noticed the small type difference of the payload, this works for
me now:
client.publish("bedroom/light/status", (uint8_t*) "ON", 2, true);
Ping @raenrfm <https://github.com/raenrfm> in case you haven't solved it
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#68 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AX9UrvJ5IZw694cPAI7QzfUK4_piu0Yzks5s8INZgaJpZM4QJG6y>
.
--
<object width="290" height="130"><param name="movie" value="
http://www.wunderground.com/swf/pws_mini_rf_nc.swf?station=ITHUNDER5&freq=&units=metric&lang=EN"
/><embed src="
http://www.wunderground.com/swf/pws_mini_rf_nc.swf?station=ITHUNDER5&freq=&units=metric&lang=EN"
type="application/x-shockwave-flash" width="290" height="130" /></object>
|
Yep @raenrfm |
Would this apply if your payloads are just unsigned integers?
On Sat, 2 Dec 2017 at 17:34 Simon Hellbe ***@***.***> wrote:
Yep @raenrfm <https://github.com/raenrfm>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#68 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AX9UrsqV4cq5PHV5yaEs2erE1m82rr6Pks5s8dBkgaJpZM4QJG6y>
.
--
<object width="290" height="130"><param name="movie" value="
http://www.wunderground.com/swf/pws_mini_rf_nc.swf?station=ITHUNDER5&freq=&units=metric&lang=EN"
/><embed src="
http://www.wunderground.com/swf/pws_mini_rf_nc.swf?station=ITHUNDER5&freq=&units=metric&lang=EN"
type="application/x-shockwave-flash" width="290" height="130" /></object>
|
Sorry what I meant was that I'm using this on a particle photon and have
the payloads set as unsigned int's
On Wed, 6 Dec 2017 at 09:48 Robert Mantel ***@***.***> wrote:
Would this apply if your payloads are just unsigned integers?
On Sat, 2 Dec 2017 at 17:34 Simon Hellbe ***@***.***> wrote:
> Yep @raenrfm <https://github.com/raenrfm>
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <#68 (comment)>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AX9UrsqV4cq5PHV5yaEs2erE1m82rr6Pks5s8dBkgaJpZM4QJG6y>
> .
>
--
<object width="290" height="130"><param name="movie" value="
http://www.wunderground.com/swf/pws_mini_rf_nc.swf?station=ITHUNDER5&freq=&units=metric&lang=EN"
/><embed src="
http://www.wunderground.com/swf/pws_mini_rf_nc.swf?station=ITHUNDER5&freq=&units=metric&lang=EN"
type="application/x-shockwave-flash" width="290" height="130" /></object>
|
I really wish he created an example of using the retained feature. I'm
still having trouble getting this to work.
On Wed, 6 Dec 2017 at 09:51 Robert Mantel ***@***.***> wrote:
Sorry what I meant was that I'm using this on a particle photon and have
the payloads set as unsigned int's
On Wed, 6 Dec 2017 at 09:48 Robert Mantel ***@***.***> wrote:
> Would this apply if your payloads are just unsigned integers?
>
> On Sat, 2 Dec 2017 at 17:34 Simon Hellbe ***@***.***>
> wrote:
>
>> Yep @raenrfm <https://github.com/raenrfm>
>>
>> —
>> You are receiving this because you were mentioned.
>> Reply to this email directly, view it on GitHub
>> <#68 (comment)>,
>> or mute the thread
>> <https://github.com/notifications/unsubscribe-auth/AX9UrsqV4cq5PHV5yaEs2erE1m82rr6Pks5s8dBkgaJpZM4QJG6y>
>> .
>>
> --
<object width="290" height="130"><param name="movie" value="
http://www.wunderground.com/swf/pws_mini_rf_nc.swf?station=ITHUNDER5&freq=&units=metric&lang=EN"
/><embed src="
http://www.wunderground.com/swf/pws_mini_rf_nc.swf?station=ITHUNDER5&freq=&units=metric&lang=EN"
type="application/x-shockwave-flash" width="290" height="130" /></object>
--
<object width="290" height="130"><param name="movie" value="
http://www.wunderground.com/swf/pws_mini_rf_nc.swf?station=ITHUNDER5&freq=&units=metric&lang=EN"
/><embed src="
http://www.wunderground.com/swf/pws_mini_rf_nc.swf?station=ITHUNDER5&freq=&units=metric&lang=EN"
type="application/x-shockwave-flash" width="290" height="130" /></object>
|
I think you're ok as long as you're not overflowing it with a high number, uint8_t is short for an unsigned 8 bit integer (i.e. 0-255). But I'm kind of out of my depth here :) |
Check out this thread for converting high ints to uint8_t arrays: https://forum.arduino.cc/index.php?topic=361659.0 |
yeah, it's working without the retained setup, but I don't know what
callback function to use to publish a retained payload.
On Wed, 6 Dec 2017 at 10:12 Simon Hellbe ***@***.***> wrote:
I think you're ok as long as you're not overflowing it with a high number,
uint8_t is short for an unsigned *8 bit* integer (i.e. 0-255). But I'm
kind of out of my depth here :)
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#68 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AX9UruVQWEvi8_4ME55Zw2Qr7aukmnAoks5s9q7FgaJpZM4QJG6y>
.
--
<object width="290" height="130"><param name="movie" value="
http://www.wunderground.com/swf/pws_mini_rf_nc.swf?station=ITHUNDER5&freq=&units=metric&lang=EN"
/><embed src="
http://www.wunderground.com/swf/pws_mini_rf_nc.swf?station=ITHUNDER5&freq=&units=metric&lang=EN"
type="application/x-shockwave-flash" width="290" height="130" /></object>
|
He has three example ino files but none of them show the use of the
retained bit.
On Wed, 6 Dec 2017 at 10:15 Robert Mantel ***@***.***> wrote:
yeah, it's working without the retained setup, but I don't know what
callback function to use to publish a retained payload.
On Wed, 6 Dec 2017 at 10:12 Simon Hellbe ***@***.***> wrote:
> I think you're ok as long as you're not overflowing it with a high
> number, uint8_t is short for an unsigned *8 bit* integer (i.e. 0-255).
> But I'm kind of out of my depth here :)
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <#68 (comment)>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AX9UruVQWEvi8_4ME55Zw2Qr7aukmnAoks5s9q7FgaJpZM4QJG6y>
> .
>
--
<object width="290" height="130"><param name="movie" value="
http://www.wunderground.com/swf/pws_mini_rf_nc.swf?station=ITHUNDER5&freq=&units=metric&lang=EN"
/><embed src="
http://www.wunderground.com/swf/pws_mini_rf_nc.swf?station=ITHUNDER5&freq=&units=metric&lang=EN"
type="application/x-shockwave-flash" width="290" height="130" /></object>
--
<object width="290" height="130"><param name="movie" value="
http://www.wunderground.com/swf/pws_mini_rf_nc.swf?station=ITHUNDER5&freq=&units=metric&lang=EN"
/><embed src="
http://www.wunderground.com/swf/pws_mini_rf_nc.swf?station=ITHUNDER5&freq=&units=metric&lang=EN"
type="application/x-shockwave-flash" width="290" height="130" /></object>
|
You might need to clarify your use case more. The original question was just about publishing with retained flag but now you're talking about callbacks? I provided an example how to publish with a retained bit in this comment. If you have a high int as the payload the recommendation from the arduino forum thread I linked before is to convert your int to a string and then back to int on the receiving end. |
If you don't use the correct callback function you can't use the retained
bit capability, from what I understand.
On Wed, 6 Dec 2017 at 10:20 Simon Hellbe ***@***.***> wrote:
You might need to clarify your use case more. The original question was
just about publishing with retained flag but now you're talking about
callbacks?
I provided an example how to publish with a retained bit in this comment
<#68 (comment)>.
If you have a high int as the payload you want to suggest the
recommendation from the arduino forum thread I linked before is to convert
your int to a string and then back to int on the receiving end.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#68 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AX9Urv0BiTutKaJJtvSnZmb17Kh4vTQlks5s9rCjgaJpZM4QJG6y>
.
--
<object width="290" height="130"><param name="movie" value="
http://www.wunderground.com/swf/pws_mini_rf_nc.swf?station=ITHUNDER5&freq=&units=metric&lang=EN"
/><embed src="
http://www.wunderground.com/swf/pws_mini_rf_nc.swf?station=ITHUNDER5&freq=&units=metric&lang=EN"
type="application/x-shockwave-flash" width="290" height="130" /></object>
|
Here is the callback function used in his example:
void callback(char* topic, byte* payload, unsigned int length);
if you attempt to use this with the retained bit option in your publish
statement it blows up.
On Wed, 6 Dec 2017 at 10:24 Robert Mantel ***@***.***> wrote:
If you don't use the correct callback function you can't use the retained
bit capability, from what I understand.
On Wed, 6 Dec 2017 at 10:20 Simon Hellbe ***@***.***> wrote:
> You might need to clarify your use case more. The original question was
> just about publishing with retained flag but now you're talking about
> callbacks?
>
> I provided an example how to publish with a retained bit in this comment
> <#68 (comment)>.
> If you have a high int as the payload you want to suggest the
> recommendation from the arduino forum thread I linked before is to convert
> your int to a string and then back to int on the receiving end.
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <#68 (comment)>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AX9Urv0BiTutKaJJtvSnZmb17Kh4vTQlks5s9rCjgaJpZM4QJG6y>
> .
>
--
<object width="290" height="130"><param name="movie" value="
http://www.wunderground.com/swf/pws_mini_rf_nc.swf?station=ITHUNDER5&freq=&units=metric&lang=EN"
/><embed src="
http://www.wunderground.com/swf/pws_mini_rf_nc.swf?station=ITHUNDER5&freq=&units=metric&lang=EN"
type="application/x-shockwave-flash" width="290" height="130" /></object>
--
<object width="290" height="130"><param name="movie" value="
http://www.wunderground.com/swf/pws_mini_rf_nc.swf?station=ITHUNDER5&freq=&units=metric&lang=EN"
/><embed src="
http://www.wunderground.com/swf/pws_mini_rf_nc.swf?station=ITHUNDER5&freq=&units=metric&lang=EN"
type="application/x-shockwave-flash" width="290" height="130" /></object>
|
I'm converting floats to strings then publishing. I'm thinking that's the
difference between your case and mine.
On Wed, 6 Dec 2017 at 10:26 Robert Mantel ***@***.***> wrote:
Here is the callback function used in his example:
void callback(char* topic, byte* payload, unsigned int length);
if you attempt to use this with the retained bit option in your publish
statement it blows up.
On Wed, 6 Dec 2017 at 10:24 Robert Mantel ***@***.***> wrote:
> If you don't use the correct callback function you can't use the retained
> bit capability, from what I understand.
>
> On Wed, 6 Dec 2017 at 10:20 Simon Hellbe ***@***.***>
> wrote:
>
>> You might need to clarify your use case more. The original question was
>> just about publishing with retained flag but now you're talking about
>> callbacks?
>>
>> I provided an example how to publish with a retained bit in this comment
>> <#68 (comment)>.
>> If you have a high int as the payload you want to suggest the
>> recommendation from the arduino forum thread I linked before is to convert
>> your int to a string and then back to int on the receiving end.
>>
>> —
>> You are receiving this because you were mentioned.
>> Reply to this email directly, view it on GitHub
>> <#68 (comment)>,
>> or mute the thread
>> <https://github.com/notifications/unsubscribe-auth/AX9Urv0BiTutKaJJtvSnZmb17Kh4vTQlks5s9rCjgaJpZM4QJG6y>
>> .
>>
> --
> <object width="290" height="130"><param name="movie" value="
> http://www.wunderground.com/swf/pws_mini_rf_nc.swf?station=ITHUNDER5&freq=&units=metric&lang=EN"
> /><embed src="
> http://www.wunderground.com/swf/pws_mini_rf_nc.swf?station=ITHUNDER5&freq=&units=metric&lang=EN"
> type="application/x-shockwave-flash" width="290" height="130" /></object>
>
--
<object width="290" height="130"><param name="movie" value="
http://www.wunderground.com/swf/pws_mini_rf_nc.swf?station=ITHUNDER5&freq=&units=metric&lang=EN"
/><embed src="
http://www.wunderground.com/swf/pws_mini_rf_nc.swf?station=ITHUNDER5&freq=&units=metric&lang=EN"
type="application/x-shockwave-flash" width="290" height="130" /></object>
--
<object width="290" height="130"><param name="movie" value="
http://www.wunderground.com/swf/pws_mini_rf_nc.swf?station=ITHUNDER5&freq=&units=metric&lang=EN"
/><embed src="
http://www.wunderground.com/swf/pws_mini_rf_nc.swf?station=ITHUNDER5&freq=&units=metric&lang=EN"
type="application/x-shockwave-flash" width="290" height="130" /></object>
|
FYI, I added a method like so:
With this, I just do I'm happy to provide a PR if it's useful to the community @hirotakaster |
Hi @dakl , |
#77 should fix this. @raenrfm @hirotakaster |
I'm trying to send payloads that I want retained, but I cannot figure out the syntax of the publish statement to allow that. I'm using QOS0 so don't care about that.
The text was updated successfully, but these errors were encountered: