parent
918fefbc57
commit
f253fddc41
|
@ -7,8 +7,7 @@ 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, Pipe
|
from multiprocessing import Process
|
||||||
from ast import literal_eval
|
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
@ -109,23 +108,18 @@ def connect_mqtt():
|
||||||
client.connect("localhost", 1883)
|
client.connect("localhost", 1883)
|
||||||
return client
|
return client
|
||||||
|
|
||||||
def mqtt_publisher():
|
if __name__ == "__main__":
|
||||||
# Create and start a thread for each universe
|
flask_thread = Process(target=flask_api)
|
||||||
db = connect(
|
flask_thread.start()
|
||||||
host=config['mysql']['host'],
|
|
||||||
user=config['mysql']['user'],
|
|
||||||
password=config['mysql']['password'],
|
|
||||||
database=config['mysql']['database'],
|
|
||||||
)
|
|
||||||
|
|
||||||
db.autocommit(True)
|
# 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:
|
||||||
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()
|
||||||
try:
|
try:
|
||||||
# Gets whatever the last Art-Net packet we received is
|
# Gets whatever the last Art-Net packet we received is
|
||||||
|
@ -135,8 +129,10 @@ 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 index_row in tube_index:
|
print(TUBE_INDEX)
|
||||||
|
for index_row in TUBE_INDEX:
|
||||||
|
print(index_row)
|
||||||
if artNetPacket.universe == int(index_row[1]):
|
if artNetPacket.universe == int(index_row[1]):
|
||||||
dmx_address = int(index_row[2])
|
dmx_address = int(index_row[2])
|
||||||
#Define RGB values per pixel
|
#Define RGB values per pixel
|
||||||
|
@ -149,11 +145,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()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
publisher_thread = Process(target=mqtt_publisher)
|
|
||||||
publisher_thread.start()
|
|
||||||
flask_thread = Process(target=flask_api)
|
|
||||||
flask_thread.start()
|
|
Loading…
Reference in New Issue