2022-07-18 05:30:07 +00:00
|
|
|
|
|
|
|
# importing vlc module
|
2022-07-20 09:14:04 +00:00
|
|
|
from os import listdir
|
|
|
|
from os.path import isfile, join
|
|
|
|
from random import randint
|
2022-07-18 05:30:07 +00:00
|
|
|
from time import sleep
|
|
|
|
import paho.mqtt.client as mqtt
|
|
|
|
from video import Video
|
|
|
|
import multiprocessing
|
2022-07-18 06:47:01 +00:00
|
|
|
import sys
|
2022-07-20 09:14:04 +00:00
|
|
|
from random import randint
|
2022-07-18 05:30:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
class App:
|
2022-07-18 06:47:01 +00:00
|
|
|
def __init__(self, client, x, y):
|
2022-07-18 05:30:07 +00:00
|
|
|
self.client = client
|
2022-07-18 06:47:01 +00:00
|
|
|
self.video = Video(x, y)
|
2022-07-20 09:14:04 +00:00
|
|
|
self.videos = [join("slave/videos", f) for f in listdir("slave/videos") if isfile(join("slave/videos", f))]
|
|
|
|
print(self.videos)
|
|
|
|
print(self.videos[randint(0, len(self.videos))])
|
2022-07-18 05:30:07 +00:00
|
|
|
|
|
|
|
def on_connect(self, client, userdata, flags, rc):
|
|
|
|
print("Connected with result code "+str(rc))
|
2022-07-20 09:14:04 +00:00
|
|
|
self.client.subscribe("slave")
|
2022-07-18 05:30:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
def on_message(self, client, userdata, msg):
|
|
|
|
print(msg.topic+" "+str(msg.payload))
|
2022-07-20 09:14:04 +00:00
|
|
|
if msg.payload == b'idle':
|
|
|
|
print("Idle")
|
|
|
|
self.x = multiprocessing.Process(target = self.idle)
|
2022-07-18 05:30:07 +00:00
|
|
|
self.x.start()
|
|
|
|
|
|
|
|
elif msg.payload == b'stop':
|
|
|
|
print("Stop")
|
|
|
|
self.x.terminate()
|
|
|
|
|
2022-07-20 09:14:04 +00:00
|
|
|
|
|
|
|
def idle(self):
|
|
|
|
while True:
|
|
|
|
#if self.x is not None:
|
|
|
|
# self.x.terminate()
|
|
|
|
video = self.videos[randint(0, len(self.videos))]
|
|
|
|
self.video.start(video)
|
|
|
|
|
|
|
|
|
2022-07-18 06:47:01 +00:00
|
|
|
def main():
|
2022-07-18 05:30:07 +00:00
|
|
|
|
2022-07-18 06:47:01 +00:00
|
|
|
client = mqtt.Client()
|
|
|
|
app = App(client, int(sys.argv[1]), int(sys.argv[2]))
|
|
|
|
client.on_connect = app.on_connect
|
|
|
|
client.on_message = app.on_message
|
2022-07-18 05:30:07 +00:00
|
|
|
|
2022-07-20 09:14:04 +00:00
|
|
|
client.connect("10.1.1.162", 1883, 60)
|
2022-07-18 06:47:01 +00:00
|
|
|
|
|
|
|
client.loop_forever()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|