Skip to content

Commit

Permalink
Merge pull request #20 from spitzlbergerj/development
Browse files Browse the repository at this point in the history
diverse Fehlerbehebungen und Verbesserungen/Stabilisierungen
  • Loading branch information
spitzlbergerj authored Mar 16, 2024
2 parents 15d33cc + c93315e commit 369d053
Show file tree
Hide file tree
Showing 31 changed files with 3,518 additions and 376 deletions.
24 changes: 12 additions & 12 deletions .crontabs/crontab-pi
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,36 @@

# Klimasensoren alle 60 Sekunden auslesen
02-59/10 * * * * python3 -u /home/pi/CaravanPi/climate/climate2file.py -i 76 >/home/pi/CaravanPi/.log/climate2file76.log 2>&1
#03-59/10 * * * * python3 -u /home/pi/CaravanPi/climate/climate2file.py -i 77 >/home/pi/CaravanPi/.log/climate2file77.log 2>&1
# 03-59/10 * * * * python3 -u /home/pi/CaravanPi/climate/climate2file.py -i 77 >/home/pi/CaravanPi/.log/climate2file77.log 2>&1

# Lagesensor auslesen, Zeitsteuerung im Skript inkl. Live Modus
@reboot python3 -u /home/pi/CaravanPi/position/position2file.py -f >/home/pi/CaravanPi/.log/position2file.log 2>&1
@reboot sleep 300 && python3 -u /home/pi/CaravanPi/position/position2file.py -s >/home/pi/CaravanPi/.log/position2file.log 2>&1

# Taster für Kalibrierung Lagesensor und Gaswaage aktivieren
@reboot python3 -u /home/pi/CaravanPi/tactileSwitch/tactileSwitches.py >/home/pi/CaravanPi/.log/tactileSwitches.log 2>&1
@reboot sleep 310 && python3 -u /home/pi/CaravanPi/tactileSwitch/tactileSwitches.py >/home/pi/CaravanPi/.log/tactileSwitches.log 2>&1

# Füllmenge Tanks auslesen
@reboot python3 -u /home/pi/CaravanPi/levels/freshLevels2file.py -t 1 -f >/home/pi/CaravanPi/.log/levels.log 2>&1
#04-59/10 * * * * python3 -u /home/pi/CaravanPi/levels/wasteLevels2file.py -t 2 -f >/home/pi/CaravanPi/.log/levels.log 2>&1
@reboot sleep 320 && python3 -u /home/pi/CaravanPi/levels/freshLevels2file.py -t 1 -f >/home/pi/CaravanPi/.log/levels.log 2>&1
# 04-59/10 * * * * python3 -u /home/pi/CaravanPi/levels/wasteLevels2file.py -t 2 -f >/home/pi/CaravanPi/.log/levels.log 2>&1

# Batteriemanagement auslesen
05-59/10 * * * * python3 -u /home/pi/CaravanPi/batteryMgmt/bms2file.py >/home/pi/CaravanPi/.log/bms2file.log 2>&1
05-59/10 * * * * python3 -u /home/pi/CaravanPi/batteryMgmt/bms2file.py -s >/home/pi/CaravanPi/.log/bms2file.log 2>&1

# Systemdaten Raspberry Pi lesen
@reboot python3 -u /home/pi/CaravanPi/raspberrypi/systemstat2file.py >/home/pi/CaravanPi/.log/systemstat.log 2>&1
@reboot sleep 330 && python3 -u /home/pi/CaravanPi/raspberrypi/systemstat2file.py -s >/home/pi/CaravanPi/.log/systemstat.log 2>&1

# MariaDB bereinigen, jeden Montag 01:05
05 01 * * 1 python3 -u /home/pi/CaravanPi/raspberrypi/clean_MariaDB.py -d 150 >/home/pi/CaravanPi/.log/cleanMariaDB.log 2>&1

# Gassensor überwachen
@reboot python3 -u /home/pi/CaravanPi/analogSignals/gassensorCheck.py >/home/pi/CaravanPi/.log/gassensorCheck.log 2>&1
@reboot sleep 340 && python3 -u /home/pi/CaravanPi/analogSignals/gassensorCheck.py -s >/home/pi/CaravanPi/.log/gassensorCheck.log 2>&1

