Skip to content

Commit 011afd0

Browse files
committed
Merge branch '0_15' into blending-styles
2 parents 77723b6 + 8d00e4d commit 011afd0

File tree

19 files changed

+677
-346
lines changed

19 files changed

+677
-346
lines changed

tools/stress_test.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash
2+
# Some web server stress tests
3+
#
4+
# Perform a large number of parallel requests, stress testing the web server
5+
# TODO: some kind of performance metrics
6+
7+
# Accepts three command line arguments:
8+
# - first argument - mandatory - IP or hostname of target server
9+
# - second argument - target type (optional)
10+
# - third argument - xfer count (for replicated targets) (optional)
11+
HOST=$1
12+
declare -n TARGET_STR="${2:-JSON_LARGER}_TARGETS"
13+
REPLICATE_COUNT=$(("${3:-10}"))
14+
15+
PARALLEL_MAX=${PARALLEL_MAX:-50}
16+
17+
CURL_ARGS="--compressed --parallel --parallel-immediate --parallel-max ${PARALLEL_MAX}"
18+
CURL_PRINT_RESPONSE_ARGS="-w %{http_code}\n"
19+
20+
JSON_TARGETS=('json/state' 'json/info' 'json/si', 'json/palettes' 'json/fxdata' 'settings/s.js?p=2')
21+
FILE_TARGETS=('' 'iro.js' 'rangetouch.js' 'settings' 'settings/wifi')
22+
# Replicate one target many times
23+
function replicate() {
24+
printf "${1}?%d " $(seq 1 ${REPLICATE_COUNT})
25+
}
26+
read -a JSON_TINY_TARGETS <<< $(replicate "json/nodes")
27+
read -a JSON_SMALL_TARGETS <<< $(replicate "json/info")
28+
read -a JSON_LARGE_TARGETS <<< $(replicate "json/si")
29+
read -a JSON_LARGER_TARGETS <<< $(replicate "json/fxdata")
30+
31+
# Expand target URLS to full arguments for curl
32+
TARGETS=(${TARGET_STR[@]})
33+
#echo "${TARGETS[@]}"
34+
FULL_TGT_OPTIONS=$(printf "http://${HOST}/%s -o /dev/null " "${TARGETS[@]}")
35+
#echo ${FULL_TGT_OPTIONS}
36+
37+
time curl ${CURL_ARGS} ${FULL_TGT_OPTIONS}

tools/udp_test.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import numpy as np
2+
import socket
3+
4+
class WledRealtimeClient:
5+
def __init__(self, wled_controller_ip, num_pixels, udp_port=21324, max_pixels_per_packet=126):
6+
self.wled_controller_ip = wled_controller_ip
7+
self.num_pixels = num_pixels
8+
self.udp_port = udp_port
9+
self.max_pixels_per_packet = max_pixels_per_packet
10+
self._sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
11+
self._prev_pixels = np.full((3, self.num_pixels), 253, dtype=np.uint8)
12+
self.pixels = np.full((3, self.num_pixels), 1, dtype=np.uint8)
13+
14+
def update(self):
15+
# Truncate values and cast to integer
16+
self.pixels = np.clip(self.pixels, 0, 255).astype(np.uint8)
17+
p = np.copy(self.pixels)
18+
19+
idx = np.where(~np.all(p == self._prev_pixels, axis=0))[0]
20+
num_pixels = len(idx)
21+
n_packets = (num_pixels + self.max_pixels_per_packet - 1) // self.max_pixels_per_packet
22+
idx_split = np.array_split(idx, n_packets)
23+
24+
header = bytes([1, 2]) # WARLS protocol header
25+
for packet_indices in idx_split:
26+
data = bytearray(header)
27+
for i in packet_indices:
28+
data.extend([i, *p[:, i]]) # Index and RGB values
29+
self._sock.sendto(bytes(data), (self.wled_controller_ip, self.udp_port))
30+
31+
self._prev_pixels = np.copy(p)
32+
33+
34+
35+
################################## LED blink test ##################################
36+
if __name__ == "__main__":
37+
WLED_CONTROLLER_IP = "192.168.1.153"
38+
NUM_PIXELS = 255 # Amount of LEDs on your strip
39+
import time
40+
wled = WledRealtimeClient(WLED_CONTROLLER_IP, NUM_PIXELS)
41+
print('Starting LED blink test')
42+
while True:
43+
for i in range(NUM_PIXELS):
44+
wled.pixels[1, i] = 255 if wled.pixels[1, i] == 0 else 0
45+
wled.update()
46+
time.sleep(.01)

0 commit comments

Comments
 (0)