parent
3734f4ee4e
commit
3d9bdb95cc
|
@ -43,6 +43,8 @@ db.autocommit(True)
|
||||||
|
|
||||||
mqtt_client_id = "PiXelTubeMaster-"+wlan_mac_address
|
mqtt_client_id = "PiXelTubeMaster-"+wlan_mac_address
|
||||||
|
|
||||||
|
TUBE_INDEX = None
|
||||||
|
|
||||||
# Function to register a tube in the database
|
# Function to register a tube in the database
|
||||||
def register_tube(mac_address):
|
def register_tube(mac_address):
|
||||||
cur = db.cursor()
|
cur = db.cursor()
|
||||||
|
@ -109,17 +111,16 @@ def connect_mqtt():
|
||||||
return client
|
return client
|
||||||
|
|
||||||
def update_tube_index():
|
def update_tube_index():
|
||||||
global tube_index
|
|
||||||
while True:
|
while True:
|
||||||
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()
|
TUBE_INDEX = cur.fetchall()
|
||||||
cur.close()
|
cur.close()
|
||||||
print("Updated index: "+str(tube_index))
|
print("Updated index: "+str(TUBE_INDEX))
|
||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
|
|
||||||
def mqtt_publisher():
|
def mqtt_publisher():
|
||||||
global tube_index
|
global 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()
|
||||||
|
@ -133,8 +134,8 @@ def mqtt_publisher():
|
||||||
#Checks to see if the current packet is for the specified DMX Universe
|
#Checks to see if the current packet is for the specified DMX Universe
|
||||||
dmxPacket = artNetPacket.data
|
dmxPacket = artNetPacket.data
|
||||||
# Create MQTT topic based on the universe and channel
|
# Create MQTT topic based on the universe and channel
|
||||||
if tube_index is not None:
|
if TUBE_INDEX is not None:
|
||||||
for row in tube_index:
|
for row in TUBE_INDEX:
|
||||||
dmx_address = int(row[2])
|
dmx_address = int(row[2])
|
||||||
if artNetPacket.universe == int(row[1]):
|
if artNetPacket.universe == int(row[1]):
|
||||||
#Define RGB values per pixel
|
#Define RGB values per pixel
|
||||||
|
@ -150,7 +151,6 @@ def mqtt_publisher():
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
global tube_index
|
|
||||||
tube_index_updater_thread = Process(target=update_tube_index)
|
tube_index_updater_thread = Process(target=update_tube_index)
|
||||||
tube_index_updater_thread.start()
|
tube_index_updater_thread.start()
|
||||||
flask_thread = Process(target=flask_api)
|
flask_thread = Process(target=flask_api)
|
||||||
|
|
Loading…
Reference in New Issue