# 230V Eingang überwachen
@reboot python3 -u /home/pi/CaravanPi/analogSignals/v230Check.py >/home/pi/CaravanPi/.log/v230Check.log 2>&1
@reboot sleep 350 && python3 -u /home/pi/CaravanPi/analogSignals/v230Check.py -s >/home/pi/CaravanPi/.log/v230Check.log 2>&1

# 12V Eingang überwachen
#@reboot python3 -u /home/pi/CaravanPi/analogSignals/v12Check.py -b "car" >/home/pi/CaravanPi/.log/v12Check.log 2>&1
@reboot python3 -u /home/pi/CaravanPi/analogSignals/v12Check.py -b "bord" >/home/pi/CaravanPi/.log/v12Check.log 2>&1
# @reboot sleep 360 && python3 -u /home/pi/CaravanPi/analogSignals/v12Check.py -b "car" -s >/home/pi/CaravanPi/.log/v12Check.log 2>&1
@reboot sleep 370 && python3 -u /home/pi/CaravanPi/analogSignals/v12Check.py -b "bord" -s >/home/pi/CaravanPi/.log/v12Check.log 2>&1

# Zeit zwischen StromPi und Raspberry Pi synchronisieren
@reboot python /home/pi/StromPi3/RTCSerial.py >/home/pi/CaravanPi/.log/StromPi-RTC-sync.log 2>&1
# @reboot sleep 380 && python /home/pi/StromPi3/RTCSerial.py >/home/pi/CaravanPi/.log/StromPi-RTC-sync.log 2>&1
37 changes: 33 additions & 4 deletions .git_hooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ CRONTABS_DIR="/home/pi/CaravanPi/.crontabs"

# Backup-Funktion
backup_files() {
cp "$1" "$BACKUP_DIR/$(basename $1).backup"
cp "$1" "$BACKUP_DIR/$(basename $1).backup"
}

# Dateien vor der Bearbeitung sichern
Expand All @@ -20,9 +20,38 @@ backup_files "$README_MD"

