parent
abbe011e71
commit
356b184bef
|
@ -87,7 +87,7 @@ sudo apt update -y && sudo apt upgrade -y && sudo apt install python3 python3-pi
|
||||||
pip3 install Flask
|
pip3 install Flask
|
||||||
pip3 install adafruit_circuitpython_neopixel
|
pip3 install adafruit_circuitpython_neopixel
|
||||||
pip3 install Requests
|
pip3 install Requests
|
||||||
pip3 install sacn
|
pip3 install python-artnet
|
||||||
pip3 install wifi
|
pip3 install wifi
|
||||||
pip3 install paho-mqtt
|
pip3 install paho-mqtt
|
||||||
pip3 install get-mac
|
pip3 install get-mac
|
||||||
|
|
|
@ -3,7 +3,7 @@ import json
|
||||||
import MySQLdb
|
import MySQLdb
|
||||||
import paho.mqtt.client as mqtt
|
import paho.mqtt.client as mqtt
|
||||||
import threading
|
import threading
|
||||||
import sacn
|
import python_artnet as Artnet
|
||||||
import os
|
import os
|
||||||
from getmac import get_mac_address
|
from getmac import get_mac_address
|
||||||
import netifaces
|
import netifaces
|
||||||
|
@ -93,7 +93,7 @@ def get_eth0_ip():
|
||||||
try:
|
try:
|
||||||
# Get the IP address of the eth0 interface
|
# Get the IP address of the eth0 interface
|
||||||
eth0_ip = netifaces.ifaddresses('eth0')[netifaces.AF_INET][0]['addr']
|
eth0_ip = netifaces.ifaddresses('eth0')[netifaces.AF_INET][0]['addr']
|
||||||
return eth0_ip
|
return str(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}")
|
||||||
return None
|
return None
|
||||||
|
@ -113,31 +113,22 @@ def connect_mqtt():
|
||||||
return client
|
return client
|
||||||
|
|
||||||
|
|
||||||
def mqtt_publisher(universe):
|
def mqtt_publisher(universe, artnetPacket):
|
||||||
universe = universe-1
|
universe = universe-1
|
||||||
mqtt_client = connect_mqtt()
|
mqtt_client = connect_mqtt()
|
||||||
try:
|
try:
|
||||||
receiver = sacn.sACNreceiver(bind_address=get_eth0_ip())
|
dmx_values = artnetPacket.data
|
||||||
print(str(get_eth0_ip()))
|
|
||||||
receiver.start()
|
|
||||||
|
|
||||||
def on_dmx_frame(packet, universe, channel_data): # packet type: sacn.DataPacket
|
|
||||||
print(packet.dmxData)
|
|
||||||
global dmx_values
|
|
||||||
dmx_values = packet.dmxData
|
|
||||||
|
|
||||||
receiver.join_multicast(universe)
|
|
||||||
receiver.register_listener(universe=universe, func=on_dmx_frame)
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
if dmx_values is not None:
|
if artnetPacket.universe == universe:
|
||||||
for channel, value in enumerate(dmx_values):
|
if dmx_values is not None:
|
||||||
# Create MQTT topic based on the universe and channel
|
dmxPacket = artnetPacket.data
|
||||||
topic = f"{universe}/{channel}"
|
for i in dmx_values:
|
||||||
|
# # Create MQTT topic based on the universe and channel
|
||||||
|
# topic = f"{universe}/{channel}"
|
||||||
|
|
||||||
# Publish the DMX value to the MQTT topic
|
# # Publish the DMX value to the MQTT topic
|
||||||
mqtt_client.publish(topic, value)
|
# mqtt_client.publish(topic, value)
|
||||||
print(str(universe+" "+channel+" "+value))
|
print(dmxPacket[i-1], end=" ")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error in universe {universe}: {e}")
|
print(f"Error in universe {universe}: {e}")
|
||||||
|
|
Loading…
Reference in New Issue