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))
# Update physical dashboard depending on the changed feed.
# Notice the feed_id is checked to find out which feed changed, then the
# appropriate physical dashboard widget is changed.
if feed_id == 'pi-dashboard-slider':
# The requests.post function will make an HTTP request against the
# dashboard. See the requests documentation for more information:
# http://docs.python-requests.org/en/latest/
requests.post('{0}/widgets/slider'.format(DASHBOARD_URL), data={'value': payload})
elif feed_id == 'pi-dashboard-humidity':
requests.post('{0}/widgets/humidity'.format(DASHBOARD_URL), data={'value': payload})
elif feed_id == 'pi-dashboard-temp':
requests.post('{0}/widgets/temp'.format(DASHBOARD_URL), data={'value': payload})
# Create an MQTT client instance.
评论列表
文章目录