parent
6f45740f66
commit
d84d431600
|
@ -1,7 +1,6 @@
|
||||||
import socket
|
|
||||||
import os
|
import os
|
||||||
import wifi
|
import wifi
|
||||||
from pythonosc import udp_client
|
from stupidArtnet import *
|
||||||
from neopixel import *
|
from neopixel import *
|
||||||
import threading
|
import threading
|
||||||
import requests
|
import requests
|
||||||
|
@ -22,6 +21,9 @@ LED_COUNT = 60
|
||||||
strip = Adafruit_NeoPixel(LED_COUNT, LED_STRIP_PIN, 800000, 10, False)
|
strip = Adafruit_NeoPixel(LED_COUNT, LED_STRIP_PIN, 800000, 10, False)
|
||||||
strip.begin()
|
strip.begin()
|
||||||
|
|
||||||
|
def test_callback(data):
|
||||||
|
print(data)
|
||||||
|
|
||||||
def register_tube():
|
def register_tube():
|
||||||
# Register or reauthenticate the tube with the server
|
# Register or reauthenticate the tube with the server
|
||||||
try:
|
try:
|
||||||
|
@ -41,37 +43,16 @@ def is_connected_to_wifi():
|
||||||
except wifi.exceptions.InterfaceError:
|
except wifi.exceptions.InterfaceError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def listen_to_artnet(universe, dmx_address):
|
def listen_to_artnet(universe, dmx_address, strip, pixelCount):
|
||||||
# Set up Art-Net client
|
|
||||||
client = udp_client.SimpleUDPClient(SERVER_IP, SERVER_PORT)
|
|
||||||
|
|
||||||
# Listen to Art-Net messages
|
|
||||||
while True:
|
|
||||||
try:
|
try:
|
||||||
# Receive Art-Net message
|
artnet = StupidArtnetServer(universe=universe, callback_function=test_callback)
|
||||||
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as sock:
|
u_listener = artnet.register_listener(universe)
|
||||||
sock.bind(('0.0.0.0', 6454)) # Listen on all interfaces
|
while True:
|
||||||
data, addr = sock.recvfrom(1024)
|
data = artnet.get_buffer(listener_id=u_listener)
|
||||||
|
if len(data) > 0:
|
||||||
# Process Art-Net message
|
print(data)
|
||||||
universe_id = int.from_bytes(data[14:15], byteorder='big')
|
for i in range(pixelCount):
|
||||||
dmx_start_address = int.from_bytes(data[15:17], byteorder='big')
|
strip[i] = (data[(3 * i) + 0 + dmx_address], data[(3 * i) + 1 + dmx_address], data[(3 * i) + 2 + dmx_address])
|
||||||
|
|
||||||
if universe_id == universe and dmx_start_address <= dmx_address <= dmx_start_address + 2 * LED_COUNT:
|
|
||||||
# Extract RGB values from Art-Net packet
|
|
||||||
r = data[17]
|
|
||||||
g = data[18]
|
|
||||||
b = data[19]
|
|
||||||
|
|
||||||
# Map DMX address to LED index
|
|
||||||
led_index = (dmx_address - dmx_start_address) // 3
|
|
||||||
|
|
||||||
# Update LED strip
|
|
||||||
strip.setPixelColor(led_index, Color(r, g, b))
|
|
||||||
strip.show()
|
|
||||||
|
|
||||||
# Send confirmation to the server
|
|
||||||
client.send_message('/acknowledge', {'tube_id': wlan_mac_address, 'led_index': led_index})
|
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error: {e}")
|
print(f"Error: {e}")
|
||||||
|
|
|
@ -64,7 +64,7 @@
|
||||||
// Function to populate the tube list
|
// Function to populate the tube list
|
||||||
function populateTubeList() {
|
function populateTubeList() {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: '/get_tube_list',
|
url: "{{ url_for('', filename='/get_tube_list')}}",
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
success: function (data) {
|
success: function (data) {
|
||||||
$('#tubeList').empty();
|
$('#tubeList').empty();
|
||||||
|
|
Loading…
Reference in New Issue