# Funktion, um die Dateien zu bearbeiten (wie zuvor)
update_files() {
sed -i 's/<MariaDBpasswd>[^<]*<\/MariaDBpasswd>/<MariaDBpasswd>dasGeheimePasswort<\/MariaDBpasswd>/' "$1"
sed -i 's/<MQTTpassword>[^<]*<\/MQTTpassword>/<MQTTpassword>dasGeheimePasswort<\/MQTTpassword>/' "$1"
sed -i 's/<MQTTbroker>[^<]*<\/MQTTbroker>/<MQTTbroker>MQTTBrokerWebAdresse<\/MQTTbroker>/' "$1"
sed -i 's/<countGasScales>[^<]*<\/countGasScales>/<countGasScales>0<\/countGasScales>/' "$1"
sed -i 's/<countTanks>[^<]*<\/countTanks>/<countTanks>0<\/countTanks>/' "$1"
sed -i 's/<countClimateSensors>[^<]*<\/countClimateSensors>/<countClimateSensors>0<\/countClimateSensors>/' "$1"

sed -i 's/<write2file>[^<]*<\/write2file>/<write2file>1<\/write2file>/' "$1"

sed -i 's/<write2MariaDB>[^<]*<\/write2MariaDB>/<write2MariaDB>0<\/write2MariaDB>/' "$1"
sed -i 's/<MariaDBpasswd>[^<]*<\/MariaDBpasswd>/<MariaDBpasswd>dasGeheimePasswort<\/MariaDBpasswd>/' "$1"

sed -i 's/<send2MQTT>[^<]*<\/send2MQTT>/<send2MQTT>0<\/send2MQTT>/' "$1"
sed -i 's/<MQTTpassword>[^<]*<\/MQTTpassword>/<MQTTpassword>dasGeheimePasswort<\/MQTTpassword>/' "$1"
sed -i 's/<MQTTbroker>[^<]*<\/MQTTbroker>/<MQTTbroker>MQTTBrokerWebAdresse<\/MQTTbroker>/' "$1"

sed -i 's/<stromPiInstalled>[^<]*<\/stromPiInstalled>/<stromPiInstalled>0<\/stromPiInstalled>/' "$1"

sed -i 's/<gassensorInstalled>[^<]*<\/gassensorInstalled>/<gassensorInstalled>0<\/gassensorInstalled>/' "$1"
sed -i 's/<gassensorAlarmActive>[^<]*<\/gassensorAlarmActive>/<gassensorAlarmActive>0<\/gassensorAlarmActive>/' "$1"
sed -i 's/<gassensorAlarmResume>[^<]*<\/gassensorAlarmResume>/<gassensorAlarmResume>0<\/gassensorAlarmResume>/' "$1"

sed -i 's/<v230CheckInstalled>[^<]*<\/v230CheckInstalled>/<v230CheckInstalled>0<\/v230CheckInstalled>/' "$1"
sed -i 's/<v230CheckAlarmActive>[^<]*<\/v230CheckAlarmActive>/<v230CheckAlarmActive>0<\/v230CheckAlarmActive>/' "$1"
sed -i 's/<v230CheckAlarmResume>[^<]*<\/v230CheckAlarmResume>/<v230CheckAlarmResume>0<\/v230CheckAlarmResume>/' "$1"

sed -i 's/<v12BatteryCheckInstalled>[^<]*<\/v12BatteryCheckInstalled>/<v12BatteryCheckInstalled>0<\/v12BatteryCheckInstalled>/' "$1"
sed -i 's/<v12BatteryCheckAlarmActive>[^<]*<\/v12BatteryCheckAlarmActive>/<v12BatteryCheckAlarmActive>0<\/v12BatteryCheckAlarmActive>/' "$1"
sed -i 's/<v12BatteryCheckAlarmResume>[^<]*<\/v12BatteryCheckAlarmResume>/<v12BatteryCheckAlarmResume>0<\/v12BatteryCheckAlarmResume>/' "$1"

sed -i 's/<v12CarCheckInstalled>[^<]*<\/v12CarCheckInstalled>/<v12CarCheckInstalled>0<\/v12CarCheckInstalled>/' "$1"
sed -i 's/<v12CarCheckAlarmActive>[^<]*<\/v12CarCheckAlarmActive>/<v12CarCheckAlarmActive>0<\/v12CarCheckAlarmActive>/' "$1"
sed -i 's/<v12CarCheckAlarmResume>[^<]*<\/v12CarCheckAlarmResume>/<v12CarCheckAlarmResume>0<\/v12CarCheckAlarmResume>/' "$1"

sed -i 's/<LiontronMACAddress>[^<]*<\/LiontronMACAddress>/<LiontronMACAddress>00:00:00:00:00:00<\/LiontronMACAddress>/' "$1"
}

# Dateien aktualisieren
Expand Down
2 changes: 2 additions & 0 deletions .lib/CaravanPiFilesClass.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,8 @@ def create_db_connection(self):
# zunächst die Defaultwerte in der Default xml lesen
self.update_settings()

# print(f"Host: {self.MariaDBhost}, User: {self.MariaDBuser}, Passwd: {self.MariaDBpasswd}, Database: {self.MariaDBdatabase}")

