From a79f4e44c743c69ed7f5b522aed4fda5bf8c287c Mon Sep 17 00:00:00 2001 From: hubobel Date: Sun, 11 Jan 2026 18:42:42 +0100 Subject: [PATCH] =?UTF-8?q?error=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Python/Cron | 2 +- Python/{LCD => LCD.py} | 6 +++- Python/README.md | 5 +++ Python/error.py | 72 +++++++++++++++++++++++++++++++++++++++ Python/test.py | 72 +++++++++++++++++++++++++++++++++++++++ grafana/docker-compos.yml | 2 +- 6 files changed, 156 insertions(+), 3 deletions(-) rename Python/{LCD => LCD.py} (91%) create mode 100644 Python/error.py create mode 100644 Python/test.py diff --git a/Python/Cron b/Python/Cron index 0153110..a890971 100644 --- a/Python/Cron +++ b/Python/Cron @@ -1 +1 @@ -@reboot sleep 30 && /usr/bin/python3 /home/christof/lcd/test3.py >> /var/log/start_after_boot.log 2>&1 \ No newline at end of file +@reboot sleep 30 && /usr/bin/python3 /home/christof/lcd/LCD.py >> /var/log/start_after_boot.log 2>&1 \ No newline at end of file diff --git a/Python/LCD b/Python/LCD.py similarity index 91% rename from Python/LCD rename to Python/LCD.py index 839d4c5..83b44b9 100644 --- a/Python/LCD +++ b/Python/LCD.py @@ -46,7 +46,7 @@ def main(): print("Alle Container sind running + healthy.") subprocess.run( - ["python3", "test.py"], + ["python3", "/home/christof/lcd/test.py"], check=True ) return 0 @@ -54,6 +54,10 @@ def main(): time.sleep(SLEEP_S) print("Timeout: Container nicht rechtzeitig healthy.", file=sys.stderr) + subprocess.run( + ["python3", "/home/christof/lcd/error.py"], + check=True + ) return 1 if __name__ == "__main__": diff --git a/Python/README.md b/Python/README.md index 22060cc..e9ff351 100644 --- a/Python/README.md +++ b/Python/README.md @@ -2,4 +2,9 @@ python3 -m pip config set global.break-system-packages true sudo pip3 install adafruit-blinka + +sudo pip3 install adafruit-circuitpython-ssd1306 + +sudo pip3 install Pillow + mqtt diff --git a/Python/error.py b/Python/error.py new file mode 100644 index 0000000..e19920a --- /dev/null +++ b/Python/error.py @@ -0,0 +1,72 @@ +import board +import digitalio +from PIL import Image, ImageDraw, ImageFont +import adafruit_ssd1306 +import socket +import time + +s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) +s.connect(("8.8.8.8", 80)) # keine echte Verbindung, nur Routing +ip_address = s.getsockname()[0] +s.close() + + +# Initialize OLED display dimensions +WIDTH = 128 +HEIGHT = 64 + +# Set up I2C communication with the OLED display +i2c = board.I2C() # Utilizes board's SCL and SDA pins +oled = adafruit_ssd1306.SSD1306_I2C(WIDTH, HEIGHT, i2c, addr=0x3C) + +# Clear the OLED display +oled.fill(0) +oled.show() + +# Create a new image with 1-bit color for drawing +image = Image.new("1", (oled.width, oled.height)) + +# Obtain a drawing object to manipulate the image +draw = ImageDraw.Draw(image) + +# Draw a filled white rectangle as the background +draw.rectangle((0, 0, oled.width, oled.height), outline=255, fill=255) + +# Define border size for an inner rectangle +BORDER = 5 +# Draw a smaller black rectangle inside the larger one +draw.rectangle( + (BORDER, BORDER, oled.width - BORDER - 1, oled.height - BORDER - 1), + outline=0, + fill=0, +) + +# Load the default font for text +font = ImageFont.load_default() + +def getfontsize(font, text): + # Calculate the size of the text in pixels + left, top, right, bottom = font.getbbox(text) + return right - left, bottom - top + +# Define the text to be displayed +text = "! Error !" +# Get the width and height of the text in pixels +(font_width, font_height) = getfontsize(font, text) +# Draw the text, centered on the display +draw.text( + (oled.width // 2 - font_width // 2, oled.height // 2 - font_height // 2), + text, + font=font, + fill=255, +) + +# Send the image to the OLED display +oled.image(image) +oled.show() + +DISPLAY_ON_TIME = 10 * 60 +time.sleep(DISPLAY_ON_TIME) + +# --- OLED sauber ausschalten --- +oled.poweroff() \ No newline at end of file diff --git a/Python/test.py b/Python/test.py new file mode 100644 index 0000000..f37a597 --- /dev/null +++ b/Python/test.py @@ -0,0 +1,72 @@ +import board +import digitalio +from PIL import Image, ImageDraw, ImageFont +import adafruit_ssd1306 +import socket +import time + +s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) +s.connect(("8.8.8.8", 80)) # keine echte Verbindung, nur Routing +ip_address = s.getsockname()[0] +s.close() + + +# Initialize OLED display dimensions +WIDTH = 128 +HEIGHT = 64 + +# Set up I2C communication with the OLED display +i2c = board.I2C() # Utilizes board's SCL and SDA pins +oled = adafruit_ssd1306.SSD1306_I2C(WIDTH, HEIGHT, i2c, addr=0x3C) + +# Clear the OLED display +oled.fill(0) +oled.show() + +# Create a new image with 1-bit color for drawing +image = Image.new("1", (oled.width, oled.height)) + +# Obtain a drawing object to manipulate the image +draw = ImageDraw.Draw(image) + +# Draw a filled white rectangle as the background +draw.rectangle((0, 0, oled.width, oled.height), outline=255, fill=255) + +# Define border size for an inner rectangle +BORDER = 5 +# Draw a smaller black rectangle inside the larger one +draw.rectangle( + (BORDER, BORDER, oled.width - BORDER - 1, oled.height - BORDER - 1), + outline=0, + fill=0, +) + +# Load the default font for text +font = ImageFont.load_default() + +def getfontsize(font, text): + # Calculate the size of the text in pixels + left, top, right, bottom = font.getbbox(text) + return right - left, bottom - top + +# Define the text to be displayed +text = ip_address +# Get the width and height of the text in pixels +(font_width, font_height) = getfontsize(font, text) +# Draw the text, centered on the display +draw.text( + (oled.width // 2 - font_width // 2, oled.height // 2 - font_height // 2), + text, + font=font, + fill=255, +) + +# Send the image to the OLED display +oled.image(image) +oled.show() + +DISPLAY_ON_TIME = 10 * 60 +time.sleep(DISPLAY_ON_TIME) + +# --- OLED sauber ausschalten --- +oled.poweroff() \ No newline at end of file diff --git a/grafana/docker-compos.yml b/grafana/docker-compos.yml index bb4a459..68fed58 100644 --- a/grafana/docker-compos.yml +++ b/grafana/docker-compos.yml @@ -12,7 +12,7 @@ services: ports: - '3000:3000' volumes: - - /home/christof/grafana/storage/:/var/lib/grafana' + - /home/christof/grafana/storage/:/var/lib/grafana networks: