[MQTT Dash] Refresh on connect

380 views
Skip to first unread message

Rene J. Martins

unread,
Oct 23, 2019, 4:34:29 PM10/23/19
to Routix
Hi Vadim Mostovoy,

I wonder if it is possible to refresh values on connect so that if someone else updates any topic, it could reflect in my dashboard next time I connect to the broker from MQTT Dash.

Thanks and congratulations for your wonderful app!

Regards,

Rene

Vadim Mostovoy

unread,
Oct 23, 2019, 4:37:47 PM10/23/19
to rene.j....@gmail.com, Routix
Hi Rene, MQTT protocol has `retained` messages. Read about it for better understanding.
In short, last retained message stored on broker side and sent to the client as soon as client subscribed on topic.

--
Thanks,
Vadim Mostovoy


--
You received this message because you are subscribed to the Google Groups "Routix" group.
To unsubscribe from this group and stop receiving emails from it, send an email to routix+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/routix/0cb5dff3-5501-4d73-9a26-a23c28c40763%40googlegroups.com.

Rene J. Martins

unread,
Oct 24, 2019, 10:25:32 AM10/24/19
to Routix
I've read about retained messages and made a bunch of testing. However, it doesn't seem to work with io.adafruit.com, unfortunately. :-(

Regards,
______________________________________________
Rene J. Martins 

Vadim Mostovoy

unread,
Oct 24, 2019, 11:48:41 AM10/24/19
to rene.j....@gmail.com, Routix
Sorry about that.
Unfortunately there is nothing like "request last data" in MQTT protocol specification.
Client app can only passively listen on topic. The only viable thing is retained message.
It works fine in my and others' environments.
I suggest to contact adafruit and check with them.

--
Thanks,
Vadim Mostovoy

Rene J. Martins

unread,
Oct 24, 2019, 5:56:33 PM10/24/19
to Routix
I have just confirmed that io.adafruit.com does not support retained messages (https://io.adafruit.com/api/docs/mqtt.html#retained-values), which is a shame!
Fortunately, I managed to find a workaround for this issue (for those who use io.adafruit.com), thanks to your JavaScript handlers!

Here we go:


On Receive event:
if (!event.data) {
  event.data = {};
}
event.data['MyButton'] = 'done';


On Display event:
if (!event.data) {
  event.data = {};
  event.data['MyButton'] = 'refresh';
}
if (event.data['MyButton'] != 'done') {
  app.publish('user/feeds/myfeed/get', 'get', false, 1);
}



Explanation: If you publish anything into feed/get, it won't be published. However, it will force your subscription to receive data as if it had just been updated! (https://io.adafruit.com/api/docs/mqtt.html#using-the-get-topic)

Regards,
______________________________________________
Rene J. Martins 

Reply all
Reply to author
Forward
0 new messages