project reimplemented

This commit is contained in:
2023-01-14 01:01:51 +01:00
parent 9ba01e69d1
commit 9a58d5f118
21 changed files with 196 additions and 363 deletions
+6
View File
@@ -0,0 +1,6 @@
install:
chmod +x ./lc.py
cp lc.service /etc/systemd/system/
systemctl daemon-reload
systemctl enable --now lc.service
systemctl restart lc
+5
View File
@@ -0,0 +1,5 @@
scp lc.py lc.service Makefile pi@192.168.188.76:~/
ssh pi@192.168.188.76 'sudo make install'
scp lc.py lc.service Makefile pi@192.168.188.64:~/
ssh pi@192.168.188.76 'sudo make install'
Executable
+52
View File
@@ -0,0 +1,52 @@
#!/usr/bin/python3
import socket
import re
import Adafruit_WS2801
import Adafruit_GPIO.SPI as SPI
import RPi.GPIO as GPIO
PIXEL_COUNT = 32
SPI_PORT = 0
SPI_DEVICE = 0
pixels = Adafruit_WS2801.WS2801Pixels(PIXEL_COUNT, spi=SPI.SpiDev(SPI_PORT, SPI_DEVICE), gpio=GPIO)
def hex_to_rgb(hex):
r = int(hex[0:2],16)
g = int(hex[2:4],16)
b = int(hex[4:6],16)
return r,g,b
reg = re.compile("[0-9a-f]{6}$")
host = "0.0.0.0"
port = 5000
s = socket.socket()
s.bind((host, port))
s.listen(1)
while True:
conn, address = s.accept()
print("Connection from: ", str(address))
while True:
data = conn.recv(1024).decode()
if not data:
print("Disconneted: ", str(address))
break
if reg.match(data):
print("set color", data)
for i in range(PIXEL_COUNT):
pixels.set_pixel_rgb(i, *hex_to_rgb(data))
pixels.show()
elif data == 'PING':
conn.send('PONG'.encode())
else:
print(data, "incorrect format. use hex color code.")
break
conn.close()
+19
View File
@@ -0,0 +1,19 @@
[Unit]
Description=Start Light Controll as Daemon
After=multi-user.target
[Service]
Type=simple
User=pi
Group=pi
SyslogIdentifier=lc
Restart=on-failure
RestartSec=2
WorkingDirectory=/home/pi
ExecStart=/home/pi/lc.py
SyslogIdentifier=pyserver
StandardOutput=syslog
StandardError=syslog
[Install]
WantedBy=multi-user.target