parent
3e1f60fa22
commit
3a5ad1e6af
|
@ -94,10 +94,6 @@ def get_eth0_ip():
|
||||||
except (KeyError, IndexError, OSError) as e:
|
except (KeyError, IndexError, OSError) as e:
|
||||||
print(f"Error getting eth0 IP: {e}")
|
print(f"Error getting eth0 IP: {e}")
|
||||||
exit
|
exit
|
||||||
|
|
||||||
def on_message(mqttc, obj, msg):
|
|
||||||
global TUBE_INDEX
|
|
||||||
TUBE_INDEX = list(msg.payload.decode())
|
|
||||||
|
|
||||||
def on_connect(client, userdata, flags, reason_code, properties):
|
def on_connect(client, userdata, flags, reason_code, properties):
|
||||||
if reason_code == 0:
|
if reason_code == 0:
|
||||||
|
@ -113,11 +109,19 @@ def connect_mqtt():
|
||||||
client.connect("localhost", 1883)
|
client.connect("localhost", 1883)
|
||||||
return client
|
return client
|
||||||
|
|
||||||
def mqtt_publisher():
|
if __name__ == "__main__":
|
||||||
|
flask_thread = Process(target=flask_api)
|
||||||
|
flask_thread.start()
|
||||||
|
|
||||||
# Create and start a thread for each universe
|
# Create and start a thread for each universe
|
||||||
|
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:
|
||||||
|
cur = db.cursor()
|
||||||
|
cur.execute("SELECT mac_address, universe, dmx_address FROM tubes")
|
||||||
|
TUBE_INDEX = cur.fetchall()
|
||||||
|
cur.close()
|
||||||
try:
|
try:
|
||||||
# Gets whatever the last Art-Net packet we received is
|
# Gets whatever the last Art-Net packet we received is
|
||||||
artNetPacket = artNet.readPacket()
|
artNetPacket = artNet.readPacket()
|
||||||
|
@ -140,26 +144,4 @@ def mqtt_publisher():
|
||||||
mqtt_client.publish(p1_topic, str([str([p1_r, p1_g, p1_b]), str([p2_r, p2_g, p2_b]), str([p3_r, p3_g, p3_b]), str([p4_r, p4_g, p4_b]), str([p5_r, p5_g, p5_b]), str([p6_r, p6_g, p6_b])]))
|
mqtt_client.publish(p1_topic, str([str([p1_r, p1_g, p1_b]), str([p2_r, p2_g, p2_b]), str([p3_r, p3_g, p3_b]), str([p4_r, p4_g, p4_b]), str([p5_r, p5_g, p5_b]), str([p6_r, p6_g, p6_b])]))
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
artNet.close()
|
artNet.close()
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
def tube_index_updater():
|
|
||||||
while True:
|
|
||||||
mqtt_client = connect_mqtt()
|
|
||||||
cur = db.cursor()
|
|
||||||
cur.execute("SELECT mac_address, universe, dmx_address FROM tubes")
|
|
||||||
TUBE_INDEX = cur.fetchall()
|
|
||||||
cur.close()
|
|
||||||
mqtt_client.publish("pxm/tube_index", str(TUBE_INDEX))
|
|
||||||
print("Updated tube index")
|
|
||||||
time.sleep(5)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
update_tube_index_thread = Process(target=tube_index_updater)
|
|
||||||
update_tube_index_thread.start()
|
|
||||||
flask_thread = Process(target=flask_api)
|
|
||||||
flask_thread.start()
|
|
||||||
mqtt_client = connect_mqtt()
|
|
||||||
mqtt_client.subscribe("pxm/tube_index")
|
|
||||||
mqtt_client.loop_start()
|
|
||||||
mqtt_publisher()
|
|
Loading…
Reference in New Issue