Update Dockerfile, and add mqtt client
This commit is contained in:
parent
0b56adce60
commit
c66cc44546
|
@ -8,3 +8,7 @@ WORKDIR /usr/src/app
|
||||||
COPY requirements.txt ./
|
COPY requirements.txt ./
|
||||||
|
|
||||||
RUN pip install -r requirements.txt
|
RUN pip install -r requirements.txt
|
||||||
|
|
||||||
|
COPY . ./
|
||||||
|
|
||||||
|
CMD ["python", "mqtt_run.py"]
|
|
@ -1,3 +1,4 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from Jiffy import Jiffy
|
from Jiffy import Jiffy
|
||||||
|
|
46
mqtt_run.py
Normal file
46
mqtt_run.py
Normal file
|
@ -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
Block a user