parent
f1000a053a
commit
50d07e2e15
|
@ -109,17 +109,25 @@ def connect_mqtt():
|
||||||
client.connect("localhost", 1883)
|
client.connect("localhost", 1883)
|
||||||
return client
|
return client
|
||||||
|
|
||||||
def mqtt_publisher(ti_receiver):
|
def mqtt_publisher(ti_queue):
|
||||||
|
tube_index = None
|
||||||
# Create and start a thread for each universe
|
# Create and start a thread for each universe
|
||||||
mqtt_client = connect_mqtt()
|
mqtt_client = connect_mqtt()
|
||||||
artnetBindIp = get_eth0_ip()
|
artnetBindIp = get_eth0_ip()
|
||||||
artNet = Artnet.Artnet(BINDIP = artnetBindIp, DEBUG = True, SHORTNAME = "PiXelTubeMaster", LONGNAME = "PiXelTubeMaster", PORT = 6454)
|
artNet = Artnet.Artnet(BINDIP = artnetBindIp, DEBUG = True, SHORTNAME = "PiXelTubeMaster", LONGNAME = "PiXelTubeMaster", PORT = 6454)
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
start = time.time()
|
try:
|
||||||
tube_index = ti_receiver.recv()
|
start = time.time()
|
||||||
end = time.time()
|
tube_index = ti_queue.get(block=False)
|
||||||
print("Receiving of tube index took: "+str(end-start))
|
end = time.time()
|
||||||
|
print("Receiving of tube index took: "+str(end-start))
|
||||||
|
tube_index_old = tube_index
|
||||||
|
except:
|
||||||
|
if tube_index_old is not None:
|
||||||
|
tube_index = tube_index_old
|
||||||
|
else:
|
||||||
|
tube_index = None
|
||||||
# Gets whatever the last Art-Net packet we received is
|
# Gets whatever the last Art-Net packet we received is
|
||||||
start = time.time()
|
start = time.time()
|
||||||
artNetPacket = artNet.readPacket()
|
artNetPacket = artNet.readPacket()
|
||||||
|
@ -144,6 +152,7 @@ def mqtt_publisher(ti_receiver):
|
||||||
mqtt_client.publish(p1_topic, result)
|
mqtt_client.publish(p1_topic, result)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
artNet.close()
|
artNet.close()
|
||||||
|
|
||||||
def tube_index_updater(ti_queue):
|
def tube_index_updater(ti_queue):
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
|
@ -156,27 +165,12 @@ def tube_index_updater(ti_queue):
|
||||||
print(e)
|
print(e)
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
|
|
||||||
def tube_index_collector(ti_queue, ti_sender):
|
|
||||||
item_old = None
|
|
||||||
while True:
|
|
||||||
try:
|
|
||||||
item = ti_queue.get(block=False)
|
|
||||||
ti_sender.send(item)
|
|
||||||
item_old = item
|
|
||||||
except Empty:
|
|
||||||
if item_old is not None:
|
|
||||||
ti_sender.send(item_old)
|
|
||||||
else:
|
|
||||||
ti_sender.send(None)
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
(ti_receiver,ti_sender) = Pipe(True)
|
(ti_receiver,ti_sender) = Pipe(True)
|
||||||
ti_queue = Queue()
|
ti_queue = Queue()
|
||||||
collector_thread = Process(target=tube_index_collector, args=(ti_queue, ti_sender, ))
|
|
||||||
collector_thread.start()
|
|
||||||
ti_updater_thread = Process(target=tube_index_updater, args=(ti_queue, ))
|
ti_updater_thread = Process(target=tube_index_updater, args=(ti_queue, ))
|
||||||
ti_updater_thread.start()
|
ti_updater_thread.start()
|
||||||
publisher_thread = Process(target=mqtt_publisher, args=(ti_receiver, ))
|
publisher_thread = Process(target=mqtt_publisher, args=(ti_queue, ))
|
||||||
publisher_thread.start()
|
publisher_thread.start()
|
||||||
flask_thread = Process(target=flask_api)
|
flask_thread = Process(target=flask_api)
|
||||||
flask_thread.start()
|
flask_thread.start()
|
Loading…
Reference in New Issue