Feed Sharing

Feed sharing is a feature of Adafruit IO which allows you to share your feeds with people you specify.

If you want to share a feed on your Adafruit IO Account with another user, visit the Sharing a feed page on the Adafruit Learning System.

The Adafruit IO Python client supports Feed Sharing in the mqtt_client.py class.

Usage Example

Example of reading and writing to a shared  Adafruit IO Feed.


Author: Brent Rubell for Adafruit Industries 2018

# Import standard python modules.
import sys
import time
import random

# Import Adafruit IO MQTT client.
from Adafruit_IO import MQTTClient

# Set to your Adafruit IO key.
# Remember, your key is a secret,
# so make sure not to publish it when you publish this code!

# Set to your Adafruit IO username.
# (go to https://accounts.adafruit.com to find your username)

# Shared IO Feed
# Make sure you have read AND write access to this feed to publish.

# IO Feed Owner's username

# Define callback functions which will be called when certain events happen.
def connected(client):
    """Connected function will be called when the client connects.
    client.subscribe(IO_FEED, IO_FEED_USERNAME)

def disconnected(client):
    """Disconnected function will be called when the client disconnects.
    print('Disconnected from Adafruit IO!')

def message(client, feed_id, payload):
    """Message function will be called when a subscribed feed has a new value.
    The feed_id parameter identifies the feed, and the payload parameter has
    the new value.
    print('Feed {0} received new value: {1}'.format(feed_id, payload))

# Create an MQTT client instance.

# Setup the callback functions defined above.
client.on_connect       =   connected
client.on_disconnect    =   disconnected
client.on_message       =   message

# Connect to the Adafruit IO server.

print('Publishing a new message every 10 seconds (press Ctrl-C to quit)...')

while True:
    value = random.randint(0, 100)
    print('Publishing {0} to {1}.'.format(value, IO_FEED))
    client.publish(IO_FEED, value, IO_FEED_USERNAME)