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: 265
Joined: Mon Feb 01, 2010 12:48 pm

Please be positive and constructive with your questions and comments.