parent
4cae853f15
commit
914c328a45
|
@ -7,7 +7,8 @@ import os
|
||||||
from getmac import get_mac_address
|
from getmac import get_mac_address
|
||||||
import time
|
import time
|
||||||
import sys
|
import sys
|
||||||
from multiprocessing import Process, Manager
|
from multiprocessing import Process, Value
|
||||||
|
from ctypes import c_char_p
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
@ -108,13 +109,12 @@ def connect_mqtt():
|
||||||
client.connect("localhost", 1883)
|
client.connect("localhost", 1883)
|
||||||
return client
|
return client
|
||||||
|
|
||||||
def mqtt_publisher(shared_dict):
|
def mqtt_publisher(tube_index):
|
||||||
# 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:
|
||||||
tube_index = shared_dict["tube_index"]
|
|
||||||
# print(tube_index)
|
# print(tube_index)
|
||||||
try:
|
try:
|
||||||
# Gets whatever the last Art-Net packet we received is
|
# Gets whatever the last Art-Net packet we received is
|
||||||
|
@ -140,27 +140,25 @@ def mqtt_publisher(shared_dict):
|
||||||
artNet.close()
|
artNet.close()
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
def tube_index_updater(shared_dict):
|
def tube_index_updater(tube_index):
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
cur = db.cursor()
|
cur = db.cursor()
|
||||||
cur.execute("SELECT mac_address, universe, dmx_address FROM tubes")
|
cur.execute("SELECT mac_address, universe, dmx_address FROM tubes")
|
||||||
tube_index = cur.fetchall()
|
result = cur.fetchall()
|
||||||
cur.close()
|
cur.close()
|
||||||
shared_dict["tube_index"] = [str(tube_index)]
|
tube_index = [str(result)]
|
||||||
print("Updated tube index with values: "+str(tube_index))
|
print("Updated tube index with values: "+str(tube_index))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
manager = Manager()
|
tube_index = Value(c_char_p, None)
|
||||||
shared_dict = manager.dict()
|
ti_updater_thread = Process(target=tube_index_updater, args=(tube_index))
|
||||||
shared_dict["tube_index"] = None
|
|
||||||
ti_updater_thread = Process(target=tube_index_updater, args=(shared_dict))
|
|
||||||
ti_updater_thread.start()
|
ti_updater_thread.start()
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
publisher_thread = Process(target=mqtt_publisher, args=(shared_dict))
|
publisher_thread = Process(target=mqtt_publisher, args=(tube_index))
|
||||||
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