parent
0b56adce60
commit
c66cc44546
@ -0,0 +1,46 @@ |
||||
#!/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', |
||||
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('test/jiffy/#') |
||||
|
||||
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 == 'test/jiffy/image': |
||||
logging.debug('image message received') |
||||
logging.debug('Image url is: ', 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() |
Loading…
Reference in new issue