0

Publish to single MQTT topic to update multiple feeds
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Publish to single MQTT topic to update multiple feeds

by sensmaster on Tue Jan 29, 2019 6:04 am

Hi guys,

As I understand currently the Adafruit IO generate 1 topic for each feed. Is it possible to publish data to a single MQTT topic with JSON formatted payload, and the JSON formatted payload has all the feeds data.

Thanks for your time.

sensmaster
 
Posts: 1
Joined: Tue Jan 29, 2019 5:54 am

Re: Publish to single MQTT topic to update multiple feeds

by abachman on Tue Jan 29, 2019 6:36 pm

Hi sensmaster,


The Groups API can do that. We use it internally in the Adafruit IO Arduino and I've added documentation to our primary MQTT documentation spot: https://learn.adafruit.com/welcome-to-a ... entation-2.

Put all the feeds you want to publish to at the same time in a group together and then MQTT publish to {username}/groups/{group_key} with the payload format:
Code: Select all | TOGGLE FULL SIZE
{
  "feeds": {
    "key-1": "value 1",
    "key-2": "value 2",
    "key-3": "value 3"
  },
  "location": {
    "lat": 1.0,
    "lon": 2.0,
    "ele": 3.0
  }
}


Where "key-1", etc. are the feed keys you want to publish to. The location object is optional and you only have to include the feeds you want to update.

You can also subscribe to the group MQTT topic if you want to monitor all the feeds in a group from a single MQTT subscription.


- adam b.

abachman
 
Posts: 286
Joined: Mon Feb 01, 2010 12:48 pm

Re: Publish to single MQTT topic to update multiple feeds

by profhuster on Fri Mar 15, 2019 11:39 am

How would that be done in python?
The documentation and the examples I have found in io.adafruit.com and learn.adafruit.com do not mention groups very much. I did find https://learn.adafruit.com/welcome-to-adafruit-io/mqtt-api-documentation-2, but it would be nice to have a python example.

Also, key for feeds in a group, getting the key is hard to figure out.. For example I made a group something like
Code: Select all | TOGGLE FULL SIZE
MyRoom0
with a feed
Code: Select all | TOGGLE FULL SIZE
myroom0_temp
. In the Feed display the Name is truncated as
Code: Select all | TOGGLE FULL SIZE
myroom0.myroom...
. When I click on the feed, then Feed Info I see the feed is named
Code: Select all | TOGGLE FULL SIZE
advlab0-temp
and the URL is
Code: Select all | TOGGLE FULL SIZE
https://io.adafruit.com/profhuster/feeds/advlab0.advlab0-temp

profhuster
 
Posts: 1
Joined: Fri Mar 08, 2019 8:52 pm

Please be positive and constructive with your questions and comments.