Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/home/un/Documents/Coding Projects/WebApi/Discord
/Discord
.idea/
__pycache__/
assets/settings/
15 changes: 14 additions & 1 deletion Basic_Light.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def __init__(self):
self.strip.begin()
self.colors = {}
self.is_uniform = True
self.on = False
self.uniform = {'all': [0, 0, 0, 0]}
for i in range(self.END_LED + 1):
self.colors[str(i)] = [0, 0, 0, 0]
Expand All @@ -50,24 +51,36 @@ def get_color(self):
return self.uniform['all']
else:
return None

def setBrightness(self, alpha):
self.LED_BRIGHTNESS = alpha

print(self.process)
self.on = alpha != 0
print(self.uniform if self.is_uniform else self.colors)
if self.process[0] is None or not self.process[1].is_alive():
self.showAll(self.uniform if self.is_uniform else self.colors)

def setPixelColor(self, index, color):
color = [int(c * self.LED_BRIGHTNESS / 255 + 0.5) for c in color]
self.strip.setPixelColor(index, Color(*color))
for i in color:
if i != 0:
self.on = self.LED_BRIGHTNESS != 0
return
self.on = False

@stopProcess
def show(self, index, color):
self.is_uniform = False
self.setPixelColor(index, color)
self.strip.show()
self.colors[str(index)] = color
for i in color:
if i != 0:
self.on = self.LED_BRIGHTNESS != 0
rerurn
slef.on = False

def showAll(self, dict: dict, stop=True):
if stop:
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# WebApi
This project is not thought to be used by other people.
HOWEVER, feel free to take inspiration from the code and if you want me to expand/change features open an issue or join my [discord server](https://discord.gg/F6bjEfKybV)

## Functionalities
It creates a local api and web page on the port 5000. Api can be used to control some sk6812rgbw led strips.
Websitegives access to camera, led strips and all your files for an easy access over the network.

## Disclaimer
Use at your own risks. In particular, the file explorer has no security whatsoever, therefore anyone on the network can access and delete your files.
62 changes: 55 additions & 7 deletions Server.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import os
import shutil
import time
# import RPi.GPIO as GPIO
import pigpio
from threading import Timer
from warnings import warn

Expand All @@ -17,8 +19,16 @@
from flask_restful import Api, Resource
from waitress import serve

from VideoScrapper import VideoScrapperModule as module_bp

from Basic_Light import LightStrip

path = os.path.dirname(os.path.realpath(__file__))

light_strip = LightStrip()

display = False

try:
cap = cv2.VideoCapture(0)
cap.set(cv2.CAP_PROP_BRIGHTNESS, 60)
Expand All @@ -31,7 +41,44 @@
nocam = True
warn("Camera has not been loaded. Either because it is not connected or something else.")

path = os.path.dirname(os.path.realpath(__file__))
"""
# setup interrupt to have a light switch
button_pin = 9
GPIO.setmode(GPIO.BCM)
def light_switch(x):
print(x)
print("hi")
if light_strip.on:
light_strip.setBrightness(0)
light_strip.showAll({"all": [0, 0, 0, 0]})
else:
light_strip.showAll({"all": [50, 20, 0, 255]})
light_strip.setBrightness(255)
GPIO.setup(button_pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.add_event_detect(button_pin, GPIO.BOTH, callback=light_switch bouncetime=50)
"""
# TODO push to github
pi = pigpio.pi()
if not pi.connected:
warn("GPIO not connected, some features may not work properly.")

button_pin = 9
pi.set_mode(button_pin, pigpio.INPUT)
pi.set_pull_up_down(button_pin, pigpio.PUD_DOWN)

def light_switch(gpio, level, tick):
if level == pigpio.TIMEOUT:
return
if light_strip.on:
light_strip.setBrightness(0)
light_strip.showAll({"all": [0, 0, 0, 0]})
else:
light_strip.showAll({"all": [50, 20, 0, 255]})
light_strip.setBrightness(255)

pi.set_glitch_filter(button_pin, 100000)
cb = pi.callback(button_pin, pigpio.EITHER_EDGE, light_switch)


with open(path + '/assets/settings/settings.json', 'r') as fp:
settings = json.load(fp)
Expand All @@ -47,12 +94,9 @@
if users['ip_address'][ip]['keep_login']:
logged_in[ip] = users['ip_address'][ip]['user']

light_strip = LightStrip()

display = False

# Init app, flask, ...
app = Flask(__name__)
app.register_blueprint(module_bp("/media/Series"), url_prefix="/VideoScrapper")

api = Api(app)

Expand Down Expand Up @@ -470,5 +514,9 @@ def func(f):
api.add_resource(Delete, '/api/file_explorer/delete/<string:file>')

if __name__ == '__main__':
load_from_planning()
serve(app, host=server_ip, port=4000)
try:
load_from_planning()
serve(app, host=server_ip, port=4000)
finally:
cb.cancel()
pi.stop()
24 changes: 0 additions & 24 deletions assets/settings/saved_users.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,6 @@
"127.0.0.1": {
"user": "laggrif",
"keep_login": true
},
"192.168.0.172": {
"user": "ugo",
"keep_login": true
},
"192.168.0.32": {
"user": "ugo",
"keep_login": true
},
"128.179.136.226": {
"user": "ugo",
"keep_login": true
},
"128.179.151.247": {
"user": "ugo",
"keep_login": true
},
"192.168.0.172": {
"user": "ugo",
"keep_login": true
},
"192.168.0.32": {
"user": "ugo",
"keep_login": true
}
}
}