#!/usr/bin/env python import logging import paho.mqtt.client as mqtt from Jiffy import Jiffy logging.basicConfig(level=logging.DEBUG) jiffy = Jiffy( host='dashpi-g1.hacklab', api_url_v1_0='api/v1', api_url_v1_2='api/v1.2', credentials=( 'admin', 'hacklab' ) ) def send_jiffy(client, url): jiffy.display_media_from_url(url, 10) def on_connect(client, userdata, flags, rc): logging.debug("connected with result " + str(rc)) client.subscribe('display/nec/#') def on_message(client, userdata, msg): try: lastmsg = msg.payload.decode("utf-8") #logging.debug(lastmsg) except Exception as e: lastmsg = '' logging.debug("Error {}".format(e)) if msg.topic == 'display/nec/image': logging.debug('image message received') logging.debug('Image url is: {}'.format(lastmsg)) send_jiffy(client, lastmsg) client = mqtt.Client() client.on_connect = on_connect client.on_message = on_message client.connect("mqtt.hacklab") client.loop_forever()