connection = None
try:
connection = mysql.connector.connect(
Expand Down
8 changes: 8 additions & 0 deletions .splashScreen/CaravanPi.plymouth
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[Plymouth Theme]
Name=CaravanPi
Description=CaravanPi Splash
ModuleName=script

[script]
ImageDir=/usr/share/plymouth/themes/CaravanPi
ScriptFile=/usr/share/plymouth/themes/CaravanPi/CaravanPi.script
53 changes: 53 additions & 0 deletions .splashScreen/CaravanPi.script
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
screen_width = Window.GetWidth();
screen_height = Window.GetHeight();

if (Plymouth.GetMode() != "shutdown")
{
theme_image = Image("splash.png");
}
else
{
theme_image = Image("splash_halt.png");
}

image_width = theme_image.GetWidth();
image_height = theme_image.GetHeight();

scale_x = image_width / screen_width;
scale_y = image_height / screen_height;

if (scale_x > 1 || scale_y > 1)
{
if (scale_x > scale_y)
{
resized_image = theme_image.Scale (screen_width, image_height / scale_x);
image_x = 0;
image_y = (screen_height - ((image_height * screen_width) / image_width)) / 2;
}
else
{
resized_image = theme_image.Scale (image_width / scale_y, screen_height);
image_x = (screen_width - ((image_width * screen_height) / image_height)) / 2;
image_y = 0;
}
}
else
{
resized_image = theme_image.Scale (image_width, image_height);
image_x = (screen_width - image_width) / 2;
image_y = (screen_height - image_height) / 2;
}

sprite = Sprite (resized_image);
sprite.SetPosition (image_x, image_y, -100);

message_sprite = Sprite();
message_sprite.SetPosition(screen_width * 0.1, screen_height * 0.9, 10000);

fun message_callback (text) {
my_image = Image.Text(text, 1, 1, 1);
message_sprite.SetImage(my_image);
sprite.SetImage (resized_image);
}

Plymouth.SetUpdateStatusFunction(message_callback);
Binary file added .splashScreen/splash-only-hg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .splashScreen/splash-with-hg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .splashScreen/splash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
76 changes: 76 additions & 0 deletions StromPi3/RTCSerial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import serial
import threading
from time import sleep
import time
import datetime
import os

serial_port = serial.Serial()

serial_port.baudrate = 38400
serial_port.port = '/dev/serial0'
serial_port.timeout = 1
serial_port.bytesize = 8
serial_port.stopbits = 1
serial_port.parity = serial.PARITY_NONE


if serial_port.isOpen(): serial_port.close()
serial_port.open()


try:
serial_port.write(str.encode('Q'))
sleep(1)
serial_port.write(str.encode('\x0D'))
sleep(1)
serial_port.write(str.encode('date-rpi'))
sleep(0.1)
serial_port.write(str.encode('\x0D'))
data = serial_port.read(9999);
date = int(data)

strompi_year = date // 10000
strompi_month = date % 10000 // 100
strompi_day = date % 100

sleep(0.1)
serial_port.write(str.encode('time-rpi'))
sleep(0.1)
serial_port.write(str.encode('\x0D'))
data = serial_port.read(9999);
timevalue = int(data)

strompi_hour = timevalue // 10000
strompi_min = timevalue % 10000 // 100
strompi_sec = timevalue % 100

rpi_time = datetime.datetime.now().replace(microsecond=0)
strompi_time = datetime.datetime(2000 + strompi_year, strompi_month, strompi_day, strompi_hour, strompi_min, strompi_sec, 0)

command = 'set-time %02d %02d %02d' % (int(rpi_time.strftime('%H')),int(rpi_time.strftime('%M')),int(rpi_time.strftime('%S')))

if rpi_time > strompi_time:
serial_port.write(str.encode('set-date %02d %02d %02d %02d' % (int(rpi_time.strftime('%d')),int(rpi_time.strftime('%m')),int(rpi_time.strftime('%Y'))%100,int(rpi_time.isoweekday()))))
sleep(0.5)
serial_port.write(str.encode('\x0D'))
sleep(1)
serial_port.write(str.encode('set-clock %02d %02d %02d' % (int(rpi_time.strftime('%H')),int(rpi_time.strftime('%M')),int(rpi_time.strftime('%S')))))
sleep(0.5)
serial_port.write(str.encode('\x0D'))

print ('-----------------------------------------')
print ('The date und time has been synced: Raspberry Pi -> StromPi')
print ('-----------------------------------------')

else:
os.system('sudo date +%%y%%m%%d --set=%02d%02d%02d' % (strompi_year, strompi_month, strompi_day))
os.system('sudo date +%%T -s "%02d:%02d:%02d"' % (strompi_hour, strompi_min, strompi_sec))
print ('-----------------------------------------')
print ('The date und time has been synced: StromPi -> Raspberry Pi')
print ('-----------------------------------------')

except KeyboardInterrupt:
print('interrupted!')

serial_port.close()
Loading

0 comments on commit 369d053

Please sign in to comment.