adfded multiprocessisng back again and also made a mqtt share for the tube index
Signed-off-by: Ebbe Baß <ebbe.bass>main
parent
775a6caf77
commit
77ad069eec
|
@ -109,19 +109,24 @@ def connect_mqtt():
|
||||||
client.connect("localhost", 1883)
|
client.connect("localhost", 1883)
|
||||||
return client
|
return client
|
||||||
|
|
||||||
if __name__ == "__main__":
|
def mqtt_publisher():
|
||||||
flask_thread = Process(target=flask_api)
|
def on_message(mqttc, obj, msg):
|
||||||
flask_thread.start()
|
print(msg.payload)
|
||||||
|
print(type(msg.payload))
|
||||||
|
global TUBE_INDEX
|
||||||
|
TUBE_INDEX = msg.payload
|
||||||
|
|
||||||
|
# Set Connecting Client ID
|
||||||
|
mqtt_client = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2)
|
||||||
|
# client.username_pw_set(username, password)
|
||||||
|
mqtt_client.on_message = on_message
|
||||||
|
mqtt_client.connect("localhost", 1883)
|
||||||
# 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)
|
||||||
|
mqtt_client.subscribe("pxm/tube_index")
|
||||||
|
mqtt_client.loop_start()
|
||||||
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()
|
||||||
|
@ -145,3 +150,20 @@ if __name__ == "__main__":
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
artNet.close()
|
artNet.close()
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
|
def tube_index_updater():
|
||||||
|
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))
|
||||||
|
|
||||||
|
|
||||||
|
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()
|
||||||
|
publisher_thread = Process(target=mqtt_publisher)
|
||||||
|
publisher_thread.start()
|
Loading…
Reference in New Issue