diff --git a/.crontabs/crontab-pi b/.crontabs/crontab-pi index 27a2344..79357eb 100644 --- a/.crontabs/crontab-pi +++ b/.crontabs/crontab-pi @@ -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 diff --git a/.git_hooks/pre-commit b/.git_hooks/pre-commit index 978a43e..d22c1ad 100755 --- a/.git_hooks/pre-commit +++ b/.git_hooks/pre-commit @@ -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 @@ -20,9 +20,38 @@ backup_files "$README_MD" # Funktion, um die Dateien zu bearbeiten (wie zuvor) update_files() { - sed -i 's/[^<]*<\/MariaDBpasswd>/dasGeheimePasswort<\/MariaDBpasswd>/' "$1" - sed -i 's/[^<]*<\/MQTTpassword>/dasGeheimePasswort<\/MQTTpassword>/' "$1" - sed -i 's/[^<]*<\/MQTTbroker>/MQTTBrokerWebAdresse<\/MQTTbroker>/' "$1" + sed -i 's/[^<]*<\/countGasScales>/0<\/countGasScales>/' "$1" + sed -i 's/[^<]*<\/countTanks>/0<\/countTanks>/' "$1" + sed -i 's/[^<]*<\/countClimateSensors>/0<\/countClimateSensors>/' "$1" + + sed -i 's/[^<]*<\/write2file>/1<\/write2file>/' "$1" + + sed -i 's/[^<]*<\/write2MariaDB>/0<\/write2MariaDB>/' "$1" + sed -i 's/[^<]*<\/MariaDBpasswd>/dasGeheimePasswort<\/MariaDBpasswd>/' "$1" + + sed -i 's/[^<]*<\/send2MQTT>/0<\/send2MQTT>/' "$1" + sed -i 's/[^<]*<\/MQTTpassword>/dasGeheimePasswort<\/MQTTpassword>/' "$1" + sed -i 's/[^<]*<\/MQTTbroker>/MQTTBrokerWebAdresse<\/MQTTbroker>/' "$1" + + sed -i 's/[^<]*<\/stromPiInstalled>/0<\/stromPiInstalled>/' "$1" + + sed -i 's/[^<]*<\/gassensorInstalled>/0<\/gassensorInstalled>/' "$1" + sed -i 's/[^<]*<\/gassensorAlarmActive>/0<\/gassensorAlarmActive>/' "$1" + sed -i 's/[^<]*<\/gassensorAlarmResume>/0<\/gassensorAlarmResume>/' "$1" + + sed -i 's/[^<]*<\/v230CheckInstalled>/0<\/v230CheckInstalled>/' "$1" + sed -i 's/[^<]*<\/v230CheckAlarmActive>/0<\/v230CheckAlarmActive>/' "$1" + sed -i 's/[^<]*<\/v230CheckAlarmResume>/0<\/v230CheckAlarmResume>/' "$1" + + sed -i 's/[^<]*<\/v12BatteryCheckInstalled>/0<\/v12BatteryCheckInstalled>/' "$1" + sed -i 's/[^<]*<\/v12BatteryCheckAlarmActive>/0<\/v12BatteryCheckAlarmActive>/' "$1" + sed -i 's/[^<]*<\/v12BatteryCheckAlarmResume>/0<\/v12BatteryCheckAlarmResume>/' "$1" + + sed -i 's/[^<]*<\/v12CarCheckInstalled>/0<\/v12CarCheckInstalled>/' "$1" + sed -i 's/[^<]*<\/v12CarCheckAlarmActive>/0<\/v12CarCheckAlarmActive>/' "$1" + sed -i 's/[^<]*<\/v12CarCheckAlarmResume>/0<\/v12CarCheckAlarmResume>/' "$1" + + sed -i 's/[^<]*<\/LiontronMACAddress>/00:00:00:00:00:00<\/LiontronMACAddress>/' "$1" } # Dateien aktualisieren diff --git a/.lib/CaravanPiFilesClass.py b/.lib/CaravanPiFilesClass.py index 1d95826..606df2b 100644 --- a/.lib/CaravanPiFilesClass.py +++ b/.lib/CaravanPiFilesClass.py @@ -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( diff --git a/.splashScreen/CaravanPi.plymouth b/.splashScreen/CaravanPi.plymouth new file mode 100644 index 0000000..b6180f0 --- /dev/null +++ b/.splashScreen/CaravanPi.plymouth @@ -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 diff --git a/.splashScreen/CaravanPi.script b/.splashScreen/CaravanPi.script new file mode 100644 index 0000000..6e2f564 --- /dev/null +++ b/.splashScreen/CaravanPi.script @@ -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); diff --git a/.splashScreen/splash-only-hg.png b/.splashScreen/splash-only-hg.png new file mode 100644 index 0000000..f7db836 Binary files /dev/null and b/.splashScreen/splash-only-hg.png differ diff --git a/.splashScreen/splash-with-hg.png b/.splashScreen/splash-with-hg.png new file mode 100644 index 0000000..4efb768 Binary files /dev/null and b/.splashScreen/splash-with-hg.png differ diff --git a/.splashScreen/splash.png b/.splashScreen/splash.png new file mode 100644 index 0000000..fb56d90 Binary files /dev/null and b/.splashScreen/splash.png differ diff --git a/StromPi3/RB-StromPi3-strompi_config_gui_anleitung.pdf b/StromPi3/RB-StromPi3-strompi_config_gui_anleitung.pdf new file mode 100644 index 0000000..e9affe1 Binary files /dev/null and b/StromPi3/RB-StromPi3-strompi_config_gui_anleitung.pdf differ diff --git a/StromPi3/RTCSerial.py b/StromPi3/RTCSerial.py new file mode 100644 index 0000000..478de3c --- /dev/null +++ b/StromPi3/RTCSerial.py @@ -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() \ No newline at end of file diff --git a/StromPi3/StromPi3_Status.py b/StromPi3/StromPi3_Status.py new file mode 100644 index 0000000..65cbc77 --- /dev/null +++ b/StromPi3/StromPi3_Status.py @@ -0,0 +1,243 @@ +import serial +from time import sleep +import datetime +import os +import time +from time import sleep + +wide_range_volt_min = 4.8 +battery_volt_min = 0.5 +mUSB_volt_min = 4.1 + +breakS = 0.1 +breakL = 0.5 + +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() + +####################################################################################################################### + +def enabled_disabled_converter(argument): + switcher = { + 0: 'Disabled', + 1: 'Enabled', + } + return switcher.get(argument, 'nothing') + +def weekday_converter(argument): + switcher = { + 1: 'Monday', + 2: 'Tuesday', + 3: 'Wednesday', + 4: 'Thursday', + 5: 'Friday', + 6: 'Saturday', + 7: 'Sunday', + } + return switcher.get(argument, 'nothing') + +def strompi_mode_converter(argument): + switcher = { + 1: 'mUSB -> Wide', + 2: 'Wide -> mUSB', + 3: 'mUSB -> Battery', + 4: 'Wide -> Battery', + 5: "mUSB -> Wide -> Battery", + 6: "Wide -> mUSB -> Battery", + } + return switcher.get(argument, 'nothing') + +def alarm_mode_converter(argument): + switcher = { + 1: 'Time-Alarm', + 2: 'Date-Alarm', + 3: 'Weekday-Alarm', + } + return switcher.get(argument, 'nothing') + +def batterylevel_shutdown_converter(argument): + switcher = { + 0: 'Disabled', + 1: '10%', + 2: '25%', + 3: '50%', + } + return switcher.get(argument, 'nothing') + +def output_status_converter(argument): + switcher = { + 0: 'Power-Off', #only for Debugging-Purposes + 1: 'mUSB', + 2: 'Wide', + 3: 'Battery', + } + return switcher.get(argument, 'nothing') + + +def batterylevel_converter(batterylevel,charging): + + if charging: + switcher = { + 1: ' [10%] [charging]', + 2: ' [25%] [charging]', + 3: ' [50%] [charging]', + 4: ' [100%] [charging]', + } + return switcher.get(batterylevel, 'nothing') + else: + switcher = { + 1: ' [10%]', + 2: ' [25%]', + 3: ' [50%]', + 4: ' [100%]', + } + return switcher.get(batterylevel, 'nothing') + +####################################################################################################################### +serial_port.write(str.encode('quit')) +sleep(breakS) +serial_port.write(str.encode('\x0D')) +sleep(breakL) + +serial_port.write(str.encode('status-rpi')) +sleep(1) +serial_port.write(str.encode('\x0D')) +sp3_time = serial_port.readline(9999); +sp3_date = serial_port.readline(9999); +sp3_weekday = serial_port.readline(9999); +sp3_modus = serial_port.readline(9999); +sp3_alarm_enable = serial_port.readline(9999); +sp3_alarm_mode = serial_port.readline(9999); +sp3_alarm_hour = serial_port.readline(9999); +sp3_alarm_min = serial_port.readline(9999); +sp3_alarm_day = serial_port.readline(9999); +sp3_alarm_month = serial_port.readline(9999); +sp3_alarm_weekday = serial_port.readline(9999); +sp3_alarmPoweroff = serial_port.readline(9999); +sp3_alarm_hour_off = serial_port.readline(9999); +sp3_alarm_min_off = serial_port.readline(9999); +sp3_shutdown_enable = serial_port.readline(9999); +sp3_shutdown_time = serial_port.readline(9999); +sp3_warning_enable = serial_port.readline(9999); +sp3_serialLessMode = serial_port.readline(9999); +sp3_intervalAlarm = serial_port.readline(9999); +sp3_intervalAlarmOnTime = serial_port.readline(9999); +sp3_intervalAlarmOffTime = serial_port.readline(9999); +sp3_batLevel_shutdown = serial_port.readline(9999); +sp3_batLevel = serial_port.readline(9999); +sp3_charging = serial_port.readline(9999); +sp3_powerOnButton_enable = serial_port.readline(9999); +sp3_powerOnButton_time = serial_port.readline(9999); +sp3_powersave_enable = serial_port.readline(9999); +sp3_poweroffMode = serial_port.readline(9999); +sp3_poweroff_time_enable = serial_port.readline(9999); +sp3_poweroff_time = serial_port.readline(9999); +sp3_wakeupweekend_enable = serial_port.readline(9999); +sp3_ADC_Wide = float(serial_port.readline(9999))/1000; +sp3_ADC_BAT = float(serial_port.readline(9999))/1000; +sp3_ADC_USB = float(serial_port.readline(9999))/1000; +sp3_ADC_OUTPUT = float(serial_port.readline(9999))/1000; +sp3_output_status = serial_port.readline(9999); +sp3_powerfailure_counter = serial_port.readline(9999); +sp3_firmwareVersion = serial_port.readline(9999); + +date = int(sp3_date) + +strompi_year = int(sp3_date) // 10000 +strompi_month = int(sp3_date) % 10000 // 100 +strompi_day = int(sp3_date) % 100 + +strompi_hour = int(sp3_time) // 10000 +strompi_min = int(sp3_time) % 10000 // 100 +strompi_sec = int(sp3_time) % 100 + +try: + if sp3_ADC_Wide > wide_range_volt_min: + wide_range_volt = str(sp3_ADC_Wide) + 'V' + else: + wide_range_volt = ' not connected' + + if sp3_ADC_BAT > battery_volt_min: + battery_volt = str(sp3_ADC_BAT) + 'V' + batterylevel_converter(int(sp3_batLevel),int(sp3_charging)) + else: + battery_volt = ' not connected' + + if sp3_ADC_USB > mUSB_volt_min: + microUSB_volt = str(sp3_ADC_USB) + 'V' + else: + microUSB_volt = ' not connected' + + output_volt = str(sp3_ADC_OUTPUT) + 'V' + + print(' ') + print('---------------------------------') + print('StromPi-Status:') + print('---------------------------------') + print('Time: ' + str(strompi_hour).zfill(2) + ':' + str(strompi_min).zfill(2) + ':' + str(strompi_sec).zfill(2)) + print('Date: ' + weekday_converter(int(sp3_weekday)) + ' ' + str(strompi_day).zfill(2) + '.' + str(strompi_month).zfill(2) + '.' + str(strompi_year).zfill(2)) + print(' ') + print('StromPi-Output: ' + output_status_converter((int(sp3_output_status)))) + print(' ') + print('StromPi-Mode: ' + strompi_mode_converter((int(sp3_modus)))) + print(' ') + print('Raspberry Pi Shutdown: ' + enabled_disabled_converter(int(sp3_shutdown_enable))) + print(' Shutdown-Timer: ' + str(sp3_shutdown_time, 'utf-8').rstrip('\n').zfill(2) + ' seconds') + print(' ') + print('Powerfail Warning: ' + enabled_disabled_converter(int(sp3_warning_enable))) + print(' ') + print('Serial-Less Mode: ' + enabled_disabled_converter(int(sp3_serialLessMode))) + print(' ') + print('Power Save Mode: ' + enabled_disabled_converter(int(sp3_powersave_enable))) + print(' ') + print('PowerOn-Button: ' + enabled_disabled_converter(int(sp3_powerOnButton_enable))) + print(' ') + print(' PowerOn-Button-Timer: ' + str(sp3_powerOnButton_time, 'utf-8').rstrip('\n').zfill(2) + ' seconds') + print(' ') + print('Battery-Level Shutdown: ' + batterylevel_shutdown_converter(int(sp3_batLevel_shutdown))) + print(' ') + print('Powerfail-Counter: ' + str(sp3_powerfailure_counter, 'utf-8').rstrip('\n')) + print(' ') + print('PowerOff Mode: ' + enabled_disabled_converter(int(sp3_poweroffMode))) + print('---------------------------------') + print('Alarm-Configuration:') + print('---------------------------------') + print('WakeUp-Alarm: ' + enabled_disabled_converter(int(sp3_alarm_enable))) + if int(sp3_poweroff_time_enable) == 1: + print (' Alarm-Mode: Minute WakeUp-Alarm') + elif int(sp3_alarm_mode) > 0 and int(sp3_alarm_mode) < 4: + print(' Alarm-Mode: ' + alarm_mode_converter(int(sp3_alarm_mode))) + print(' Alarm-Time: ' + str(sp3_alarm_hour, 'utf-8').rstrip('\n').zfill(2) + ':' + str(sp3_alarm_min, 'utf-8').rstrip('\n').zfill(2)) + print(' Alarm-Date: ' + str(sp3_alarm_day, 'utf-8').rstrip('\n').zfill(2) + '.' + str(sp3_alarm_month, 'utf-8').rstrip('\n').zfill(2)) + print(' WakeUp-Alarm: ' + weekday_converter(int(sp3_alarm_weekday))) + print(' Weekend Wakeup: ' + enabled_disabled_converter(int(sp3_wakeupweekend_enable))) + print(' Minute Wakeup Timer: ' + str(sp3_poweroff_time, 'utf-8').rstrip('\n').zfill(2) + ' minutes ') + print(' ') + print('PowerOff-Alarm: ' + enabled_disabled_converter(int(sp3_alarmPoweroff))) + print(' PowerOff-Alarm-Time: ' + str(sp3_alarm_hour_off, 'utf-8').rstrip('\n').zfill(2) + ':' + str(sp3_alarm_min_off, 'utf-8').rstrip('\n').zfill(2)) + print(' ') + print('Interval-Alarm: ' + enabled_disabled_converter(int(sp3_intervalAlarm))) + print(' Interval-On-Time: ' + str(sp3_intervalAlarmOnTime, 'utf-8').rstrip('\n').zfill(2) + ' minutes') + print(' Interval-Off-Time: ' + str(sp3_intervalAlarmOffTime, 'utf-8').rstrip('\n').zfill(2) + ' minutes') + print(' ') + print('---------------------------------') + print('Voltage-Levels:') + print('---------------------------------') + print('Wide-Range-Inputvoltage: ' + wide_range_volt) + print('LifePo4-Batteryvoltage: ' + battery_volt) + print('microUSB-Inputvoltage: ' + microUSB_volt) + print('Output-Voltage: ' + output_volt) + print(' ') + +except KeyboardInterrupt: + print('interrupted!') + +serial_port.close() \ No newline at end of file diff --git a/StromPi3/fan_control_de.py b/StromPi3/fan_control_de.py new file mode 100644 index 0000000..33e685e --- /dev/null +++ b/StromPi3/fan_control_de.py @@ -0,0 +1,40 @@ +from gpiozero import CPUTemperature, PWMLED +from time import sleep + +led = PWMLED(2) # PWM-Pin (GPIO 2) + +startTemp = 55 # Temperatur bei der der Luefter an geht + +pTemp = 4 # Proportionalanteil +iTemp = 0.2 # Integralanteil + +fanSpeed = 0 # Lueftergeschwindigkeit +sum = 0 # Speichervariable fuer iAnteil + + +while True: # Regelschleife + cpu = CPUTemperature() # Auslesen der aktuellen Temperaturwerte + actTemp = cpu.temperature # Aktuelle Temperatur als float-Variable + + diff = actTemp - startTemp + sum = sum + diff + pDiff = diff * pTemp + iDiff = sum * iTemp + fanSpeed = pDiff + iDiff + 35 + + + if fanSpeed > 100: + fanSpeed = 100 + elif fanSpeed < 35: + fanSpeed = 0 + + if sum > 100: + sum = 100 + elif sum < -100: + sum = -100 + + #print(str(actTemp) + "C, " + str(fanSpeed)) + + led.value = fanSpeed / 100 # PWM Ausgabe + + sleep(1) \ No newline at end of file diff --git a/StromPi3/favicon.png b/StromPi3/favicon.png new file mode 100644 index 0000000..f36a98f Binary files /dev/null and b/StromPi3/favicon.png differ diff --git a/StromPi3/logo.gif b/StromPi3/logo.gif new file mode 100644 index 0000000..2762ec1 Binary files /dev/null and b/StromPi3/logo.gif differ diff --git a/StromPi3/poweralarm_serial.py b/StromPi3/poweralarm_serial.py new file mode 100644 index 0000000..ac556c0 --- /dev/null +++ b/StromPi3/poweralarm_serial.py @@ -0,0 +1,165 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +import RPi.GPIO as GPIO +import time +import serial +import os +import smtplib +from email.mime.text import MIMEText +############################################################################## +# This is The config for the EMAIL notification +############################################################################## +SERVER = 'SMTP.Server.Com' +PORT = 587 +EMAIL = 'Example@Example.com' +PASSWORT = 'Password' +EMPFAENGER = ['Empfänger@Example.com' ,] +SUBJECT_Powerfail = 'Raspberry Pi Powerfail!' #Powerfail Email Betreff +SUBJECT_Powerback = 'Raspberry Pi Powerback!' #Powerback Email Betreff +SUBJECT_Restart = 'Raspberry Pi Restart!' #Restart Email Betreff +############################################################################## +# Here you can choose whether you want to receive an email when the Raspberry Pi restarts - 1 to activate - 0 to deactivate +Restart_Mail = 0 +############################################################################## +t=0 #Temporary time-variable +############################################################################## + +def Detect_Powerfail(): + while 1: + x=ser.readline() + y = x.decode(encoding='UTF-8',errors='strict') + if y==('xxxShutdownRaspberryPixxx\n') or y==('xxx--StromPiPowerfail--xxx\n'): + print ("PowerFail - Email Sent") + Sendmail_Powerfail() + +def Sendmail_Powerback(): + BODY = """ + + + + + + + + +
StromPi hat Spannung wiedererkannt!
+ + + """ + + session = smtplib.SMTP(SERVER, PORT) + session.set_debuglevel(1) + session.ehlo() + session.starttls() + session.ehlo + session.login(EMAIL, PASSWORT) + msg = MIMEText(BODY, 'html') + msg['Subject'] = SUBJECT_Powerback + msg['From'] = EMAIL + msg['To'] = ", ".join(EMPFAENGER) + session.sendmail(EMAIL, EMPFAENGER, msg.as_string()) + Detect_Powerfail() + +def Sendmail_Restart(): + BODY = """ + + + + + + + + +
Ihr Raspberry Pi wurde neugestartet.
+ + + """ + + session = smtplib.SMTP(SERVER, PORT) + session.set_debuglevel(1) + session.ehlo() + session.starttls() + session.ehlo + session.login(EMAIL, PASSWORT) + msg = MIMEText(BODY, 'html') + msg['Subject'] = SUBJECT_Restart + msg['From'] = EMAIL + msg['To'] = ", ".join(EMPFAENGER) + session.sendmail(EMAIL, EMPFAENGER, msg.as_string()) + Detect_Powerfail() + +def Sendmail_Powerfail(): + BODY = """ + + + + + + + + +
StromPi hat einen STROMAUSFALL erkannt!!!!
+ + + """ + + session = smtplib.SMTP(SERVER, PORT) + session.set_debuglevel(1) + session.ehlo() + session.starttls() + session.ehlo + session.login(EMAIL, PASSWORT) + msg = MIMEText(BODY, 'html') + msg['Subject'] = SUBJECT_Powerfail + msg['From'] = EMAIL + msg['To'] = ", ".join(EMPFAENGER) + session.sendmail(EMAIL, EMPFAENGER, msg.as_string()) + Detect_Powerback() + +def Detect_Powerback(): + while 1: + x=ser.readline() + y=x.decode(encoding='UTF-8',errors='strict') + if y==('xxx--StromPiPowerBack--xxx\n'): + print ("PowerBack - Email Sent") + Sendmail_Powerback() + +ser = serial.Serial( + port='/dev/serial0', + baudrate = 38400, + parity=serial.PARITY_NONE, + stopbits=serial.STOPBITS_ONE, + bytesize=serial.EIGHTBITS, + timeout=1 +) +counter=0 + +time.sleep(5) +if Restart_Mail == 1: + Sendmail_Restart() + + + + + + + +Detect_Powerfail() diff --git a/StromPi3/serialShutdown.py b/StromPi3/serialShutdown.py index c74bf5d..ce318e6 100644 --- a/StromPi3/serialShutdown.py +++ b/StromPi3/serialShutdown.py @@ -1,8 +1,6 @@ #!/usr/bin/env python import serial import os -import time -import sys ############################################################################## #Hier muss der wait_for_shutdowntimer eingestellt werden - dieser wartet mit dem Herunterfahren des Raspberry Pi, # fuer den Fall dass die primaere Stromquelle wiederhergesttelt werden sollte @@ -18,18 +16,6 @@ t=0 #Temporary time-variable -os.system('sudo date') -print ('StromPi - serial shutdown Skript started') -print ('-----------------------------------------') -print ('wait to bring up all things') -sys.stdout.flush() - -time.sleep(90) - -os.system('sudo date') -print ('start serial ...') -sys.stdout.flush() - ser = serial.Serial( port='/dev/serial0', baudrate = 38400, @@ -40,28 +26,18 @@ ) counter=0 -os.system('sudo date') -print ('enter loop') -sys.stdout.flush() - while 1: x=ser.readline() y = x.decode(encoding='UTF-8',errors='strict') - if y==('xxxShutdownRaspberryPixxx\n'): - os.system('sudo date') - print ("PowerFail - Raspberry Pi Shutdown") - sys.stdout.flush() - t= wait_for_shutdowntimer + 1 - elif y==('xxx--StromPiPowerBack--xxx\n'): - os.system('sudo date') + if y != "": + print(y) + if y.find('xxx--StromPiPowerBack--xxx\n') != -1: print ("PowerBack - Raspberry Pi Shutdown aborted") - sys.stdout.flush() t=0 + elif y.find('xxxShutdownRaspberryPixxx\n') != -1: + print ("PowerFail - Raspberry Pi Shutdown") + t= wait_for_shutdowntimer + 1 if t>0: t-=1 if t == 1: - os.system('sudo date') - print ("shutdown Raspberry Pi in 1 second") - sys.stdout.flush() - time.sleep(1) - os.system("sudo shutdown -h now") \ No newline at end of file + os.system("sudo shutdown -h now") diff --git a/StromPi3/strompi_config.py b/StromPi3/strompi_config.py new file mode 100644 index 0000000..2f10f07 --- /dev/null +++ b/StromPi3/strompi_config.py @@ -0,0 +1,1005 @@ +import serial +from time import sleep +import datetime +import os +import time +from time import sleep + +wide_range_volt_min = 4.8 +battery_volt_min = 0.5 +mUSB_volt_min = 4.1 + +breakS = 0.1 +breakL = 0.5 + +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() + +####################################################################################################################### + +def enabled_disabled_converter(argument): + switcher = { + 0: 'Disabled', + 1: 'Enabled', + } + return switcher.get(argument, 'nothing') + +def weekday_converter(argument): + switcher = { + 1: 'Monday', + 2: 'Tuesday', + 3: 'Wednesday', + 4: 'Thursday', + 5: 'Friday', + 6: 'Saturday', + 7: 'Sunday', + } + return switcher.get(argument, 'nothing') + +def strompi_mode_converter(argument): + switcher = { + 1: 'mUSB -> Wide', + 2: 'Wide -> mUSB', + 3: 'mUSB -> Battery', + 4: 'Wide -> Battery', + 5: "mUSB -> Wide -> Battery", + 6: "Wide -> mUSB -> Battery", + } + return switcher.get(argument, 'nothing') + +def alarm_mode_converter(argument): + switcher = { + 1: 'Time-Alarm', + 2: 'Date-Alarm', + 3: 'Weekday-Alarm', + 4: 'Wakeup Timer', + } + return switcher.get(argument, 'nothing') + +def batterylevel_shutdown_converter(argument): + switcher = { + 0: 'Disabled', + 1: '10%', + 2: '25%', + 3: '50%', + } + return switcher.get(argument, 'nothing') + +def output_status_converter(argument): + switcher = { + 0: 'Power-Off', #only for Debugging-Purposes + 1: 'mUSB', + 2: 'Wide', + 3: 'Battery', + } + return switcher.get(argument, 'nothing') + + +def batterylevel_converter(batterylevel,charging): + + if charging: + switcher = { + 1: ' [10%] [charging]', + 2: ' [25%] [charging]', + 3: ' [50%] [charging]', + 4: ' [100%] [charging]', + } + return switcher.get(batterylevel, 'nothing') + else: + switcher = { + 1: ' [10%]', + 2: ' [25%]', + 3: ' [50%]', + 4: ' [100%]', + } + return switcher.get(batterylevel, 'nothing') + +####################################################################################################################### +serial_port.write(str.encode('quit')) +sleep(breakS) +serial_port.write(str.encode('\x0D')) +sleep(breakL) + +serial_port.write(str.encode('status-rpi')) +sleep(1) +serial_port.write(str.encode('\x0D')) +sp3_time = serial_port.readline(9999); +sp3_date = serial_port.readline(9999); +sp3_weekday = serial_port.readline(9999); +sp3_modus = serial_port.readline(9999); +sp3_alarm_enable = serial_port.readline(9999); +sp3_alarm_mode = serial_port.readline(9999); +sp3_alarm_hour = serial_port.readline(9999); +sp3_alarm_min = serial_port.readline(9999); +sp3_alarm_day = serial_port.readline(9999); +sp3_alarm_month = serial_port.readline(9999); +sp3_alarm_weekday = serial_port.readline(9999); +sp3_alarmPoweroff = serial_port.readline(9999); +sp3_alarm_hour_off = serial_port.readline(9999); +sp3_alarm_min_off = serial_port.readline(9999); +sp3_shutdown_enable = serial_port.readline(9999); +sp3_shutdown_time = serial_port.readline(9999); +sp3_warning_enable = serial_port.readline(9999); +sp3_serialLessMode = serial_port.readline(9999); +sp3_intervalAlarm = serial_port.readline(9999); +sp3_intervalAlarmOnTime = serial_port.readline(9999); +sp3_intervalAlarmOffTime = serial_port.readline(9999); +sp3_batLevel_shutdown = serial_port.readline(9999); +sp3_batLevel = serial_port.readline(9999); +sp3_charging = serial_port.readline(9999); +sp3_powerOnButton_enable = serial_port.readline(9999); +sp3_powerOnButton_time = serial_port.readline(9999); +sp3_powersave_enable = serial_port.readline(9999); +sp3_poweroffMode = serial_port.readline(9999); +sp3_poweroff_time_enable = serial_port.readline(9999); +sp3_poweroff_time = serial_port.readline(9999); +sp3_wakeupweekend_enable = serial_port.readline(9999); +sp3_ADC_Wide = float(serial_port.readline(9999))/1000; +sp3_ADC_BAT = float(serial_port.readline(9999))/1000; +sp3_ADC_USB = float(serial_port.readline(9999))/1000; +sp3_ADC_OUTPUT = float(serial_port.readline(9999))/1000; +sp3_output_status = serial_port.readline(9999); +sp3_powerfailure_counter = serial_port.readline(9999); +sp3_firmwareVersion = serial_port.readline(9999); +powerofftime_enabletest = (str(sp3_poweroff_time_enable, 'utf-8').rstrip('\n').zfill(2)) +date = int(sp3_date) + +strompi_year = int(sp3_date) // 10000 +strompi_month = int(sp3_date) % 10000 // 100 +strompi_day = int(sp3_date) % 100 + +strompi_hour = int(sp3_time) // 10000 +strompi_min = int(sp3_time) % 10000 // 100 +strompi_sec = int(sp3_time) % 100 + +try: + print('###########################################################################') + print('\rStromPi V3 Serial Config Script (PYTHON3)\r') + print('###########################################################################') + + print('\n---------------------------------------------------------------------------') + print(' Main Configuration') + print('---------------------------------------------------------------------------') + + #strompi-mode + print('[StromPi-Mode: ' + sp3_modus.decode(encoding='UTF-8', errors='strict').rstrip('\n') + ' (' + strompi_mode_converter((int(sp3_modus))) + ')]') + print('\nSetting the StromPi mode \n(1 = mUSB -> Wide, 2 = Wide -> mUSB, 3 = mUSB -> Battery, 4 = Wide -> Battery, 5 = mUSB -> Wide -> Battery, 6 = Wide -> mUSB -> Battery)\n') + sp3_modus_temp = int(sp3_modus) + sp3_modus = input('Mode (1-6): ') + while int(sp3_modus) < 1 or int(sp3_modus) > 6: + sp3_modus = input('Failed! Value not in Range - Please try again\nMode (1-6): ') + + if sp3_modus_temp != int(sp3_modus): + modusreset = 1 + else: + modusreset = 0 + + print('\n--------------------------------------') + #Shutdown-enable & set-timer + print('[Raspberry Pi Shutdown: ' + enabled_disabled_converter(int(sp3_shutdown_enable)) + ']') + print('\nEnabling or disabling the Raspberry Pi shutdown (0 = disable, 1 = enable)\n') + + sp3_shutdown_enable = input('Shutdown enable/disable (0 - 1): ') + while int(sp3_shutdown_enable ) < 0 or int(sp3_shutdown_enable ) > 1: + sp3_shutdown_enable = input('Failed! Value not in Range - Please try again\nShutdown status (0 - 1): ') + + if int(sp3_shutdown_enable ) == 1: + print('\n--------------------------------------') + print('[Shutdown-Timer: ' + str(sp3_shutdown_time, 'utf-8').rstrip('\n').zfill(2) + ' seconds' + ']') + print('\nSetting shutdown timer (seconds)\n') + + sp3_shutdown_time = input('Seconds (0 - 65535): ') + while int(sp3_shutdown_time) < 0 or int(sp3_shutdown_time) > 65535: + sp3_shutdown_time = input('Failed! Value not in Range - Please try again\nSeconds (0 - 65535): ') + + #batlevel-shutdown + print('\n--------------------------------------') + print('[Battery-Level Shutdown: ' + batterylevel_shutdown_converter(int(sp3_batLevel_shutdown)) + ']') + print('\nSetting battery level shutdown (0 = disable, 1 = below 10%, 2 = below 25%, 3 = below 50%)\n') + + sp3_batLevel_shutdown = input('Battery level shutdown (0 - 3): ') + while int(sp3_batLevel_shutdown) < 0 or int(sp3_batLevel_shutdown) > 3: + sp3_batLevel_shutdown = input('Failed! Value not in Range - Please try again\nBattery level shutdown (0 - 3): ') + + + #serialless-mode + print('\n--------------------------------------') + print('[Serial-Less Mode: ' + enabled_disabled_converter(int(sp3_serialLessMode)) + ']') + print('\nEnabling or disabling serialless-mode (0 = disable, 1 = enable)\n') + + sp3_serialLessMode = input('Serialless mode (0 - 1): ') + while int(sp3_serialLessMode) < 0 or int(sp3_serialLessMode) > 1: + sp3_serialLessMode = input('Failed! Value not in Range - Please try again\nSerialless mode (0 - 1): ') + + #powersave + print('\n--------------------------------------') + print('[Power Save Mode: ' + enabled_disabled_converter(int(sp3_powersave_enable)) + ']') + print('\nEnabling or disabling the Power Save mode (0 = disable, 1 = enable)\n') + + sp3_powersave_enable = input('Power Save mode (0 - 1): ') + while int(sp3_powersave_enable) < 0 or int(sp3_powersave_enable) > 1: + sp3_powersave_enable = input('Failed! Value not in Range - Please try again\nPower Save mode (0 - 1): ') + + + #warning-enable + print('\n--------------------------------------') + print('[Powerfail Warning: ' + enabled_disabled_converter(int(sp3_warning_enable)) + ']') + print('\nEnabling or disabling the Powerfail-Warning (instead of a shutdown) through the serial interface (0 = disable, 1 = enable)\n') + + sp3_warning_enable = input('Warning enable/disable (0 - 1): ') + while int(sp3_warning_enable) < 0 or int(sp3_warning_enable) > 1: + sp3_warning_enable = input('Failed! Value not in Range - Please try again\nWarning status (0 - 1): ') + + print('\n--------------------------------------') + # PowerOn-Button Enable & PowerOn-Button Timer + print('[PowerOn-Button: ' + enabled_disabled_converter(int(sp3_powerOnButton_enable)) + ']') + print('\nEnabling or disabling the PowerOn-Button Feature (0 = disable, 1 = enable)\n') + + sp3_powerOnButton_enable = input('PowerOn-Button enable/disable (0 - 1): ') + while int(sp3_powerOnButton_enable) < 0 or int(sp3_powerOnButton_enable) > 1: + sp3_powerOnButton_enable = input('Failed! Value not in Range - Please try again\nShutdown status (0 - 1): ') + + if int(sp3_powerOnButton_enable) == 1 and int(sp3_shutdown_enable) == 1: + print('\n--------------------------------------') + print('[Poweroff Mode: ' + enabled_disabled_converter(int(sp3_poweroffMode)) + ']') + + sp3_poweroffMode = input('Poweroff Mode enable/disable (0 - 1): ') + while int(sp3_poweroffMode) < 0 or int(sp3_poweroffMode) > 1: + sp3_poweroffMode = input('Failed! Value not in Range - Please try again\nPoweroff Mode status (0 - 1): ') + + if int(sp3_powerOnButton_enable) == 1: + print('\n--------------------------------------') + print('[PowerOn-Button Initialization Time: ' + str(sp3_powerOnButton_time, 'utf-8').rstrip('\n').zfill(2) + ' seconds' + ']') + print('\nPowerOn-Button Initialization Time: (seconds)\n') + + sp3_powerOnButton_time = input('Seconds (0 - 65535): ') + while int(sp3_powerOnButton_time) < 0 or int(sp3_powerOnButton_time) > 65535: + sp3_powerOnButton_time = input('Failed! Value not in Range - Please try again\nSeconds (0 - 65535): ') + + print('\n---------------------------------------------------------------------------') + print(' Time&Date-Configuration') + print('---------------------------------------------------------------------------') + #set-clock + print('[Actual Raspberry Pi Time&Date]') + print('[Time: ' + str(strompi_hour).zfill(2) + ':' + str(strompi_min).zfill(2) + ':' + str(strompi_sec).zfill(2) + ']') + print('[Date: ' + weekday_converter(int(sp3_weekday)) + ' ' + str(strompi_day).zfill(2) + '.' + str(strompi_month).zfill( + 2) + '.' + str(strompi_year).zfill(2) + ']') + + timeconfig = input('\nDo you want to change the Time&Date-Configuration? (Y) Yes | (N) No:') + while not (timeconfig == 'Y' or timeconfig == 'N'): + timeconfig = input('Failed! Value not in Range - Please try again\nDo you want to change the Alarm-Configuration? (Y) Yes | (N) No: ') + + if timeconfig == 'Y': + + internettime = input( + 'Do you want to change the Time&Date Manual\n or do you want to transfer the actual SystemTime of the Raspberry Pi (S) Systemtime | (M) Manual:') + while not (internettime == 'S' or internettime == 'M'): + internettime = input( + 'Failed! Value not in Range - Please try again\nDo you want to change the Alarm-Configuration? (Y) Yes | (N) No: ') + + if internettime == 'S': + + print('-----------------------------------------') + print('TimeSync-Process | Please Wait') + print('-----------------------------------------') + + 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) + + 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 ('-----------------------------------------') + + + elif internettime == 'M': + print('\n--------------------------------------') + print('\nSetting the clock (hour, minute)\n') + + setClockH = input('Hour (0-23): ') + while int(setClockH) < 0 or int(setClockH) > 23: + setClockH = input('Failed! Value not in Range - Please try again\nHour (0-23): ') + + setClockM = input('Minute (0-59): ') + while int(setClockM) < 0 or int(setClockM) > 59: + setClockM = input('Failed! Value not in Range - Please try again\nMinute (0-59): ') + + setClockS = '00' + + # set-date + print('\n--------------------------------------') + print('\nSetting the date (day, month, year, weekday)\n') + + setDateD = input('Day (1-31): ') + while int(setDateD) < 1 or int(setDateD) > 31: + setDateD = input('Failed! Value not in Range - Please try again\nDay (1-31): ') + + setDateM = input('Month (1-12): ') + while int(setDateM) < 1 or int(setDateM) > 12: + setDateM = input('Failed! Value not in Range - Please try again\nMonth (1-12): ') + + setDateY = input('Year (0-99): ') + while int(setDateY) < 0 or int(setDateY) > 99: + setDateY = input('Failed! Value not in Range - Please try again\nYear (0-99): ') + + setDateWD = input( + 'Weekday (1 = Monday, 2 = Tuesday, 3 = Wednesday, 4 = Thursday, 5 = Friday, 6 = Saturday, 7 = Sunday): ') + while int(setDateWD) < 1 or int(setDateWD) > 7: + setDateWD = input( + 'Failed! Value not in Range - Please try again\nWeekday (1 = Monday, 2 = Tuesday, 3 = Wednesday, 4 = Thursday, 5 = Friday, 6 = Saturday, 7 = Sunday): ') + + serial_port.write(str.encode('quit')) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + + serial_port.write(str.encode('set-date ' + setDateD + ' ' + setDateM + ' ' + setDateY + ' ' + setDateWD)) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + print('\n\nSetting set-date...') + sleep(breakL) + + serial_port.write(str.encode('set-clock ' + setClockH + ' ' + setClockM + ' ' + setClockS)) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + print('Setting set-clock...') + sleep(breakL) + + print('\n---------------------------------------------------------------------------') + print(' Alarm-Configuration') + print('---------------------------------------------------------------------------') + + print('[Actual Raspberry Pi Time&Date]') + if powerofftime_enabletest == "01": + print(' Alarm-Mode: Wakeup Timer') + else: + print(' Alarm-Mode: ' + alarm_mode_converter(int(sp3_alarm_mode))) + print( + ' Alarm-Time: ' + str(sp3_alarm_hour, 'utf-8').rstrip('\n').zfill(2) + ':' + str(sp3_alarm_min, 'utf-8').rstrip( + '\n').zfill(2)) + print(' Alarm-Date: ' + str(sp3_alarm_day, 'utf-8').rstrip('\n').zfill(2) + '.' + str(sp3_alarm_month, + 'utf-8').rstrip( + '\n').zfill(2)) + print(' WakeUp-Alarm: ' + weekday_converter(int(sp3_alarm_weekday))) + print(' ') + print('PowerOff-Alarm: ' + enabled_disabled_converter(int(sp3_alarmPoweroff))) + print( + ' PowerOff-Alarm-Time: ' + str(sp3_alarm_hour_off, 'utf-8').rstrip('\n').zfill(2) + ':' + str(sp3_alarm_min_off, + 'utf-8').rstrip( + '\n').zfill(2)) + print(' ') + print('Interval-Alarm: ' + enabled_disabled_converter(int(sp3_intervalAlarm))) + print(' Interval-On-Time: ' + str(sp3_intervalAlarmOnTime, 'utf-8').rstrip('\n').zfill(2) + ' minutes') + print(' Interval-Off-Time: ' + str(sp3_intervalAlarmOffTime, 'utf-8').rstrip('\n').zfill(2) + ' minutes') + print(' ') + + alarmconfig = '0' + alarmconfig = input('Do you want to change the Alarm-Configuration? (Y) Yes | (N) No:') + while not (alarmconfig == 'Y' or alarmconfig == 'N'): + alarmconfig = input( + 'Failed! Value not in Range - Please try again\nDo you want to change the Alarm-Configuration? (Y) Yes | (N) No: ') + + if alarmconfig == 'Y': + + print('\n----------------------------------------------') + print(' Power-Off Alarm Configuration') + print('-----------------------------------------------') + + alarmconfig = '0' + alarmconfig = input('Do you want to change the Power-Off Alarm-Configuration? (Y) Yes | (N) No:') + while not (alarmconfig == 'Y' or alarmconfig == 'N'): + alarmconfig = input( + 'Failed! Value not in Range - Please try again\nDo you want to change the Alarm-Configuration? (Y) Yes | (N) No: ') + + if alarmconfig == 'Y': + # poweroff-enable & poweroff-set-time + print('\n--------------------------------------') + print('Enabling or disabling poweroff (0 = disable, 1 = enable)\n') + + sp3_alarmPoweroff = input('Poweroff status (0 - 1): ') + while int(sp3_alarmPoweroff) < 0 or int(sp3_alarmPoweroff) > 1: + sp3_alarmPoweroff = input('Failed! Value not in Range - Please try again\nPoweroff status (0 - 1): ') + + if int(sp3_alarmPoweroff) == 1: + print('\n--------------------------------------') + print('Setting poweroff time (hour, minute)\n') + + sp3_alarm_hour_off = input('Hour (0 - 23): ') + while int(sp3_alarm_hour_off) < 0 or int(sp3_alarm_hour_off) > 23: + sp3_alarm_hour_off = input('Failed! Value not in Range - Please try again\nHour (0 - 23): ') + + sp3_alarm_min_off = input('Minute (0 - 59): ') + while int(sp3_alarm_min_off) < 0 or int(sp3_alarm_min_off) > 59: + sp3_alarm_min_off = input('Failed! Value not in Range - Please try again\nMinute (0 - 59): ') + + print('\n---------------------------------------------------------------------------') + print(' Wake-Up Alarm-Configuration') + print('---------------------------------------------------------------------------') + + alarmconfig = '0' + alarmconfig = input('Do you want to change the Wake-Up Alarm-Configuration? (Y) Yes | (N) No:') + while not (alarmconfig == 'Y' or alarmconfig == 'N'): + alarmconfig = input( + 'Failed! Value not in Range - Please try again\nDo you want to change the Alarm-Configuration? (Y) Yes | (N) No: ') + + if alarmconfig == 'Y': + print('\n--------------------------------------') + # alarm-enable & alarm-mode + print('\nEnabling or disabling wake up alarm (0 = disable, 1 = enable)\n') + + sp3_alarm_enable = input('Wake up alarm status (0 - 1): ') + while int(sp3_alarm_enable) < 0 or int(sp3_alarm_enable) > 1: + sp3_alarm_enable = input( + 'Failed! Value not in Range - Please try again\nWake up alarm status (0 - 1): ') + + if int(sp3_alarm_enable) == 1: + print('\n--------------------------------------') + print('Setting the wake up alarm mode (1 = Time-Alarm , 2 = Date-Alarm, 3 = Weekday-Alarm, 4 = Wakeup Timer)\n') + + sp3_alarm_mode = input('Wake up alarm mode (1 - 4): ') + while int(sp3_alarm_mode) < 1 or int(sp3_alarm_mode) > 4: + sp3_alarm_mode = input('Failed! Value not in Range - Please try again\nWake up alarm mode (1 - 4): ') + if int(sp3_alarm_mode) == 4: + print('\n--------------------------------------') + print('Set the wake up Timer\n') + + sp3_poweroff_time = input('Wake up Timer (1-65535): ') + while int(sp3_poweroff_time) < 1 or int(sp3_poweroff_time) > 65535: + sp3_poweroff_time = input('Failed! Value not in Range - Please try again\nWake up Timer (1-65535): ') + + # Wake up alarm time + if int(sp3_alarm_mode) == 1: + print('\n--------------------------------------') + print('Setting the wake up alarm time (hours, minutes)\n') + + sp3_alarm_hour = input('Hours (0-23): ') + while int(sp3_alarm_hour) < 0 or int(sp3_alarm_hour) > 23: + sp3_alarm_hour = input('Failed! Value not in Range - Please try again\nHours (0-23): ') + + sp3_alarm_min = input('Minutes (0-59): ') + while int(sp3_alarm_min) < 0 or int(sp3_alarm_min) > 59: + sp3_alarm_min = input('Failed! Value not in Range - Please try again\nHours (0-59): ') + + sp3_wakeupweekend_enable = input('Wakeup Weekend mode (0-1): ') + while int(sp3_wakeupweekend_enable) < 0 or int(sp3_wakeupweekend_enable) > 1: + sp3_wakeupweekend_enable = input('Failed! Value not in Range - Please try again\nDisable Enable (0 - 1): ') + # Wake up alarm date + elif int(sp3_alarm_mode) == 2: + print('\n--------------------------------------') + print('Setting the wake up alarm date (day, month)\n') + + sp3_alarm_day = input('Day (1-31): ') + while int(sp3_alarm_day) < 1 or int(sp3_alarm_day) > 31: + sp3_alarm_day = input('Failed! Value not in Range - Please try again\nDay (1-31): ') + + sp3_alarm_month = input('Month (1-12): ') + while int(sp3_alarm_month) < 1 or int(sp3_alarm_month) > 12: + sp3_alarm_month = input('Failed! Value not in Range - Please try again\nMonth (1-12): ') + + else: + print('\n--------------------------------------') + print( + 'Setting the wake up alarm date (1 = Monday, 2 = Tuesday, 3 = Wednesday, 4 = Thursday, 5 = Friday, 6 = Saturday, 7 = Sunday)\n') + + sp3_alarm_weekday = input('Weekday (1 - 7): ') + while int(sp3_alarm_weekday) < 1 or int(sp3_alarm_weekday) > 7: + sp3_alarm_weekday = input('Failed! Value not in Range - Please try again\nWeekday (1 - 7): ') + + print('\n----------------------------------------------') + print(' Interval-Alarm Configuration') + print('-----------------------------------------------') + + alarmconfig = '0' + alarmconfig = input('Do you want to change the Interval-Alarm-Configuration? (Y) Yes | (N) No:') + while not (alarmconfig == 'Y' or alarmconfig == 'N'): + alarmconfig = input( + 'Failed! Value not in Range - Please try again\nDo you want to change the Alarm-Configuration? (Y) Yes | (N) No: ') + + if alarmconfig == 'Y': + # poweroff-enable & poweroff-set-time + print('\n--------------------------------------') + print('\nEnabling or disabling the Interval-Alarm (0 = disable, 1 = enable)\n') + + sp3_intervalAlarm = input('Interval-Alarm status (0 - 1): ') + while int(sp3_intervalAlarm) < 0 or int(sp3_intervalAlarm) > 1: + sp3_intervalAlarm = input( + 'Failed! Value not in Range - Please try again\nInterval-Alarm status (0 - 1): ') + + if int(sp3_intervalAlarm) == 1: + print('\n--------------------------------------') + print('\nSetting Interval-Time Settings\n') + + sp3_intervalAlarmOnTime = input('Interval On-Time in minutes (1-65535): ') + while int(sp3_intervalAlarmOnTime) < 1 or int(sp3_intervalAlarmOnTime) > 65535: + sp3_intervalAlarmOnTime = input( + 'Failed! Value not in Range - Please try again\nInterval On-Time in minutes (1-65535): ') + + sp3_intervalAlarmOffTime = input('Interval Off-Time in minutes (1-65535): ') + while int(sp3_intervalAlarmOffTime) < 0 or int(sp3_intervalAlarmOffTime) > 65535: + sp3_intervalAlarmOffTime = input( + 'Failed! Value not in Range - Please try again\nInterval Off-Time in minutes (1-65535): ') + + +####################################################################################################################### + + print('\n----------------------------------------------') + print(' Configuration Successful') + print(' Transfer new Configuration to the StromPi 3') + print(' \n###Please Wait###') + print('-----------------------------------------------') + + breakS = 0.1 + breakL = 0.2 + + + if type(sp3_modus) == str: + serial_port.write(str.encode('set-config ' + '1 ' + sp3_modus)) + else: + serial_port.write(str.encode('set-config ' + '1 ' + sp3_modus.decode(encoding='UTF-8', errors='strict'))) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + + if sp3_alarm_mode == "1": + serial_port.write(str.encode('set-config ' + '2 0')) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + + serial_port.write(str.encode('set-config ' + '3 0')) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + + serial_port.write(str.encode('set-config ' + '4 1')) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + + serial_port.write(str.encode('set-config ' + '26 0')) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + + elif sp3_alarm_mode == "2": + serial_port.write(str.encode('set-config ' + '2 1')) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + + serial_port.write(str.encode('set-config ' + '3 0')) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + + serial_port.write(str.encode('set-config ' + '4 0')) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + + serial_port.write(str.encode('set-config ' + '26 0')) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + + elif sp3_alarm_mode == "3": + serial_port.write(str.encode('set-config ' + '2 0')) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + + serial_port.write(str.encode('set-config ' + '3 1')) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + + serial_port.write(str.encode('set-config ' + '4 0')) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + + serial_port.write(str.encode('set-config ' + '26 0')) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + + elif sp3_alarm_mode == "4": + serial_port.write(str.encode('set-config ' + '2 0')) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + + serial_port.write(str.encode('set-config ' + '3 0')) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + + serial_port.write(str.encode('set-config ' + '4 0')) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + + serial_port.write(str.encode('set-config ' + '26 1')) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + + + if type(sp3_alarmPoweroff) == str: + serial_port.write(str.encode('set-config ' + '5 ' + sp3_alarmPoweroff)) + else: + serial_port.write(str.encode('set-config ' + '5 ' + sp3_alarmPoweroff.decode(encoding='UTF-8', errors='strict'))) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + + if type(sp3_alarm_min) == str: + serial_port.write(str.encode('set-config ' + '6 ' + sp3_alarm_min)) + else: + serial_port.write(str.encode('set-config ' + '6 ' + sp3_alarm_min.decode(encoding='UTF-8', errors='strict'))) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + + if type(sp3_alarm_hour) == str: + serial_port.write(str.encode('set-config ' + '7 ' + sp3_alarm_hour)) + else: + serial_port.write(str.encode('set-config ' + '7 ' + sp3_alarm_hour.decode(encoding='UTF-8', errors='strict'))) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + + if type(sp3_alarm_min_off) == str: + serial_port.write(str.encode('set-config ' + '8 ' + sp3_alarm_min_off)) + else: + serial_port.write(str.encode('set-config ' + '8 ' + sp3_alarm_min_off.decode(encoding='UTF-8', errors='strict'))) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + + if type(sp3_alarm_hour_off) == str: + serial_port.write(str.encode('set-config ' + '9 ' + sp3_alarm_hour_off)) + else: + serial_port.write(str.encode('set-config ' + '9 ' + sp3_alarm_hour_off.decode(encoding='UTF-8', errors='strict'))) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + + if type(sp3_alarm_day) == str: + serial_port.write(str.encode('set-config ' + '10 ' + sp3_alarm_day)) + else: + serial_port.write(str.encode('set-config ' + '10 ' + sp3_alarm_day.decode(encoding='UTF-8', errors='strict'))) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + + if type(sp3_alarm_month) == str: + serial_port.write(str.encode('set-config ' + '11 ' + sp3_alarm_month)) + else: + serial_port.write(str.encode('set-config ' + '11 ' + sp3_alarm_month.decode(encoding='UTF-8', errors='strict'))) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + + if type(sp3_alarm_weekday) == str: + serial_port.write(str.encode('set-config ' + '12 ' + sp3_alarm_weekday)) + else: + serial_port.write(str.encode('set-config ' + '12 ' + sp3_alarm_weekday.decode(encoding='UTF-8', errors='strict'))) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + + if type(sp3_alarm_enable) == str: + serial_port.write(str.encode('set-config ' + '13 ' + sp3_alarm_enable)) + else: + serial_port.write(str.encode('set-config ' + '13 ' + sp3_alarm_enable.decode(encoding='UTF-8', errors='strict'))) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + + if type(sp3_shutdown_enable) == str: + serial_port.write(str.encode('set-config ' + '14 ' + sp3_shutdown_enable)) + else: + serial_port.write(str.encode('set-config ' + '14 ' + sp3_shutdown_enable.decode(encoding='UTF-8', errors='strict'))) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + + if type(sp3_shutdown_time) == str: + serial_port.write(str.encode('set-config ' + '15 ' + sp3_shutdown_time)) + else: + serial_port.write(str.encode('set-config ' + '15 ' + sp3_shutdown_time.decode(encoding='UTF-8', errors='strict'))) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + + if type(sp3_warning_enable) == str: + serial_port.write(str.encode('set-config ' + '16 ' + sp3_warning_enable)) + else: + serial_port.write(str.encode('set-config ' + '16 ' + sp3_warning_enable.decode(encoding='UTF-8', errors='strict'))) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + + if type(sp3_serialLessMode) == str: + serial_port.write(str.encode('set-config ' + '17 ' + sp3_serialLessMode)) + else: + serial_port.write(str.encode('set-config ' + '17 ' + sp3_serialLessMode.decode(encoding='UTF-8', errors='strict'))) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + + if type(sp3_batLevel_shutdown) == str: + serial_port.write(str.encode('set-config ' + '18 ' + sp3_batLevel_shutdown)) + else: + serial_port.write(str.encode('set-config ' + '18 ' + sp3_batLevel_shutdown.decode(encoding='UTF-8', errors='strict'))) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + + if type(sp3_intervalAlarm) == str: + serial_port.write(str.encode('set-config ' + '19 ' + sp3_intervalAlarm)) + else: + serial_port.write(str.encode('set-config ' + '19 ' + sp3_intervalAlarm.decode(encoding='UTF-8', errors='strict'))) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + + if type(sp3_intervalAlarmOnTime) == str: + serial_port.write(str.encode('set-config ' + '20 ' + sp3_intervalAlarmOnTime)) + else: + serial_port.write(str.encode('set-config ' + '20 ' + sp3_intervalAlarmOnTime.decode(encoding='UTF-8', errors='strict'))) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + + if type(sp3_intervalAlarmOffTime) == str: + serial_port.write(str.encode('set-config ' + '21 ' + sp3_intervalAlarmOffTime)) + else: + serial_port.write(str.encode('set-config ' + '21 ' + sp3_intervalAlarmOffTime.decode(encoding='UTF-8', errors='strict'))) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + + if type(sp3_powerOnButton_enable) == str: + serial_port.write(str.encode('set-config ' + '22 ' + sp3_powerOnButton_enable)) + else: + serial_port.write(str.encode('set-config ' + '22 ' + sp3_powerOnButton_enable.decode(encoding='UTF-8', errors='strict'))) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + + if type(sp3_powerOnButton_time) == str: + serial_port.write(str.encode('set-config ' + '23 ' + sp3_powerOnButton_time)) + else: + serial_port.write(str.encode('set-config ' + '23 ' + sp3_powerOnButton_time.decode(encoding='UTF-8', errors='strict'))) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + + if type(sp3_powersave_enable) == str: + serial_port.write(str.encode('set-config ' + '24 ' + sp3_powersave_enable)) + else: + serial_port.write(str.encode('set-config ' + '24 ' + sp3_powersave_enable.decode(encoding='UTF-8', errors='strict'))) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + + if type(sp3_poweroffMode) == str: + serial_port.write(str.encode('set-config ' + '25 ' + sp3_poweroffMode)) + else: + serial_port.write(str.encode('set-config ' + '25 ' + sp3_poweroffMode.decode(encoding='UTF-8', errors='strict'))) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + + if type(sp3_poweroff_time) == str: + serial_port.write(str.encode('set-config ' + '27 ' + sp3_poweroff_time)) + else: + serial_port.write(str.encode('set-config ' + '27 ' + sp3_poweroff_time.decode(encoding='UTF-8', errors='strict'))) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + + if type(sp3_wakeupweekend_enable) == str: + serial_port.write(str.encode('set-config ' + '28 ' + sp3_wakeupweekend_enable)) + else: + serial_port.write(str.encode('set-config ' + '28 ' + sp3_wakeupweekend_enable.decode(encoding='UTF-8', errors='strict'))) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + + if modusreset == 1: + serial_port.write(str.encode('set-config ' + '0 1')) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + + + elif modusreset != 1: + serial_port.write(str.encode('set-config ' + '0 0')) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + + print('\n----------------------------------------------') + print(' Transfer Successful') + print('-----------------------------------------------') + + serial_port.write(str.encode('status-rpi')) + sleep(0.1) + serial_port.write(str.encode('\x0D')) + sp3_time = serial_port.readline(9999); + sp3_date = serial_port.readline(9999); + sp3_weekday = serial_port.readline(9999); + sp3_modus = serial_port.readline(9999); + sp3_alarm_enable = serial_port.readline(9999); + sp3_alarm_mode = serial_port.readline(9999); + sp3_alarm_hour = serial_port.readline(9999); + sp3_alarm_min = serial_port.readline(9999); + sp3_alarm_day = serial_port.readline(9999); + sp3_alarm_month = serial_port.readline(9999); + sp3_alarm_weekday = serial_port.readline(9999); + sp3_alarmPoweroff = serial_port.readline(9999); + sp3_alarm_hour_off = serial_port.readline(9999); + sp3_alarm_min_off = serial_port.readline(9999); + sp3_shutdown_enable = serial_port.readline(9999); + sp3_shutdown_time = serial_port.readline(9999); + sp3_warning_enable = serial_port.readline(9999); + sp3_serialLessMode = serial_port.readline(9999); + sp3_intervalAlarm = serial_port.readline(9999); + sp3_intervalAlarmOnTime = serial_port.readline(9999); + sp3_intervalAlarmOffTime = serial_port.readline(9999); + sp3_batLevel_shutdown = serial_port.readline(9999); + sp3_batLevel = serial_port.readline(9999); + sp3_charging = serial_port.readline(9999); + sp3_powerOnButton_enable = serial_port.readline(9999); + sp3_powerOnButton_time = serial_port.readline(9999); + sp3_powersave_enable = serial_port.readline(9999); + sp3_poweroffMode = serial_port.readline(9999); + sp3_poweroff_time_enable = serial_port.readline(9999); + sp3_poweroff_time = serial_port.readline(9999); + sp3_wakeupweekend_enable = serial_port.readline(9999); + sp3_ADC_Wide = float(serial_port.readline(9999))/1000; + sp3_ADC_BAT = float(serial_port.readline(9999))/1000; + sp3_ADC_USB = float(serial_port.readline(9999))/1000; + sp3_ADC_OUTPUT = float(serial_port.readline(9999))/1000; + sp3_output_status = serial_port.readline(9999); + sp3_powerfailure_counter = serial_port.readline(9999); + sp3_firmwareVersion = serial_port.readline(9999); + powerofftime_enabletest = (str(sp3_poweroff_time_enable, 'utf-8').rstrip('\n').zfill(2)) + + date = int(sp3_date) + + strompi_year = int(sp3_date) // 10000 + strompi_month = int(sp3_date) % 10000 // 100 + strompi_day = int(sp3_date) % 100 + + strompi_hour = int(sp3_time) // 10000 + strompi_min = int(sp3_time) % 10000 // 100 + strompi_sec = int(sp3_time) % 100 + + if sp3_ADC_Wide > wide_range_volt_min: + wide_range_volt = str(sp3_ADC_Wide) + 'V' + else: + wide_range_volt = ' not connected' + + if sp3_ADC_BAT > battery_volt_min: + battery_volt = str(sp3_ADC_BAT) + 'V' + batterylevel_converter(int(sp3_batLevel),int(sp3_charging)) + else: + battery_volt = ' not connected' + + if sp3_ADC_USB > mUSB_volt_min: + microUSB_volt = str(sp3_ADC_USB) + 'V' + else: + microUSB_volt = ' not connected' + + output_volt = str(sp3_ADC_OUTPUT) + 'V' + + print(' ') + print('---------------------------------') + print('StromPi-Status:') + print('---------------------------------') + print('Time: ' + str(strompi_hour).zfill(2) + ':' + str(strompi_min).zfill(2) + ':' + str(strompi_sec).zfill(2)) + print('Date: ' + weekday_converter(int(sp3_weekday)) + ' ' + str(strompi_day).zfill(2) + '.' + str(strompi_month).zfill(2) + '.' + str(strompi_year).zfill(2)) + print(' ') + print('StromPi-Output: ' + output_status_converter((int(sp3_output_status)))) + print(' ') + print('StromPi-Mode: ' + strompi_mode_converter((int(sp3_modus)))) + print(' ') + print('Raspberry Pi Shutdown: ' + enabled_disabled_converter(int(sp3_shutdown_enable))) + print(' Shutdown-Timer: ' + str(sp3_shutdown_time, 'utf-8').rstrip('\n').zfill(2) + ' seconds') + print(' ') + print('Powerfail Warning: ' + enabled_disabled_converter(int(sp3_warning_enable))) + print(' ') + print('Serial-Less Mode: ' + enabled_disabled_converter(int(sp3_serialLessMode))) + print(' ') + print('Power Save Mode: ' + enabled_disabled_converter(int(sp3_powersave_enable))) + print(' ') + print('PowerOn-Button: ' + enabled_disabled_converter(int(sp3_powerOnButton_enable))) + print(' PowerOn-Button-Timer: ' + str(sp3_powerOnButton_time, 'utf-8').rstrip('\n').zfill(2) + ' seconds') + print(' ') + print('Poweroff Mode: ' + enabled_disabled_converter(int(sp3_poweroffMode))) + print(' ') + print('Battery-Level Shutdown: ' + batterylevel_shutdown_converter(int(sp3_batLevel_shutdown))) + print(' ') + print('Powerfail-Counter: ' + str(sp3_powerfailure_counter, 'utf-8').rstrip('\n')) + print(' ') + print('---------------------------------') + print('Alarm-Configuration:') + print('---------------------------------') + print('WakeUp-Alarm: ' + enabled_disabled_converter(int(sp3_alarm_enable))) + if powerofftime_enabletest == "01": + print(' Alarm-Mode: Wakeup Timer') + else: + print(' Alarm-Mode: ' + alarm_mode_converter(int(sp3_alarm_mode))) + print(' Alarm-Time: ' + str(sp3_alarm_hour, 'utf-8').rstrip('\n').zfill(2) + ':' + str(sp3_alarm_min, 'utf-8').rstrip('\n').zfill(2)) + print(' Alarm-Date: ' + str(sp3_alarm_day, 'utf-8').rstrip('\n').zfill(2) + '.' + str(sp3_alarm_month, 'utf-8').rstrip('\n').zfill(2)) + print(' WakeUp-Alarm: ' + weekday_converter(int(sp3_alarm_weekday))) + print(' ') + print('PowerOff-Alarm: ' + enabled_disabled_converter(int(sp3_alarmPoweroff))) + print(' PowerOff-Alarm-Time: ' + str(sp3_alarm_hour_off, 'utf-8').rstrip('\n').zfill(2) + ':' + str(sp3_alarm_min_off, 'utf-8').rstrip('\n').zfill(2)) + print(' ') + print('Interval-Alarm: ' + enabled_disabled_converter(int(sp3_intervalAlarm))) + print(' Interval-On-Time: ' + str(sp3_intervalAlarmOnTime, 'utf-8').rstrip('\n').zfill(2) + ' minutes') + print(' Interval-Off-Time: ' + str(sp3_intervalAlarmOffTime, 'utf-8').rstrip('\n').zfill(2) + ' minutes') + print(' ') + print('---------------------------------') + print('Voltage-Levels:') + print('---------------------------------') + print('Wide-Range-Inputvoltage: ' + wide_range_volt) + print('LifePo4-Batteryvoltage: ' + battery_volt) + print('microUSB-Inputvoltage: ' + microUSB_volt) + print('Output-Voltage: ' + output_volt) + print(' ') + +except KeyboardInterrupt: + print('interrupted!') + +serial_port.close() \ No newline at end of file diff --git a/StromPi3/strompi_config_gui.py b/StromPi3/strompi_config_gui.py new file mode 100644 index 0000000..413d1b1 --- /dev/null +++ b/StromPi3/strompi_config_gui.py @@ -0,0 +1,1378 @@ +#!/usr/bin/env python3 + +import serial +from time import sleep +import datetime +import os +import sys +import time +from time import sleep +import tkinter as tk +from tkinter import * +from tkinter import ttk +from PIL import ImageTk, Image +import functools +fp = functools.partial +#need sudo apt-get install python3-pil python3-pil.imagetk + +wide_range_volt_min = 4.8 +battery_volt_min = 0.5 +mUSB_volt_min = 4.1 +TimeSynctmp = 0 + + + +breakS = 0.1 +breakL = 0.5 + +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 + +Alarm_Powerofffailmin = 0 +Alarm_Powerofffailhour = 0 + +def enabled_disabled_converter(argument): + switcher = { + 0: 'Disabled', + 1: 'Enabled', + } + return switcher.get(argument, 'nothing') + +def weekday_converter(argument): + switcher = { + 1: 'Monday', + 2: 'Tuesday', + 3: 'Wednesday', + 4: 'Thursday', + 5: 'Friday', + 6: 'Saturday', + 7: 'Sunday', + } + return switcher.get(argument, 'nothing') + +def strompi_mode_converter(argument): + switcher = { + 1: 'mUSB -> Wide', + 2: 'Wide -> mUSB', + 3: 'mUSB -> Battery', + 4: 'Wide -> Battery', + 5: "mUSB -> Wide -> Battery", + 6: "Wide -> mUSB -> Battery", + } + return switcher.get(argument, 'nothing') + +def alarm_mode_converter(argument): + switcher = { + 1: 'Time-Alarm', + 2: 'Date-Alarm', + 3: 'Weekday-Alarm', + 4: 'Minute Wakeup-Alarm', + } + return switcher.get(argument, 'nothing') + +def batterylevel_shutdown_converter(argument): + switcher = { + 0: 'Disabled', + 1: '10%', + 2: '25%', + 3: '50%', + } + return switcher.get(argument, 'nothing') + +def output_status_converter(argument): + switcher = { + 0: 'Power-Off', #only for Debugging-Purposes + 1: 'mUSB', + 2: 'Wide', + 3: 'Battery', + } + return switcher.get(argument, 'nothing') + +def batterylevel_converter(batterylevel,charging): + + if charging: + switcher = { + 1: ' [10%] [charging]', + 2: ' [25%] [charging]', + 3: ' [50%] [charging]', + 4: ' [100%] [charging]', + } + return switcher.get(batterylevel, 'nothing') + else: + switcher = { + 1: ' [10%]', + 2: ' [25%]', + 3: ' [50%]', + 4: ' [100%]', + } + return switcher.get(batterylevel, 'nothing') + +def Set_Alarm_Mode(sp3_alarm_mode): + if sp3_alarm_mode == "1": + serial_port.write(str.encode('set-config ' + '2 0')) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + + serial_port.write(str.encode('set-config ' + '3 0')) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + + serial_port.write(str.encode('set-config ' + '4 1')) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + + serial_port.write(str.encode('set-config ' + '26 0')) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + + elif sp3_alarm_mode == "2": + serial_port.write(str.encode('set-config ' + '2 1')) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + + serial_port.write(str.encode('set-config ' + '3 0')) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + + serial_port.write(str.encode('set-config ' + '4 0')) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + + serial_port.write(str.encode('set-config ' + '26 0')) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + + elif sp3_alarm_mode == "3": + serial_port.write(str.encode('set-config ' + '2 0')) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + + serial_port.write(str.encode('set-config ' + '3 1')) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + + serial_port.write(str.encode('set-config ' + '4 0')) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + + serial_port.write(str.encode('set-config ' + '26 0')) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + + if sp3_alarm_mode == "4": + serial_port.write(str.encode('set-config ' + '2 0')) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + + serial_port.write(str.encode('set-config ' + '3 0')) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + + serial_port.write(str.encode('set-config ' + '4 0')) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + + serial_port.write(str.encode('set-config ' + '26 1')) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + +def Set_Warning_enable(sp3_warning_enable): + if (sp3_warning_enable == "1") or (sp3_warning_enable == "0"): + if type(sp3_warning_enable) == str: + serial_port.write(str.encode('set-config ' + '16 ' + sp3_warning_enable)) + else: + serial_port.write(str.encode('set-config ' + '16 ' + sp3_warning_enable.decode(encoding='UTF-8', errors='strict'))) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + +def Set_PoweroffMode(sp3_poweroffMode): + if (sp3_poweroffMode == "1") or (sp3_poweroffMode == "0"): + if type(sp3_poweroffMode) == str: + serial_port.write(str.encode('set-config ' + '25 ' + sp3_poweroffMode)) + else: + serial_port.write(str.encode('set-config ' + '25 ' + sp3_poweroffMode.decode(encoding='UTF-8', errors='strict'))) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + +def Set_wakeupweekend_enable(sp3_wakeupweekend_enable): + if (sp3_wakeupweekend_enable == "1") or (sp3_wakeupweekend_enable == "0"): + if type(sp3_wakeupweekend_enable) == str: + serial_port.write(str.encode('set-config ' + '28 ' + sp3_wakeupweekend_enable)) + else: + serial_port.write(str.encode('set-config ' + '28 ' + sp3_wakeupweekend_enable.decode(encoding='UTF-8', errors='strict'))) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + +def Set_Shutdown_enable(sp3_shutdown_enable): + if (sp3_shutdown_enable == "1") or (sp3_shutdown_enable == "0"): + if type(sp3_shutdown_enable) == str: + serial_port.write(str.encode('set-config ' + '14 ' + sp3_shutdown_enable)) + else: + serial_port.write(str.encode('set-config ' + '14 ' + sp3_shutdown_enable.decode(encoding='UTF-8', errors='strict'))) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + +def Set_Batlevel_Shutdown(sp3_batLevel_shutdown): + if (sp3_batLevel_shutdown == "1") or (sp3_batLevel_shutdown == "0") or (sp3_batLevel_shutdown == "2") or (sp3_batLevel_shutdown == "3"): + if type(sp3_batLevel_shutdown) == str: + serial_port.write(str.encode('set-config ' + '18 ' + sp3_batLevel_shutdown)) + else: + serial_port.write(str.encode('set-config ' + '18 ' + sp3_batLevel_shutdown.decode(encoding='UTF-8', errors='strict'))) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + +def Set_Serialless_mode(sp3_serialLessMode): + if (sp3_serialLessMode == "1") or (sp3_serialLessMode == "0"): + if type(sp3_serialLessMode) == str: + serial_port.write(str.encode('set-config ' + '17 ' + sp3_serialLessMode)) + else: + serial_port.write(str.encode('set-config ' + '17 ' + sp3_serialLessMode.decode(encoding='UTF-8', errors='strict'))) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + +def Set_PoweronButton(sp3_powerOnButton_enable): + if (sp3_powerOnButton_enable == "1") or (sp3_powerOnButton_enable == "0"): + if type(sp3_powerOnButton_enable) == str: + serial_port.write(str.encode('set-config ' + '22 ' + sp3_powerOnButton_enable)) + else: + serial_port.write(str.encode('set-config ' + '22 ' + sp3_powerOnButton_enable.decode(encoding='UTF-8', errors='strict'))) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + +def Use_Modusreset(modusreset): + if modusreset == 1: + serial_port.write(str.encode('set-config ' + '0 1')) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + + + elif modusreset != 1: + serial_port.write(str.encode('set-config ' + '0 0')) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + +def Set_WakeUpAlarm(sp3_alarm_enable): + if (sp3_alarm_enable == "1") or (sp3_alarm_enable == "0"): + if type(sp3_alarm_enable) == str: + serial_port.write(str.encode('set-config ' + '13 ' + sp3_alarm_enable)) + else: + serial_port.write(str.encode('set-config ' + '13 ' + sp3_alarm_enable.decode(encoding='UTF-8', errors='strict'))) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + +def Set_Intervalmode(sp3_intervalAlarm): + if (sp3_intervalAlarm == "1") or (sp3_intervalAlarm == "0"): + if type(sp3_intervalAlarm) == str: + serial_port.write(str.encode('set-config ' + '19 ' + sp3_intervalAlarm)) + else: + serial_port.write(str.encode('set-config ' + '19 ' + sp3_intervalAlarm.decode(encoding='UTF-8', errors='strict'))) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + +def Set_Alarm_Poweroff(sp3_alarmPoweroff): + if (sp3_alarmPoweroff == "1") or (sp3_alarmPoweroff == "0"): + if type(sp3_alarmPoweroff) == str: + serial_port.write(str.encode('set-config ' + '5 ' + sp3_alarmPoweroff)) + else: + serial_port.write(str.encode('set-config ' + '5 ' + sp3_alarmPoweroff.decode(encoding='UTF-8', errors='strict'))) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + +def Set_Alarm_min(sp3_alarm_min, Alarm_Powerofffailmin): + sp3_alarm_min = ''.join([i for i in sp3_alarm_min if i.isdigit()]) + if sp3_alarm_min.isdigit(): + sp3_alarm_minint = int(sp3_alarm_min) + if (sp3_alarm_minint < 61) and (sp3_alarm_minint >= 0): + serial_port.write(str.encode('set-config ' + '8 ' + sp3_alarm_min)) + else: + Alarm_Powerofffailmin = 1 + else: + Alarm_Powerofffailmin = 1 + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + +def Set_Alarm_hour(sp3_alarm_hour): + sp3_alarm_hour = ''.join([i for i in sp3_alarm_hour if i.isdigit()]) + if sp3_alarm_hour.isdigit(): + sp3_alarm_hourint = int(sp3_alarm_hour) + if (sp3_alarm_hourint < 25) and (sp3_alarm_hourint >= 0): + serial_port.write(str.encode('set-config ' + '9 ' + sp3_alarm_hour)) + else: + Alarm_Powerofffailhour = 1 + else: + Alarm_Powerofffailhour = 1 + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + +def Set_Alarm_hour_off(sp3_alarm_hour_off): + sp3_alarm_hour_off = ''.join([i for i in sp3_alarm_hour_off if i.isdigit()]) + if sp3_alarm_hour_off.isdigit(): + sp3_alarm_hour_off2 = int(sp3_alarm_hour_off) + if (sp3_alarm_hour_off2 < 61) and (sp3_alarm_hour_off2 >= 0): + serial_port.write(str.encode('set-config ' + '7 ' + str(sp3_alarm_hour_off))) + else: + ShutdownTimeError = 1 #("You can only use Digits between 0 and 65535 for the shutdown timer") + else: + ShutdownTimeError = 1 #("You can only use Digits between 0 and 65535 for the shutdown timer") + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + +def Set_Alarm_min_off(sp3_alarm_min_off): + sp3_alarm_min_off = ''.join([i for i in sp3_alarm_min_off if i.isdigit()]) + if sp3_alarm_min_off.isdigit(): + sp3_alarm_min_off2 = int(sp3_alarm_min_off) + if (sp3_alarm_min_off2 < 61) and (sp3_alarm_min_off2 >= 0): + serial_port.write(str.encode('set-config ' + '6 ' + str(sp3_alarm_min_off))) + else: + ShutdownTimeError = 1 #("You can only use Digits between 0 and 65535 for the shutdown timer") + else: + ShutdownTimeError = 1 #("You can only use Digits between 0 and 65535 for the shutdown timer") + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + +def Set_Alarm_Day(sp3_alarm_day): + sp3_alarm_day = ''.join([i for i in sp3_alarm_day if i.isdigit()]) + if sp3_alarm_day.isdigit(): + sp3_alarm_dayint = int(sp3_alarm_day) + if (sp3_alarm_dayint <= 31) and (sp3_alarm_dayint >= 0): + serial_port.write(str.encode('set-config ' + '10 ' + sp3_alarm_day)) + else: + Alarm_Dayerror = 1 + else: + Alarm_Dayerror = 1 + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + +def Set_Alarm_Weekday(sp3_alarm_weekday): + if sp3_alarm_weekday.isdigit(): + serial_port.write(str.encode('set-config ' + '12 ' + sp3_alarm_weekday)) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + +def Set_IntervalAlarmOffTime(sp3_intervalAlarmOffTime): #21 + sp3_intervalAlarmOffTime = ''.join([i for i in sp3_intervalAlarmOffTime if i.isdigit()]) + if sp3_intervalAlarmOffTime.isdigit(): + sp3_intervalAlarmOffTimeint = int(sp3_intervalAlarmOffTime) + if (sp3_intervalAlarmOffTimeint < 65535) and (sp3_intervalAlarmOffTimeint > 0): + serial_port.write(str.encode('set-config ' + '21 ' + str(sp3_intervalAlarmOffTime))) + else: + IntervalOffTimeError = 1 + else: + IntervalOffTimeError = 1 + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + +def Set_IntervalAlarmOnTime(sp3_intervalAlarmOnTime): #20 + sp3_intervalAlarmOnTime = ''.join([i for i in sp3_intervalAlarmOnTime if i.isdigit()]) + if sp3_intervalAlarmOnTime.isdigit(): + sp3_intervalAlarmOnTimeint = int(sp3_intervalAlarmOnTime) + if (sp3_intervalAlarmOnTimeint < 65535) and (sp3_intervalAlarmOnTimeint > 0): + serial_port.write(str.encode('set-config ' + '20 ' + str(sp3_intervalAlarmOnTime))) + else: + IntervalOnTimeError = 1 + else: + IntervalOnTimeError = 1 + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + +def Set_RTC(): + 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) + 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')) + +def Set_RTC_Manual(SetClockHstr, SetClockMstr, SetDateDstr, SetDateM, SetDateWD, SetDateYstr): + SetDateWDstr = str(SetDateWD) + SetDateMstr = ''.join([i for i in SetDateM if i.isdigit()]) + SetClockHstr = ''.join([i for i in SetClockHstr if i.isdigit()]) + SetClockMstr = ''.join([i for i in SetClockMstr if i.isdigit()]) + SetDateDstr = ''.join([i for i in SetDateDstr if i.isdigit()]) + SetDateYstr = ''.join([i for i in SetDateYstr if i.isdigit()]) + if (SetDateWDstr == "1 = Monday") or (SetDateWDstr == "Monday"): + SetDateWDstr = "1" + if (SetDateWDstr == "2 = Tuesday") or (SetDateWDstr == "Tuesday"): + SetDateWDstr = "2" + if (SetDateWDstr == "3 = Wednesday") or (SetDateWDstr == "Wednesday"): + SetDateWDstr = "3" + if (SetDateWDstr == "4 = Thursday") or (SetDateWDstr == "Thursday"): + SetDateWDstr = "4" + if (SetDateWDstr == "5 = Friday") or (SetDateWDstr == "Friday"): + SetDateWDstr = "5" + if (SetDateWDstr == "6 = Saturday") or (SetDateWDstr == "Saturday"): + SetDateWDstr = "6" + if (SetDateWDstr == "7 = Sunday") or (SetDateWDstr == "Sunday"): + SetDateWDstr = "7" + if SetDateWDstr.isdigit(): + SetDateWD = int(SetDateWDstr) + if (SetDateWD <= 7) and (SetDateWD >= 1): + SetDateWDError = 0 + else: + SetDateWDError = 1 + else: + SetDateWDError = 1 + + + SetDateM = int(SetDateMstr) + + SetDateD = 0 + SetDateY = 0 + SetClockM = 0 + SetClockH = 0 + + + SetClockS = '00' + if SetClockHstr.isdigit(): + SetClockH = int(SetClockHstr) + if (SetClockH < 24) and (SetClockH >= 0): + SetClockHError = 0 + else: + SetClockHError = 1 + else: + SetClockHError = 1 + if SetClockMstr.isdigit(): + SetClockM = int(SetClockMstr) + if (SetClockM < 60) and (SetClockM >= 0): + SetClockMError = 0 + else: + SetClockMError = 1 + else: + SetClockMError = 1 + + if SetDateDstr.isdigit(): + SetDateD = int(SetDateDstr) + if (SetDateD < 32) and (SetDateD >= 1): + SetDateDError = 0 + else: + SetDateDError = 1 + else: + SetDateDError = 1 + if SetDateYstr.isdigit(): + SetDateY = int(SetDateYstr) + if (SetDateY <= 99) and (SetDateY >= 0): + SetDateYError = 0 + else: + SetDateYError = 1 + else: + SetDateYError = 1 + if (SetDateM <= 12) and (SetDateM >= 1): + SetDateMError = 0 + else: + SetDateMError = 1 + + + + + if (SetClockHError == 0) and (SetClockMError == 0) and (SetDateWDError == 0) and (SetDateDError == 0) and (SetDateMError == 0) and (SetDateYError == 0): + serial_port.write(str.encode('quit')) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + + serial_port.write(str.encode('set-date ' + SetDateDstr + ' ' + SetDateMstr + ' ' + SetDateYstr + ' ' + SetDateWDstr)) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + + serial_port.write(str.encode('set-clock ' + SetClockHstr + ' ' + SetClockMstr + ' ' + SetClockS)) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + else: + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + Refresh_Status() + +def SetDateYFocusIn(SetDateYstr): + SetDateYstr = tkSetDateY.get() + SetDateYstr = ''.join([i for i in SetDateYstr if i.isdigit()]) + tkSetDateY.set(SetDateYstr) + +def SetDateYFocusOut(SetDateYstr): + SetDateYstr = ''.join([i for i in SetDateYstr if i.isdigit()]) + tkSetDateY.set(SetDateYstr + " Year") + +def SetDateDFocusIn(SetDateDstr): + SetDateDstr = tkSetDateD.get() + SetDateDstr = ''.join([i for i in SetDateDstr if i.isdigit()]) + tkSetDateD.set(SetDateDstr) + +def SetDateDFocusOut(SetDateDstr): + SetDateDstr = ''.join([i for i in SetDateDstr if i.isdigit()]) + tkSetDateD.set(SetDateDstr + " Day") + +def SetClockHFocusIn(SetClockHstr): + SetClockHstr = tkSetClockH.get() + SetClockHstr = ''.join([i for i in SetClockHstr if i.isdigit()]) + tkSetClockH.set(SetClockHstr) + +def SetClockHFocusOut(SetClockHstr): + SetClockHstr = ''.join([i for i in SetClockHstr if i.isdigit()]) + tkSetClockH.set(SetClockHstr + " Hours") + +def SetClockMFocusIn(SetClockMstr): + SetClockMstr = tkSetClockM.get() + SetClockMstr = ''.join([i for i in SetClockMstr if i.isdigit()]) + tkSetClockM.set(SetClockMstr) + +def SetClockMFocusOut(SetClockMstr): + SetClockMstr = ''.join([i for i in SetClockMstr if i.isdigit()]) + tkSetClockM.set(SetClockMstr + " Minutes") + +def Set_PowerSaveMode(sp3_powersave_enable): + if (sp3_powersave_enable == "1") or (sp3_powersave_enable == "0"): + if type(sp3_powersave_enable) == str: + serial_port.write(str.encode('set-config ' + '24 ' + sp3_powersave_enable)) + else: + serial_port.write(str.encode('set-config ' + '24 ' + sp3_powersave_enable.decode(encoding='UTF-8', errors='strict'))) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + +def Set_powerofftimer(sp3_poweroff_time): + sp3_poweroff_time = ''.join([i for i in sp3_poweroff_time if i.isdigit()]) + if sp3_poweroff_time.isdigit(): + sp3_poweroff_timeint = int(sp3_poweroff_time) + if (sp3_poweroff_timeint < 65535) and (sp3_poweroff_timeint > 0): + serial_port.write(str.encode('set-config ' + '27 ' + str(sp3_poweroff_time))) + else: + powerOffTimeError = 1 + else: + powerOffTimeError = 1 + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + + +def Upload_to_StromPi(): + Info.config(text="Uploading data to StromPi") + fenster.update_idletasks() + sp3_powerOnButton_timestr = tkButton_time.get() + sp3_modusstr = tkmode.get() + sp3_shutdown_enablestr = tkShutdownMode.get() + sp3_batLevel_shutdownstr = tkBatShutdown.get() + sp3_serialLessModestr = tkSerialless.get() + sp3_warning_enablestr = tkPowerfailWarning.get() + sp3_powerOnButton_enablestr = tkPoweronButton.get() + sp3_shutdown_timestr = tkshutdown_time.get() + sp3_alarm_modestr = tkAlarm_Mode.get() + sp3_alarm_enablestr = tkWakeupAlarm.get() + sp3_intervalAlarmstr = tkIntervalAlarm.get() + sp3_alarmPoweroffstr = tkAlarmPoweroff.get() + sp3_alarm_min = tkAlarmPoweroffmin.get() + sp3_alarm_hour = tkAlarmPoweroffhour.get() + sp3_alarm_day = tkAlarmPoweroffday.get() + sp3_alarm_weekdaystr = tkAlarmPoweroffweekday.get() + sp3_alarm_monthstr = tkAlarmPoweroffmonth.get() + sp3_alarm_min_off = tkAlarmminoff.get() + sp3_alarm_hour_off = tkAlarmhouroff.get() + sp3_intervalAlarmOnTime = tkIntervalAlarmOnTime.get() + sp3_intervalAlarmOffTime = tkIntervalAlarmOffTime.get() + sp3_timesetting = tkTimeSync.get() + TimeSyncRB1test = TimeSyncRB1.get() + sp3_powersave_enablestr = tkPowerSave.get() + sp3_poweroffModestr = tkPoweroffMode.get() + sp3_wakeupweekend_enablestr = tkwakeupweekend_enable.get() + + sp3_wakeupweekend_enable = sp3_wakeupweekend_enablestr[0] + sp3_alarmPoweroff = sp3_alarmPoweroffstr[0] + sp3_alarm_weekday = sp3_alarm_weekdaystr[0] + sp3_alarm_month = sp3_alarm_monthstr[0] + sp3_alarm_month2 = sp3_alarm_monthstr[1] + sp3_modus = sp3_modusstr[0] + sp3_modus_temp = sp3_modus + sp3_serialLessMode = sp3_serialLessModestr[0] + sp3_batLevel_shutdown = sp3_batLevel_shutdownstr[0] + sp3_warning_enable = sp3_warning_enablestr[0] + sp3_powerOnButton_enable = sp3_powerOnButton_enablestr[0] + sp3_shutdown_enable = sp3_shutdown_enablestr[0] + sp3_alarm_mode = sp3_alarm_modestr[0] + sp3_alarm_enable = sp3_alarm_enablestr [0] + sp3_intervalAlarm = sp3_intervalAlarmstr [0] + sp3_powersave_enable = sp3_powersave_enablestr [0] + sp3_poweroffMode = sp3_poweroffModestr [0] + SetClockHstr = tkSetClockH.get() + SetClockMstr = tkSetClockM.get() + SetDateDstr = tkSetDateD.get() + SetDateM = tkSetDateM.get() + SetDateWD = tkSetDateWD.get() + SetDateYstr = tkSetDateY.get() + sp3_poweroff_time = tkPoweroff_time.get() + + + breakS = 0.1 + breakL = 0.2 + + if serial_port.isOpen(): serial_port.close() + serial_port.open() + + serial_port.write(str.encode('quit')) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + + if TimeSyncRB1test == 2: + Set_RTC() + elif TimeSyncRB1test == 3: + Set_RTC_Manual(SetClockHstr, SetClockMstr, SetDateDstr, SetDateM, SetDateWD, SetDateYstr) + + if (sp3_modus == "0") or (sp3_modus == "1") or (sp3_modus == "2") or (sp3_modus == "3") or (sp3_modus == "4") or (sp3_modus == "5") or (sp3_modus == "6"): + modusreset = 1 + serial_port.write(str.encode('set-config ' + '1 ' + sp3_modus)) + else: + modusreset = 0 + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + + Set_Alarm_Mode(sp3_alarm_mode) #2-4 and 26 + + Set_Alarm_Poweroff(sp3_alarmPoweroff) #5 + + Set_Alarm_min(sp3_alarm_min, Alarm_Powerofffailmin) #6 + + Set_Alarm_hour(sp3_alarm_hour) #7 + + Set_Alarm_min_off(sp3_alarm_min_off) #8 + + Set_Alarm_hour_off(sp3_alarm_hour_off) #9 + + Set_Alarm_Day(sp3_alarm_day) #10 + + if sp3_alarm_month2 == "1": + serial_port.write(str.encode('set-config ' + '11 ' + '11')) + elif sp3_alarm_month2 == "0": + serial_port.write(str.encode('set-config ' + '11 ' + '10')) + elif sp3_alarm_month2 == "2": + serial_port.write(str.encode('set-config ' + '11 ' + '12')) + else: + serial_port.write(str.encode('set-config ' + '11 ' + sp3_alarm_month)) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + + Set_Alarm_Weekday(sp3_alarm_weekday) #12 + + Set_WakeUpAlarm(sp3_alarm_enable) #13 + + Set_Shutdown_enable(sp3_shutdown_enable) #14 + sp3_shutdown_timestr = ''.join([i for i in sp3_shutdown_timestr if i.isdigit()]) + if sp3_shutdown_timestr.isdigit(): + sp3_shutdown_time = int(sp3_shutdown_timestr) + if (sp3_shutdown_time < 65535) and (sp3_shutdown_time > 0): + serial_port.write(str.encode('set-config ' + '15 ' + str(sp3_shutdown_time))) + else: + ShutdownTimeError = 1 + else: + ShutdownTimeError = 1 + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + + Set_Warning_enable(sp3_warning_enable) #16 + + Set_Serialless_mode(sp3_serialLessMode) #17 + + Set_Batlevel_Shutdown(sp3_batLevel_shutdown) #18 + + Set_Intervalmode(sp3_intervalAlarm) #19 + + Set_IntervalAlarmOnTime(sp3_intervalAlarmOnTime) #20 + + Set_IntervalAlarmOffTime(sp3_intervalAlarmOffTime) #21 + + Set_PoweronButton(sp3_powerOnButton_enable) #22 + + sp3_powerOnButton_timestr = ''.join([i for i in sp3_powerOnButton_timestr if i.isdigit()]) + if sp3_powerOnButton_timestr.isdigit(): + sp3_powerOnButton_time = int(sp3_powerOnButton_timestr) + if (sp3_powerOnButton_time < 65535) and (sp3_powerOnButton_time > 0): + serial_port.write(str.encode('set-config ' + '23 ' + str(sp3_powerOnButton_time))) + else: + ButtonTimeError = 1 #("You can only use Digits between 0 and 65535 for the Button timer") + else: + ButtonTimeError = 1 #("You can only use Digits between 0 and 65535 for the Button timer") + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + + Set_PowerSaveMode(sp3_powersave_enable) #24 + + Set_PoweroffMode(sp3_poweroffMode) #25 + + Set_powerofftimer(sp3_poweroff_time)#27 + + Set_wakeupweekend_enable(sp3_wakeupweekend_enable)#28 + + Use_Modusreset(modusreset) + Refresh_Status() + Info.config(text="Finished Uploading") + +def Refresh_Status(): + + 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() + + serial_port.write(str.encode('quit')) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + + serial_port.write(str.encode('status-rpi')) + sleep(1) + serial_port.write(str.encode('\x0D')) + sp3_time = serial_port.readline(9999); + sp3_date = serial_port.readline(9999); + sp3_weekday = serial_port.readline(9999); + sp3_modus = serial_port.readline(9999); + sp3_alarm_enable = serial_port.readline(9999); + sp3_alarm_mode = serial_port.readline(9999); + sp3_alarm_hour = serial_port.readline(9999); + sp3_alarm_min = serial_port.readline(9999); + sp3_alarm_day = serial_port.readline(9999); + sp3_alarm_month = serial_port.readline(9999); + sp3_alarm_weekday = serial_port.readline(9999); + sp3_alarmPoweroff = serial_port.readline(9999); + sp3_alarm_hour_off = serial_port.readline(9999); + sp3_alarm_min_off = serial_port.readline(9999); + sp3_shutdown_enable = serial_port.readline(9999); + sp3_shutdown_time = serial_port.readline(9999); + sp3_warning_enable = serial_port.readline(9999); + sp3_serialLessMode = serial_port.readline(9999); + sp3_intervalAlarm = serial_port.readline(9999); + sp3_intervalAlarmOnTime = serial_port.readline(9999); + sp3_intervalAlarmOffTime = serial_port.readline(9999); + sp3_batLevel_shutdown = serial_port.readline(9999); + sp3_batLevel = serial_port.readline(9999); + sp3_charging = serial_port.readline(9999); + sp3_powerOnButton_enable = serial_port.readline(9999); + sp3_powerOnButton_time = serial_port.readline(9999); + sp3_powersave_enable = serial_port.readline(9999); + sp3_poweroffMode = serial_port.readline(9999); + sp3_poweroff_time_enable = serial_port.readline(9999); + sp3_poweroff_time = serial_port.readline(9999); + sp3_wakeupweekend_enable = serial_port.readline(9999); + sp3_ADC_Wide = float(serial_port.readline(9999))/1000; + sp3_ADC_BAT = float(serial_port.readline(9999))/1000; + sp3_ADC_USB = float(serial_port.readline(9999))/1000; + sp3_ADC_OUTPUT = float(serial_port.readline(9999))/1000; + sp3_output_status = serial_port.readline(9999); + sp3_powerfailure_counter = serial_port.readline(9999); + sp3_firmwareVersion = serial_port.readline(9999); + + sp3_modus_temp = int(sp3_modus) + + strompi_year = int(sp3_date) // 10000 + strompi_month = int(sp3_date) % 10000 // 100 + strompi_day = int(sp3_date) % 100 + + strompi_hour = int(sp3_time) // 10000 + strompi_min = int(sp3_time) % 10000 // 100 + strompi_sec = int(sp3_time) % 100 + + + sp3_poweroff_time_enable = int(sp3_poweroff_time_enable.decode()) + if sp3_poweroff_time_enable == 1: + sp3_alarm_mode = "4" + tkmode.set(strompi_mode_converter((int(sp3_modus)))) + tkshutdown_time.set(str(sp3_shutdown_time, 'utf-8').rstrip('\n') + ' Seconds') + tkButton_time.set(str(sp3_powerOnButton_time, 'utf-8').rstrip('\n') + ' Seconds') + tkShutdownMode.set(enabled_disabled_converter(int(sp3_shutdown_enable))) + tkBatShutdown.set(batterylevel_shutdown_converter(int(sp3_batLevel_shutdown))) + tkSerialless.set(enabled_disabled_converter(int(sp3_serialLessMode))) + tkPowerfailWarning.set(enabled_disabled_converter(int(sp3_warning_enable))) + tkPoweronButton.set(enabled_disabled_converter(int(sp3_powerOnButton_enable))) + tkAlarm_Mode.set('Alarm-Mode: ' + alarm_mode_converter(int(sp3_alarm_mode))) + tkPowerSave.set('Power Save Mode: ' + enabled_disabled_converter(int(sp3_powersave_enable))) + tkwakeupweekend_enable.set('Weekend Wakeup: ' + enabled_disabled_converter(int(sp3_wakeupweekend_enable))) + #tkTimeSync.set('No Change') + tkWakeupAlarm.set('WakeUp-Alarm: ' + enabled_disabled_converter(int(sp3_alarm_enable))) + tkIntervalAlarm.set('Interval-Alarm: ' + enabled_disabled_converter(int(sp3_intervalAlarm))) + tkAlarmPoweroff.set('PowerOff-Alarm: ' + enabled_disabled_converter(int(sp3_alarmPoweroff))) + tkAlarmPoweroffmin.set(str(sp3_alarm_min_off, 'utf-8').rstrip('\n').zfill(2) + ' Minutes') + tkAlarmPoweroffhour.set(str(sp3_alarm_hour_off, 'utf-8').rstrip('\n').zfill(2) + ' Hours') + tkAlarmPoweroffmonth.set(str(sp3_alarm_month, 'utf-8').rstrip('\n').zfill(2)) + tkAlarmPoweroffweekday.set(weekday_converter(int(sp3_alarm_weekday))) + tkAlarmPoweroffday.set(str(sp3_alarm_day, 'utf-8').rstrip('\n').zfill(2) + ' Day') + tkAlarmhouroff.set(str(sp3_alarm_hour, 'utf-8').rstrip('\n').zfill(2) + ' Hours') + tkAlarmminoff.set(str(sp3_alarm_min, 'utf-8').rstrip('\n').zfill(2) + ' Minutes') + tkIntervalAlarmOffTime.set(str(sp3_intervalAlarmOffTime, 'utf-8').rstrip('\n').zfill(2) + ' Minutes') + tkIntervalAlarmOnTime.set(str(sp3_intervalAlarmOnTime, 'utf-8').rstrip('\n').zfill(2) + ' Minutes') + tkSetClockH.set(str(strompi_hour).zfill(2) + ' Hours') + tkSetClockM.set(str(strompi_min).zfill(2) + ' Minutes') + tkSetDateD.set(str(strompi_day).zfill(2) + ' Day') + tkSetDateM.set(str(strompi_month).zfill(2)) + tkSetDateWD.set(weekday_converter(int(sp3_weekday))) + tkSetDateY.set(str(strompi_year).zfill(2) + ' Year') + tkPoweroffMode.set('Poweroff Mode: ' + enabled_disabled_converter(int(sp3_poweroffMode))) + tkPoweroff_time.set(str(sp3_poweroff_time, 'utf-8').rstrip('\n').zfill(2) + ' Minutes') + tkfirmwareVersion.set(str(sp3_firmwareVersion, 'utf-8').strip('\nv').zfill(2)) + serial_port.close() + +def alarmPoweroffhourFocusIn(alarmPoweroffhour): + alarmPoweroffhour = tkAlarmPoweroffhour.get() + alarmPoweroffhour = ''.join([i for i in alarmPoweroffhour if i.isdigit()]) + tkAlarmPoweroffhour.set(alarmPoweroffhour) + +def alarmPoweroffhourFocusOut(alarmPoweroffhour): + alarmPoweroffhour = ''.join([i for i in alarmPoweroffhour if i.isdigit()]) + tkAlarmPoweroffhour.set(alarmPoweroffhour + " Hours") + +def alarmPoweroffminFocusIn(alarmPoweroffmin): + alarmPoweroffmin = tkAlarmPoweroffmin.get() + alarmPoweroffmin = ''.join([i for i in alarmPoweroffmin if i.isdigit()]) + tkAlarmPoweroffmin.set(alarmPoweroffmin) + +def alarmPoweroffminFocusOut(alarmPoweroffmin): + alarmPoweroffmin = ''.join([i for i in alarmPoweroffmin if i.isdigit()]) + tkAlarmPoweroffmin.set(alarmPoweroffmin + " Minutes") + +def alarmPoweroffdayFocusIn(alarmPoweroffday): + alarmPoweroffday = tkAlarmPoweroffday.get() + alarmPoweroffday = ''.join([i for i in alarmPoweroffday if i.isdigit()]) + tkAlarmPoweroffday.set(alarmPoweroffday) + +def alarmPoweroffdayFocusOut(alarmPoweroffday): + alarmPoweroffday = ''.join([i for i in alarmPoweroffday if i.isdigit()]) + tkAlarmPoweroffday.set(alarmPoweroffday + " Day") + +def WakeUpMinFocusIn(WakeUpMin): + WakeUpMin = tkAlarmminoff.get() + WakeUpMin = ''.join([i for i in WakeUpMin if i.isdigit()]) + tkAlarmminoff.set(WakeUpMin) + +def WakeUpMinFocusOut(WakeUpMin): + WakeUpMin = ''.join([i for i in WakeUpMin if i.isdigit()]) + tkAlarmminoff.set(WakeUpMin + " Minutes") + +def WakeUpHourFocusIn(WakeUpHour): + WakeUpHour = tkAlarmhouroff.get() + WakeUpHour = ''.join([i for i in WakeUpHour if i.isdigit()]) + tkAlarmhouroff.set(WakeUpHour) + +def WakeUpHourFocusOut(WakeUpHour): + WakeUpHour = ''.join([i for i in WakeUpHour if i.isdigit()]) + tkAlarmhouroff.set(WakeUpHour + " Hours") + +def AlarmminonFocusIn(IntervalAlarmOnTime): + IntervalAlarmOnTime = tkIntervalAlarmOnTime.get() + IntervalAlarmOnTime = ''.join([i for i in IntervalAlarmOnTime if i.isdigit()]) + tkIntervalAlarmOnTime.set(IntervalAlarmOnTime) + +def AlarmminonFocusOut(IntervalAlarmOnTime): + IntervalAlarmOnTime = ''.join([i for i in IntervalAlarmOnTime if i.isdigit()]) + tkIntervalAlarmOnTime.set(IntervalAlarmOnTime + " Minutes") + +def AlarmminoffFocusIn(IntervalAlarmOffTime): + IntervalAlarmOffTime = tkIntervalAlarmOffTime.get() + IntervalAlarmOffTime = ''.join([i for i in IntervalAlarmOffTime if i.isdigit()]) + tkIntervalAlarmOffTime.set(IntervalAlarmOffTime) + +def AlarmminoffFocusOut(IntervalAlarmOffTime): + IntervalAlarmOffTime = ''.join([i for i in IntervalAlarmOffTime if i.isdigit()]) + tkIntervalAlarmOffTime.set(IntervalAlarmOffTime + " Minutes") + +def ShutdownTimeFocusIn(ShutdownTime): + ShutdownTime = tkshutdown_time.get() + ShutdownTime = ''.join([i for i in ShutdownTime if i.isdigit()]) + tkshutdown_time.set(ShutdownTime) + +def ShutdownTimeFocusOut(ShutdownTime): + ShutdownTime = ''.join([i for i in ShutdownTime if i.isdigit()]) + tkshutdown_time.set(ShutdownTime + " Seconds") + +def PoweronButtonTimeFocusIn(PoweronButtonTime): + PoweronButtonTime = tkButton_time.get() + PoweronButtonTime = ''.join([i for i in PoweronButtonTime if i.isdigit()]) + tkButton_time.set(PoweronButtonTime) + +def PoweronButtonTimeFocusOut(PoweronButtonTime): + PoweronButtonTime = ''.join([i for i in PoweronButtonTime if i.isdigit()]) + tkButton_time.set(PoweronButtonTime + " Seconds") + +def PoweroffTimeFocusIn(Poweroff_time_tmp): + Poweroff_time_tmp = tkPoweroff_time.get() + Poweroff_time_tmp = ''.join([i for i in Poweroff_time_tmp if i.isdigit()]) + tkPoweroff_time.set(Poweroff_time_tmp) + +def PoweroffTimeFocusOut(Poweroff_time_tmp): + Poweroff_time_tmp = ''.join([i for i in Poweroff_time_tmp if i.isdigit()]) + tkPoweroff_time.set(Poweroff_time_tmp + " Minutes") + +def loading_process(): + if serial_port.isOpen(): serial_port.close() + serial_port.open() + + serial_port.write(str.encode('quit')) + sleep(breakS) + serial_port.write(str.encode('\x0D')) + sleep(breakL) + serial_port.write(str.encode('status-rpi')) + sleep(1) + serial_port.write(str.encode('\x0D')) + sp3_time = serial_port.readline(9999); + sp3_date = serial_port.readline(9999); + sp3_weekday = serial_port.readline(9999); + sp3_modus = serial_port.readline(9999); + sp3_alarm_enable = serial_port.readline(9999); + sp3_alarm_mode = serial_port.readline(9999); + sp3_alarm_hour = serial_port.readline(9999); + sp3_alarm_min = serial_port.readline(9999); + sp3_alarm_day = serial_port.readline(9999); + sp3_alarm_month = serial_port.readline(9999); + sp3_alarm_weekday = serial_port.readline(9999); + sp3_alarmPoweroff = serial_port.readline(9999); + sp3_alarm_hour_off = serial_port.readline(9999); + sp3_alarm_min_off = serial_port.readline(9999); + sp3_shutdown_enable = serial_port.readline(9999); + sp3_shutdown_time = serial_port.readline(9999); + sp3_warning_enable = serial_port.readline(9999); + sp3_serialLessMode = serial_port.readline(9999); + sp3_intervalAlarm = serial_port.readline(9999); + sp3_intervalAlarmOnTime = serial_port.readline(9999); + sp3_intervalAlarmOffTime = serial_port.readline(9999); + sp3_batLevel_shutdown = serial_port.readline(9999); + sp3_batLevel = serial_port.readline(9999); + sp3_charging = serial_port.readline(9999); + sp3_powerOnButton_enable = serial_port.readline(9999); + sp3_powerOnButton_time = serial_port.readline(9999); + sp3_powersave_enable = serial_port.readline(9999); + sp3_poweroffMode = serial_port.readline(9999); + sp3_poweroff_time_enable = serial_port.readline(9999); + sp3_poweroff_time = serial_port.readline(9999); + sp3_wakeupweekend_enable = serial_port.readline(9999); + sp3_ADC_Wide = float(serial_port.readline(9999))/1000; + sp3_ADC_BAT = float(serial_port.readline(9999))/1000; + sp3_ADC_USB = float(serial_port.readline(9999))/1000; + sp3_ADC_OUTPUT = float(serial_port.readline(9999))/1000; + sp3_output_status = serial_port.readline(9999); + sp3_powerfailure_counter = serial_port.readline(9999); + sp3_firmwareVersion = serial_port.readline(9999); + sp3_modus_temp = int(sp3_modus) + sleep(2) + root.destroy() + +def _on_mousewheel(event,scroll): + canvas.yview_scroll(int(scroll), "units") + + +root = tk.Tk() +root.title("Strompi V3 Serial Config Tool") +root.geometry("400x300") +root.configure(background="#275c6b") +root.overrideredirect(True) +root.eval('tk::PlaceWindow . center') +load = Label(root, text="Loading...", fg="snow", bg="#275c6b",font='Helvetica 18 bold',width=400, height=150, anchor=CENTER) +load.pack() +root.iconphoto(True, ImageTk.PhotoImage(Image.open("favicon.png"))) +root.after(200,loading_process) +root.mainloop() + + +#----------------Graphic User Interface------------------------ +fenster = tk.Tk() +fenster.title("Strompi V3 Serial Config Tool") +fenster.geometry("1000x600") +#fenster.resizable(width="false", height="true") +fenster.iconphoto(True, ImageTk.PhotoImage(Image.open("favicon.png"))) +mainframe = Frame(fenster) +mainframe.pack(fill=BOTH, expand=1) +canvas = Canvas(mainframe) +canvas.pack(side=LEFT, fill=BOTH, expand=1) +scrollbar = tk.Scrollbar(mainframe, orient=VERTICAL, command=canvas.yview) +scrollbar.pack(side=RIGHT, fill=Y) +canvas.configure(yscrollcommand=scrollbar.set) +canvas.bind_all("", fp(_on_mousewheel, scroll=-1)) +canvas.bind_all("", fp(_on_mousewheel, scroll=1)) +canvas.bind('', lambda e: canvas.configure(scrollregion=canvas.bbox("all"))) +fenster.bind_all("", _on_mousewheel) +frame = Frame(canvas) +frame.configure(background="#275c6b") +canvas.create_window((0,0), window=frame, anchor="nw") + +#Choice Variables +modechoices = [ '1 = mUSB -> Wide', '2 = Wide -> mUSB', '3 = mUSB -> Battery', '4 = Wide -> Battery', '5 = mUSB -> Wide -> Battery', '6 = Wide -> mUSB -> Battery'] +EnableDisableChoice = [ '0 = disable' , '1 = enable'] +BatShutdownChoices = ['0 = disable', '1 = below 10%', '2 = below 25%', '3 = below 50%'] +TimeSyncChoices = ['No Change','Sync with StromPi3', 'Manual Setting'] +Alarm_ModeChoices = ['1 = Daily time alarm', '2 = Date controlled time alarm', '3 = Weekly time alarm', '4 = Minute Wakeup-Alarm'] +Month_Choices = ['1 = January', '2 = February', '3 = March', '4 = April', '5 = May', '6 = June', '7 = July', '8 = August', '9 = September', '10 = October', '11 = November', '12 = December'] +Day_Choices = ['1 = Monday', '2 = Tuesday', '3 = Wednesday', '4 = Thursday', '5 = Friday', '6 = Saturday', '7 = Sunday'] +#Create Variables +tkshutdown_time = StringVar(frame) +tkButton_time = StringVar(frame) +tkmode = StringVar(frame) +tkShutdownMode = StringVar(frame) +tkBatShutdown = StringVar(frame) +tkSerialless = StringVar(frame) +tkPowerfailWarning = StringVar(frame) +tkPoweronButton = StringVar(frame) +tkTimeSync = StringVar(frame) +tkSetClockH = StringVar(frame) +tkSetClockM = StringVar(frame) +tkSetDateD = StringVar(frame) +tkSetDateM = StringVar(frame) +tkSetDateWD = StringVar(frame) +tkSetDateY = StringVar(frame) +tkAlarm_Mode = StringVar(frame) +tkIntervalAlarm = StringVar(frame) +tkWakeupAlarm = StringVar(frame) +tkAlarmPoweroff = StringVar(frame) +tkAlarmPoweroffmin = StringVar(frame) +tkAlarmPoweroffhour = StringVar(frame) +tkAlarmPoweroffweekday = StringVar(frame) +tkAlarmPoweroffmonth = StringVar(frame) +tkAlarmPoweroffday = StringVar(frame) +tkAlarmminoff = StringVar(frame) +tkAlarmhouroff = StringVar(frame) +tkIntervalAlarmOnTime = StringVar(frame) +tkIntervalAlarmOffTime = StringVar(frame) +tkPowerSave = StringVar(frame) +tkPoweroffMode = StringVar(frame) +tkPoweroff_time = StringVar(frame) +tkwakeupweekend_enable = StringVar(frame) +tkfirmwareVersion = StringVar(frame) +#Frames +SetClockFrame1 = LabelFrame(frame, text="Real Time Clock Settings", fg="snow", bg="#275c6b") +SetClockFrame1.grid(row = 1, column = 1, columnspan=3, rowspan=1, padx=30, pady=20, sticky=NW) +EnableDisableFrame = LabelFrame(frame, text="Options Without Timesettings:", fg="snow", bg="#275c6b") +EnableDisableFrame.grid(row = 1, column = 0, columnspan=1, rowspan=1, sticky=W, padx=30, pady=10) +SetShutdownFrame = LabelFrame(frame, text="Shutdown Timer", fg="snow", bg="#275c6b") +SetShutdownFrame.grid(row = 1, column = 1, columnspan=2, rowspan=1, sticky=SW, padx=30, pady=10) +PowerOnButtonFrame = LabelFrame(frame, text="PowerOnButton", fg="snow", bg="#275c6b") +PowerOnButtonFrame.grid(row = 2, column = 1, columnspan=2, rowspan=1, sticky=W, padx=30, pady=10) +IntervalAlarmFrame = LabelFrame(frame, text="Interval Timer", fg="snow", bg="#275c6b") +IntervalAlarmFrame.grid(row = 3, column = 0, columnspan=3, rowspan=1, sticky=W, padx=30, pady=10) +AlarmModeFrame = LabelFrame(frame, text="Alarm Modes", fg="snow", bg="#275c6b") +AlarmModeFrame.grid(row = 4, column = 0, columnspan=3, rowspan=1, sticky=W, padx=30, pady=10) +PowerOffModeFrame = LabelFrame(frame, text="Poweroff Mode", fg="snow", bg="#275c6b") +PowerOffModeFrame.grid(row = 2, column = 0, columnspan=1, rowspan=1, sticky=W, padx=30, pady=10) +FirmwareVersionFrame = LabelFrame(frame, text="Firmware Version", fg="snow", bg="#233f4e") +FirmwareVersionFrame.grid(row = 5, column = 0, sticky=W, padx=30, pady=10) +#Create GUI Objects +#-------------------------------------------------------------------------------------------------------------- +#sp3_poweroff_time GUI OBJECTS +poweroff_timelbl = Label(AlarmModeFrame, text="Minute Wakeup Time:", fg="snow", bg="#275c6b").grid(row = 18, column = 3, columnspan=1, rowspan=1, sticky=W) +poweroff_timeBox = Spinbox(AlarmModeFrame,from_=0, to =65535, textvariable=tkPoweroff_time) +poweroff_timeBox.configure(background="#233f4e", foreground="snow") +poweroff_timeBox.grid(row = 19, column = 3, columnspan=1, rowspan=1, sticky=W) +poweroff_timeBox.insert(0, "0") +poweroff_timeBox.bind("", (lambda event: PoweroffTimeFocusIn(tkPoweroff_time.get()))) +poweroff_timeBox.bind("", (lambda event: PoweroffTimeFocusOut(tkPoweroff_time.get()))) +#Powerpath GUI Objects +modepopupMenu = OptionMenu(EnableDisableFrame, tkmode, *modechoices) +modepopupMenu.configure(background="#233f4e", foreground="snow", activeforeground="#233f4e", activebackground="snow") +modepopupMenu["menu"].config(background="#233f4e", foreground="snow", activeforeground="#233f4e", activebackground="snow") +modelbl = Label(EnableDisableFrame, text="Choose StromPi V3 Powerpath Mode:", fg="snow", bg="#275c6b").grid(row = 0, column = 0, columnspan=1, rowspan=1, sticky=W) +modepopupMenu.grid(row = 1, column =0, columnspan=1, rowspan=1, sticky=W) +#Shutdown Mode GUI Objects +ShutdownModepopupMenu = OptionMenu(SetShutdownFrame, tkShutdownMode, *EnableDisableChoice) +ShutdownModelbl = Label(SetShutdownFrame, text="Choose Shutdown Mode: ", fg="snow", bg="#275c6b").grid(row = 8, column = 0, columnspan=1, rowspan=1, sticky=W) +ShutdownModepopupMenu.grid(row = 9, column =0, columnspan=1, rowspan=1, sticky=W) +ShutdownModepopupMenu.configure(background="#233f4e", foreground="snow", activeforeground="#233f4e", activebackground="snow") +ShutdownModepopupMenu["menu"].config(background="#233f4e", foreground="snow", activeforeground="#233f4e", activebackground="snow") +#Batery Level Shutdown GUI Objects +BatShutdownpopupMenu = OptionMenu(EnableDisableFrame, tkBatShutdown, *BatShutdownChoices) +BatShutdownlbl = Label(EnableDisableFrame, text="Choose Battery Shutdown Mode:", fg="snow", bg="#275c6b").grid(row = 4, column = 0, columnspan=1, rowspan=1, sticky=W) +BatShutdownpopupMenu.grid(row = 5, column =0, columnspan=1, rowspan=1, sticky=W) +BatShutdownpopupMenu.configure(background="#233f4e", foreground="snow", activeforeground="#233f4e", activebackground="snow") +BatShutdownpopupMenu["menu"].config(background="#233f4e", foreground="snow", activeforeground="#233f4e", activebackground="snow") +#Serialless GUI Objects +SeriallesspopupMenu = OptionMenu(EnableDisableFrame, tkSerialless, *EnableDisableChoice) +Seriallesslbl = Label(EnableDisableFrame, text="Choose Serialless Mode:", fg="snow", bg="#275c6b").grid(row = 6, column = 0, columnspan=1, rowspan=1, sticky=W) +SeriallesspopupMenu.grid(row = 7, column =0, columnspan=1, rowspan=1, sticky=W) +SeriallesspopupMenu.configure(background="#233f4e", foreground="snow", activeforeground="#233f4e", activebackground="snow") +SeriallesspopupMenu["menu"].config(background="#233f4e", foreground="snow", activeforeground="#233f4e", activebackground="snow") +#Seriallesslbl.configure(background="snow") +PowerfailpopupMenu = OptionMenu(EnableDisableFrame, tkPowerfailWarning, *EnableDisableChoice) +Powerfaillbl = Label(EnableDisableFrame, text="Choose Powerfail Warning Mode:", fg="snow", bg="#275c6b").grid(row = 2, column = 0, columnspan=1, rowspan=1, sticky=W) +PowerfailpopupMenu.grid(row = 3, column =0, columnspan=1, rowspan=1, sticky=W) +PowerfailpopupMenu.configure(background="#233f4e", foreground="snow", activeforeground="#233f4e", activebackground="snow") +PowerfailpopupMenu["menu"].config(background="#233f4e", foreground="snow", activeforeground="#233f4e", activebackground="snow") +#PowerSaveMode GUI Objects +PowerSavepopupMenu = OptionMenu(EnableDisableFrame, tkPowerSave, *EnableDisableChoice) +PowerSavelbl = Label(EnableDisableFrame, text="Choose Power Save Mode: ", fg="snow", bg="#275c6b").grid(row = 10, column = 0, columnspan=1, rowspan=1, sticky=W) +PowerSavepopupMenu.grid(row = 11, column =0, columnspan=1, rowspan=1, sticky=W) +PowerSavepopupMenu.configure(background="#233f4e", foreground="snow", activeforeground="#233f4e", activebackground="snow") +PowerSavepopupMenu["menu"].config(background="#233f4e", foreground="snow", activeforeground="#233f4e", activebackground="snow") +#sp3_wakeupweekend_enable GUI Objects +wakeupweekendpopupMenu = OptionMenu(AlarmModeFrame, tkwakeupweekend_enable, *EnableDisableChoice) +wakeupweekendlbl = Label(AlarmModeFrame, text="Activate WakeupAlarm on weekend?:", fg="snow", bg="#275c6b").grid(row = 20, column = 0, columnspan=1, rowspan=1, sticky=W) +wakeupweekendpopupMenu.grid(row = 21, column =0, columnspan=1, rowspan=1, sticky=W) +wakeupweekendpopupMenu.configure(background="#233f4e", foreground="snow", activeforeground="#233f4e", activebackground="snow") +wakeupweekendpopupMenu["menu"].config(background="#233f4e", foreground="snow", activeforeground="#233f4e", activebackground="snow") +#PowerOnButton GUI Objects +PoweronButtonpopupMenu = OptionMenu(PowerOnButtonFrame, tkPoweronButton, *EnableDisableChoice) +PoweronButtonlbl = Label(PowerOnButtonFrame, text="Choose PowerOn-Button Mode: ", fg="snow", bg="#275c6b").grid(row = 10, column = 0, columnspan=1, rowspan=1, sticky=W) +PoweronButtonpopupMenu.grid(row = 11, column =0, columnspan=1, rowspan=1, sticky=W) +PoweronButtonpopupMenu.configure(background="#233f4e", foreground="snow", activeforeground="#233f4e", activebackground="snow") +PoweronButtonpopupMenu["menu"].config(background="#233f4e", foreground="snow", activeforeground="#233f4e", activebackground="snow") +#sp3_shutdown_time GUI OBJECTS +ShutdownTimelbl = Label(SetShutdownFrame, text="Choose Shutdown timer: ", fg="snow", bg="#275c6b").grid(row = 8, column = 1, columnspan=1, rowspan=1, sticky=W) +ShutdownTimeBox = Spinbox(SetShutdownFrame,from_=0,to=65535, textvariable=tkshutdown_time) +ShutdownTimeBox.configure(background="#233f4e", foreground="snow") +ShutdownTimeBox.grid(row = 9, column = 1, columnspan=1, rowspan=1, sticky=W) +ShutdownTimeBox.insert(0, "0") +ShutdownTimeBox.bind("", (lambda event: ShutdownTimeFocusIn(tkshutdown_time.get()))) +ShutdownTimeBox.bind("", (lambda event: ShutdownTimeFocusOut(tkshutdown_time.get()))) +#sp3_powerOnButton_time GUI OBJECTS +PoweronButtonTimelbl = Label(PowerOnButtonFrame, text="Choose Button Shutdown time:", fg="snow", bg="#275c6b").grid(row = 10, column = 1, columnspan=1, rowspan=1, sticky=W) +PoweronButtonTimeBox = Spinbox(PowerOnButtonFrame,from_=30,to=65535, textvariable=tkButton_time) +PoweronButtonTimeBox.configure(background="#233f4e", foreground="snow") +PoweronButtonTimeBox.grid(row = 11, column = 1, columnspan=1, rowspan=1, sticky=W) +PoweronButtonTimeBox.insert(0, "0") +PoweronButtonTimeBox.bind("", (lambda event: PoweronButtonTimeFocusIn(tkButton_time.get()))) +PoweronButtonTimeBox.bind("", (lambda event: PoweronButtonTimeFocusOut(tkButton_time.get()))) +#Alarm-Mode GUI OBJECTS +Alarm_ModepopupMenu = OptionMenu(AlarmModeFrame, tkAlarm_Mode, *Alarm_ModeChoices) +Powerfaillbl = Label(AlarmModeFrame, text="Choose Alarm Mode:", fg="snow", bg="#275c6b").grid(row = 14, column = 0, columnspan=1, rowspan=1, sticky=W) +Alarm_ModepopupMenu.grid(row = 15, column =0, columnspan=1, rowspan=1, sticky=W) +Alarm_ModepopupMenu.configure(background="#233f4e", foreground="snow", activeforeground="#233f4e", activebackground="snow") +Alarm_ModepopupMenu["menu"].config(background="#233f4e", foreground="snow", activeforeground="#233f4e", activebackground="snow") +#sp3_intervalAlarm GUI OBJECTS +IntervalAlarmpopupMenu = OptionMenu(IntervalAlarmFrame, tkIntervalAlarm, *EnableDisableChoice) +IntervalAlarmlbl = Label(IntervalAlarmFrame, text="Choose Interval-Alarm Mode: ", fg="snow", bg="#275c6b").grid(row = 12, column = 0, columnspan=1, rowspan=1, sticky=W) +IntervalAlarmpopupMenu.grid(row = 13, column =0, columnspan=1, rowspan=1, sticky=W) +IntervalAlarmpopupMenu.configure(background="#233f4e", foreground="snow", activeforeground="#233f4e", activebackground="snow") +IntervalAlarmpopupMenu["menu"].config(background="#233f4e", foreground="snow", activeforeground="#233f4e", activebackground="snow") +#sp3_alarm_enable GUI OBJECTS +WakeupAlarmpopupMenu = OptionMenu(AlarmModeFrame, tkWakeupAlarm, *EnableDisableChoice) +WakeupAlarmlbl = Label(AlarmModeFrame, text="Choose WakeUp-Alarm Mode:", fg="snow", bg="#275c6b").grid(row = 16, column = 0, columnspan=1, rowspan=1, sticky=W) +WakeupAlarmpopupMenu.grid(row = 17, column =0, columnspan=1, rowspan=1, sticky=W) +WakeupAlarmpopupMenu.configure(background="#233f4e", foreground="snow", activeforeground="#233f4e", activebackground="snow") +WakeupAlarmpopupMenu["menu"].config(background="#233f4e", foreground="snow", activeforeground="#233f4e", activebackground="snow") +#sp3_alarmPoweroff GUI OBJECTS +alarmPoweroffpopupMenu = OptionMenu(AlarmModeFrame, tkAlarmPoweroff, *EnableDisableChoice) +alarmPowerofflbl = Label(AlarmModeFrame, text="Choose Power-Off Alarm Mode: ", fg="snow", bg="#275c6b").grid(row = 18, column = 0, columnspan=1, rowspan=1, sticky=W) +alarmPoweroffpopupMenu.grid(row = 19, column =0, columnspan=1, rowspan=1, sticky=W) +alarmPoweroffpopupMenu.configure(background="#233f4e", foreground="snow", activeforeground="#233f4e", activebackground="snow") +alarmPoweroffpopupMenu["menu"].config(background="#233f4e", foreground="snow", activeforeground="#233f4e", activebackground="snow") +#sp3_poweroffMode GUI OBJECTS +poweroffModepopupMenu = OptionMenu(PowerOffModeFrame, tkPoweroffMode, *EnableDisableChoice) +poweroffModelbl = Label(PowerOffModeFrame, text="Choose Poweroff Mode: ", fg="snow", bg="#275c6b").grid(row = 18, column = 0, columnspan=1, rowspan=1, sticky=W) +poweroffModepopupMenu.grid(row = 19, column =0, columnspan=1, rowspan=1, sticky=W) +poweroffModepopupMenu.configure(background="#233f4e", foreground="snow", activeforeground="#233f4e", activebackground="snow") +poweroffModepopupMenu["menu"].config(background="#233f4e", foreground="snow", activeforeground="#233f4e", activebackground="snow") +#sp3_alarmPoweroff Minute GUI OBJECTS +alarmPoweroffminlbl = Label(AlarmModeFrame, text="Choose Power-Off Minutes:", fg="snow", bg="#275c6b").grid(row = 18, column = 1, columnspan=1, rowspan=1, sticky=W) +alarmPoweroffminBox = Spinbox(AlarmModeFrame,from_=0, to =59, textvariable=tkAlarmPoweroffmin) +alarmPoweroffminBox.configure(background="#233f4e", foreground="snow") +alarmPoweroffminBox.grid(row = 19, column = 1, columnspan=1, rowspan=1, sticky=W) +alarmPoweroffminBox.insert(0, "0") +alarmPoweroffminBox.bind("", (lambda event: alarmPoweroffminFocusIn(tkAlarmPoweroffmin.get()))) +alarmPoweroffminBox.bind("", (lambda event: alarmPoweroffminFocusOut(tkAlarmPoweroffmin.get()))) +#sp3_alarmPoweroff Hour GUI OBJECTS +alarmPoweroffhourlbl = Label(AlarmModeFrame, text="Choose Power-Off Hours:", fg="snow", bg="#275c6b").grid(row = 18, column = 2, columnspan=1, rowspan=1, sticky=W) +alarmPoweroffhourBox = Spinbox(AlarmModeFrame,from_=0, to =23, textvariable=tkAlarmPoweroffhour) +alarmPoweroffhourBox.configure(background="#233f4e", foreground="snow") +alarmPoweroffhourBox.grid(row = 19, column = 2, columnspan=1, rowspan=1, sticky=W) +alarmPoweroffhourBox.insert(0, "0") +alarmPoweroffhourBox.bind("", (lambda event: alarmPoweroffhourFocusIn(tkAlarmPoweroffhour.get()))) +alarmPoweroffhourBox.bind("", (lambda event: alarmPoweroffhourFocusOut(tkAlarmPoweroffhour.get()))) +#sp3_alarm_day GUI OBJECTS +alarmPoweroffdaylbl = Label(AlarmModeFrame, text="Choose Alarm Day: ", fg="snow", bg="#275c6b").grid(row = 14, column = 2, columnspan=1, rowspan=1, sticky=W) +alarmPoweroffdayBox = Spinbox(AlarmModeFrame,from_=1, to =31, textvariable=tkAlarmPoweroffday) +alarmPoweroffdayBox.configure(background="#233f4e", foreground="snow") +alarmPoweroffdayBox.grid(row = 15, column = 2, columnspan=1, rowspan=1, sticky=W) +alarmPoweroffdayBox.insert(0, "0") +alarmPoweroffdayBox.bind("", (lambda event: alarmPoweroffdayFocusIn(tkAlarmPoweroffday.get()))) +alarmPoweroffdayBox.bind("", (lambda event: alarmPoweroffdayFocusOut(tkAlarmPoweroffday.get()))) +#sp3_alarm_weekday GUI OBJECTS +AlarmPoweroffweekdaypopupMenu = OptionMenu(AlarmModeFrame, tkAlarmPoweroffweekday, *Day_Choices) +AlarmPoweroffweekdaylbl = Label(AlarmModeFrame, text="Choose Alarm Weekday:", fg="snow", bg="#275c6b").grid(row = 14, column = 1, columnspan=1, rowspan=1, sticky=W) +AlarmPoweroffweekdaypopupMenu.grid(row = 15, column =1, columnspan=1, rowspan=1, sticky=W) +AlarmPoweroffweekdaypopupMenu.configure(background="#233f4e", foreground="snow", activeforeground="#233f4e", activebackground="snow") +AlarmPoweroffweekdaypopupMenu["menu"].config(background="#233f4e", foreground="snow", activeforeground="#233f4e", activebackground="snow") +#sp3_alarm_month GUI OBJECTS +AlarmPoweroffmonthpopupMenu = OptionMenu(AlarmModeFrame, tkAlarmPoweroffmonth, *Month_Choices) +AlarmPoweroffmonthlbl = Label(AlarmModeFrame, text="Alarm Month:", fg="snow", bg="#275c6b").grid(row = 14, column = 3, columnspan=1, rowspan=1, sticky=W) +AlarmPoweroffmonthpopupMenu.grid(row = 15, column =3, columnspan=1, rowspan=1, sticky=W) +AlarmPoweroffmonthpopupMenu.configure(background="#233f4e", foreground="snow", activeforeground="#233f4e", activebackground="snow") +AlarmPoweroffmonthpopupMenu["menu"].config(background="#233f4e", foreground="snow", activeforeground="#233f4e", activebackground="snow") +#sp3_alarm_min_off GUI OBJECTS +WakeUpMinlbl = Label(AlarmModeFrame, text="Setting WakeUp-Alarm Minute: ", fg="snow", bg="#275c6b").grid(row = 16, column = 1, columnspan=1, rowspan=1, sticky=W) +WakeUpMinBox = Spinbox(AlarmModeFrame,from_=0,to=59, textvariable=tkAlarmminoff) +WakeUpMinBox.configure(background="#233f4e", foreground="snow") +WakeUpMinBox.grid(row = 17, column = 1, columnspan=1, rowspan=1, sticky=W) +WakeUpMinBox.insert(0, "0") +WakeUpMinBox.bind("", (lambda event: WakeUpMinFocusIn(tkAlarmminoff.get()))) +WakeUpMinBox.bind("", (lambda event: WakeUpMinFocusOut(tkAlarmminoff.get()))) +#sp3_alarm_hour_off GUI OBJECTS +WakeUpHourlbl = Label(AlarmModeFrame, text="Setting WakeUp-Alarm Hour:", fg="snow", bg="#275c6b").grid(row = 16, column = 2, columnspan=1, rowspan=1, sticky=W) +WakeUpHourBox = Spinbox(AlarmModeFrame,from_=0,to=23, textvariable=tkAlarmhouroff) +WakeUpHourBox.configure(background="#233f4e", foreground="snow") +WakeUpHourBox.grid(row = 17, column = 2, columnspan=1, rowspan=1, sticky=W) +WakeUpHourBox.insert(0, "0") +WakeUpHourBox.bind("", (lambda event: WakeUpHourFocusIn(tkAlarmhouroff.get()))) +WakeUpHourBox.bind("", (lambda event: WakeUpHourFocusOut(tkAlarmhouroff.get()))) +#sp3_intervalAlarmOnTime GUI OBJECTS +Alarmminonlbl = Label(IntervalAlarmFrame, text="Interval On-Time Minute: ", fg="snow", bg="#275c6b").grid(row = 12, column = 1, columnspan=1, rowspan=1, sticky=W) +AlarmminonBox = Spinbox(IntervalAlarmFrame,from_=0,to=65535, textvariable=tkIntervalAlarmOnTime) +AlarmminonBox.configure(background="#233f4e", foreground="snow") +AlarmminonBox.grid(row = 13, column = 1, columnspan=1, rowspan=1, sticky=W) +AlarmminonBox.insert(0, "0") +AlarmminonBox.bind("", (lambda event: AlarmminonFocusIn(tkIntervalAlarmOnTime.get()))) +AlarmminonBox.bind("", (lambda event: AlarmminonFocusOut(tkIntervalAlarmOnTime.get()))) +#sp3_intervalAlarmOffTime GUI OBJECTS +Alarmminofflbl = Label(IntervalAlarmFrame, text="Interval Off-Time Minute: ", fg="snow", bg="#275c6b").grid(row = 12, column = 2, columnspan=1, rowspan=1, sticky=W) +AlarmminoffBox = Spinbox(IntervalAlarmFrame,from_=0,to=65535, textvariable=tkIntervalAlarmOffTime) +AlarmminoffBox.configure(background="#233f4e", foreground="snow") +AlarmminoffBox.grid(row = 13, column = 2, columnspan=1, rowspan=1, sticky=W) +AlarmminoffBox.insert(0, "0") +AlarmminoffBox.bind("", (lambda event: AlarmminoffFocusIn(tkIntervalAlarmOffTime.get()))) +AlarmminoffBox.bind("", (lambda event: AlarmminoffFocusOut(tkIntervalAlarmOffTime.get()))) +#Joy-IT-Logo +Logo1 = ImageTk.PhotoImage(Image.open("logo.gif")) +Panel = Label(frame, image = Logo1, borderwidth=0, highlightthickness = 0) +Panel.grid(row = 0, column = 0, columnspan = 4, rowspan = 1, sticky=N, pady = 10, padx = 10) +#SetClockH +SetClockHlbl = Label(SetClockFrame1, text="Set the Hours: ", fg="snow", bg="#275c6b").grid(row = 0, column = 3, columnspan=1, rowspan=1, sticky=W) +SetClockHBox = Spinbox(SetClockFrame1,from_=0,to=23, textvariable=tkSetClockH) +SetClockHBox.configure(background="#233f4e", foreground="snow") +SetClockHBox.grid(row = 1, column = 3, columnspan=1, rowspan=1, sticky=W) +SetClockHBox.insert(0, "0") +SetClockHBox.bind("", (lambda event: SetClockHFocusIn(tkSetClockH.get()))) +SetClockHBox.bind("", (lambda event: SetClockHFocusOut(tkSetClockH.get()))) +#SetClockM +SetClockMlbl = Label(SetClockFrame1, text="Set the Minutes:", fg="snow", bg="#275c6b").grid(row = 0, column = 4, columnspan=1, rowspan=1, sticky=W) +SetClockMBox = Spinbox(SetClockFrame1,from_=0,to=59, textvariable=tkSetClockM) +SetClockMBox.configure(background="#233f4e", foreground="snow") +SetClockMBox.grid(row = 1, column = 4, columnspan=1, rowspan=1, sticky=W) +SetClockMBox.insert(0, "0") +SetClockMBox.bind("", (lambda event: SetClockMFocusIn(tkSetClockM.get()))) +SetClockMBox.bind("", (lambda event: SetClockMFocusOut(tkSetClockM.get()))) +#SetDateM +SetDateMpopupMenu = OptionMenu(SetClockFrame1, tkSetDateM, *Month_Choices) +SetDateMpopupMenu.configure(background="#233f4e", foreground="snow", activeforeground="#233f4e", activebackground="snow") +SetDateMpopupMenu["menu"].config(background="#233f4e", foreground="snow", activeforeground="#233f4e", activebackground="snow") +SetDateMlbl = Label(SetClockFrame1, text="Set the Month:", fg="snow", bg="#275c6b").grid(row = 4, column = 3, columnspan=1, rowspan=1, sticky=W) +SetDateMpopupMenu.grid(row = 5, column =3, columnspan=1, rowspan=1, sticky=W) +#SetDateWD +SetDateWDpopupMenu = OptionMenu(SetClockFrame1, tkSetDateWD, *Day_Choices) +SetDateWDpopupMenu.configure(background="#233f4e", foreground="snow", activeforeground="#233f4e", activebackground="snow") +SetDateWDpopupMenu["menu"].config(background="#233f4e", foreground="snow", activeforeground="#233f4e", activebackground="snow") +SetDateWDlbl = Label(SetClockFrame1, text="Set The Weekday:", fg="snow", bg="#275c6b").grid(row = 4, column = 4, columnspan=1, rowspan=1, sticky=W) +SetDateWDpopupMenu.grid(row = 5, column =4, columnspan=1, rowspan=1, sticky=W) +#SetDateD +SetDateDlbl = Label(SetClockFrame1, text="Set the Days:", fg="snow", bg="#275c6b").grid(row = 2, column = 3, columnspan=1, rowspan=1, sticky=W) +SetClockDBox = Spinbox(SetClockFrame1,from_=1,to=31, textvariable=tkSetDateD) +SetClockDBox.configure(background="#233f4e", foreground="snow") +SetClockDBox.grid(row = 3, column = 3, columnspan=1, rowspan=1, sticky=W) +SetClockDBox.insert(0, "0") +SetClockDBox.bind("", (lambda event: SetDateDFocusIn(tkSetDateD.get()))) +SetClockDBox.bind("", (lambda event: SetDateDFocusOut(tkSetDateD.get()))) +#SetDateD +SetDateYstr = 0 +SetDateYlbl = Label(SetClockFrame1, text="Set the Year:", fg="snow", bg="#275c6b").grid(row = 2, column = 4, columnspan=1, rowspan=1, sticky=W) +SetDateYBox = Spinbox(SetClockFrame1,from_=2000,to=65535, textvariable=tkSetDateY) +SetDateYBox.configure(background="#233f4e", foreground="snow") +SetDateYBox.grid(row = 3, column = 4, columnspan=1, rowspan=1, sticky=W) +SetDateYBox.bind("", (lambda event: SetDateYFocusIn(tkSetDateY.get()))) +SetDateYBox.bind("", (lambda event: SetDateYFocusOut(tkSetDateY.get()))) +SetDateYBox.insert(0, "0") +#Checkbox +TimeSyncLabel =Label(SetClockFrame1, text="Settings for the Clock: ", fg="snow", bg="#275c6b").grid(row = 0, column = 0, columnspan=1, rowspan=1) +TimeSyncRB1 = IntVar(frame) +RB1 = Radiobutton(SetClockFrame1, text="No Change", variable=TimeSyncRB1, value=1, fg="snow", bg="#275c6b", activeforeground="#275c6b", activebackground="snow", selectcolor="#275c6b") +RB1.grid(row=1, column=0, sticky=W) +RB1.select() +RB2 = Radiobutton(SetClockFrame1, text="Sync with RaspberryPi", variable=TimeSyncRB1, value=2,fg="snow", bg="#275c6b", activeforeground="#233f4e", activebackground="snow", selectcolor="#275c6b") +RB2.grid(row=3, column=0, sticky=W) +RB2.deselect() +RB3 = Radiobutton(SetClockFrame1, text="Manual Setting", variable=TimeSyncRB1, value=3,fg="snow", bg="#275c6b", activeforeground="#233f4e", activebackground="snow", selectcolor="#275c6b") +RB3.grid(row=2, column=0, sticky=W) +RB3.deselect() +#Firmware Version +firmwareLabel = Label(FirmwareVersionFrame, text="Version:", fg="snow", bg="#233f4e").grid(row = 0, column = 0, columnspan=1, rowspan=1) +versionLabel= Label(FirmwareVersionFrame, textvariable=tkfirmwareVersion, fg="snow", bg="#233f4e").grid(row = 0, column = 1, columnspan=1, rowspan=1) +#Info Label +Infolbl = Label(frame, text="Please read the Readme file", fg="snow", bg="#275c6b").grid(row=999, column = 0, columnspan = 1, rowspan = 1, padx=30, pady=20) +Info = Label(frame, text="", fg="snow", bg="#275c6b") +Info.grid(row=999, column = 2, columnspan = 1, rowspan = 1, padx=30, pady=20) +#Button GUI OBJECTS +Update_Button = Button(frame, text="UPDATE!", command=Upload_to_StromPi,fg="snow", bg="#233f4e",activeforeground="#233f4e", activebackground="snow",font='Helvetica 18 bold').grid(row = 999, column = 0, columnspan = 4, rowspan = 1, padx=30, pady=20) + +Refresh_Status() + + +mainframe.mainloop() + diff --git a/analogSignals/gassensorCheck.py b/analogSignals/gassensorCheck.py index b4ebed7..978261e 100644 --- a/analogSignals/gassensorCheck.py +++ b/analogSignals/gassensorCheck.py @@ -28,6 +28,8 @@ def main(): + delay = 30 + # ArgumentParser-Objekt erstellen parser = argparse.ArgumentParser(description='Lesen aller Temperatursensoren am 1-Wire-Bus') parser.add_argument('-s', '--screen', action='store_true', @@ -40,7 +42,7 @@ def main(): # Argumente parsen args = parser.parse_args() delay = int(args.delay) - delayAlarm = 1.5 + delayAlarm = 2 # Libraries anbinden cplib = CaravanPiFiles() @@ -113,9 +115,11 @@ def main(): errorcount = 0 gasDetected = False + zaehler = 0 try: # Main program loop while True: + zaehler += 1 try: # Einlesen, ob Alarm ausgegeben werden soll gassensorAlarmActive = cplib.typwandlung(cplib.readCaravanPiConfigItem("caravanpiDefaults/gassensorAlarmActive"), "bool") if cplib.readCaravanPiConfigItem("caravanpiDefaults/gassensorAlarmActive") is not None else False @@ -139,15 +143,15 @@ def main(): cplib.writeCaravanPiConfigItem("caravanpiDefaults/gassensorAlarmActive", 1) gassensorAlarmActive = True - cplib.handle_sensor_values( - args.screen, # Anzeige am Bildschirm? - "gassensor", # sensor_name = Datenbankname - "mq-2", # sensor_id = Filename und Spalte in der Datenbank - ["parts_per_million", "alarm"], # Liste Spaltennamen - ( channel.value, gasDetected) # Tupel Sensorwerte - ) - - time.sleep(delayAlarm if gasDetected else delay) + if not gasDetected or (gasDetected and zaehler >= (delay/delayAlarm)): + cplib.handle_sensor_values( + args.screen, # Anzeige am Bildschirm? + "gassensor", # sensor_name = Datenbankname + "mq-2", # sensor_id = Filename und Spalte in der Datenbank + ["parts_per_million", "alarm"], # Liste Spaltennamen + ( channel.value, gasDetected) # Tupel Sensorwerte + ) + zaehler = 0 except Exception as e: print(f"Fehler {e} ist aufgetreten") @@ -157,11 +161,14 @@ def main(): print("zu viele Fehler") return False continue - + else: # kein Fehler aufgetreten errorcount = 0 + time.sleep(delayAlarm if gasDetected else delay) + + except KeyboardInterrupt: # Alarm ausgeben, dass nicht zufällig Dauerton verbleibt beim Abbrechen cpfunc.play_alarm_single(GPIO, buzzer_pin, 1) diff --git a/analogSignals/v12Check.py b/analogSignals/v12Check.py index 8bcc3d7..728e7c3 100644 --- a/analogSignals/v12Check.py +++ b/analogSignals/v12Check.py @@ -169,9 +169,11 @@ def main(): errorcount = 0 v12DropDetected = False + zaehler = 0 try: # Main program loop while True: + zaehler += 1 try: # Einlesen, ob Alarm ausgegeben werden soll v12CheckAlarmActive = cplib.typwandlung(cplib.readCaravanPiConfigItem(f"caravanpiDefaults/{v12xmlItemAlarm}"), "bool") if cplib.readCaravanPiConfigItem(f"caravanpiDefaults/{v12xmlItemAlarm}") is not None else False @@ -211,15 +213,16 @@ def main(): cplib.writeCaravanPiConfigItem(f"caravanpiDefaults/{v12xmlItemAlarm}", 1) v12CheckAlarmActive = True - cplib.handle_sensor_values( - args.screen, # Anzeige am Bildschirm? - "Spannung", # sensor_name = Datenbankname - f"12v{args.battery}", # sensor_id = Filename und Spalte in der Datenbank - ["spannung"], # Liste Spaltennamen - (berechne_spannungsteiler(v12R1, v12R2, Vout=channel.voltage)) # Tupel Sensorwerte - ) + if not v12DropDetected or (v12DropDetected and zaehler >= (delay/delayAlarm)): + cplib.handle_sensor_values( + args.screen, # Anzeige am Bildschirm? + "spannung", # sensor_name = Datenbankname + f"12v{args.battery}", # sensor_id = Filename und Spalte in der Datenbank + ["spannung"], # Liste Spaltennamen + (berechne_spannungsteiler(v12R1, v12R2, Vout=channel.voltage),) # Tupel Sensorwerte + ) + zaehler = 0 - time.sleep(delayAlarm if v12DropDetected else delay) except Exception as e: print(f"Fehler {e} ist aufgetreten") @@ -234,6 +237,8 @@ def main(): # kein Fehler aufgetreten errorcount = 0 + time.sleep(delayAlarm if v12DropDetected else delay) + except KeyboardInterrupt: # Alarm ausgeben, dass nicht zufällig Dauerton verbleibt beim Abbrechen cpfunc.play_alarm_single(GPIO, buzzer_pin, 1) diff --git a/analogSignals/v230Check.py b/analogSignals/v230Check.py index b719e5f..fe24f54 100644 --- a/analogSignals/v230Check.py +++ b/analogSignals/v230Check.py @@ -115,10 +115,11 @@ def main(): errorcount = 0 schwelle = 2.0 v230DropDetected = False - + zaehler = 0 try: # Main program loop - while True: + while True: + zaehler += 1 try: # Einlesen, ob Alarm ausgegeben werden soll v230CheckAlarmActive = cplib.typwandlung(cplib.readCaravanPiConfigItem("caravanpiDefaults/v230CheckAlarmActive"), "bool") if cplib.readCaravanPiConfigItem("caravanpiDefaults/v230CheckAlarmActive") is not None else False @@ -144,16 +145,18 @@ def main(): print("Alarm in Config einschalten") cplib.writeCaravanPiConfigItem("caravanpiDefaults/v230CheckAlarmActive", 1) v230CheckAlarmActive = True - - cplib.handle_sensor_values( - args.screen, # Anzeige am Bildschirm? - "Spannung", # sensor_name = Datenbankname - "230v", # sensor_id = Filename und Spalte in der Datenbank - ["spannung"], # Liste Spaltennamen - (230.0 if not v230DropDetected else 0.0 ) # Tupel Sensorwerte - ) - - time.sleep(delayAlarm if v230DropDetected else delay) + + # Falls v230 Dropped, dann nicht jedesmal schreiben + + if not v230DropDetected or (v230DropDetected and zaehler >= (delay/delayAlarm)): + cplib.handle_sensor_values( + args.screen, # Anzeige am Bildschirm? + "spannung", # sensor_name = Datenbankname + "230v", # sensor_id = Filename und Spalte in der Datenbank + ["spannung"], # Liste Spaltennamen + (230.0 if not v230DropDetected else 0.0 , ) # Tupel Sensorwerte + ) + zaehler = 0 except Exception as e: print(f"Fehler {e} ist aufgetreten") @@ -168,6 +171,8 @@ def main(): # kein Fehler aufgetreten errorcount = 0 + time.sleep(delayAlarm if v230DropDetected else delay) + except KeyboardInterrupt: # Alarm ausgeben, dass nicht zufällig Dauerton verbleibt beim Abbrechen cpfunc.play_alarm_single(GPIO, buzzer_pin, 1) diff --git a/defaults/caravanpiConfig.xml b/defaults/caravanpiConfig.xml index 547a926..ba6e376 100644 --- a/defaults/caravanpiConfig.xml +++ b/defaults/caravanpiConfig.xml @@ -1,11 +1,11 @@ - 2 - 1 + 0 + 0 1 - 1 - 1 + 0 + 0 localhost caravanpi dasGeheimePasswort @@ -14,7 +14,7 @@ 8883 CaravanPiMQTT dasGeheimePasswort - 1 + 0 0 10 10 @@ -22,29 +22,29 @@ 10 10 10 - A4:C1:38:C2:06:47 - 1 + 00:00:00:00:00:00 + 0 16 1 - 1 - 1 + 0 + 0 + 0 0 - 1 - 1 + 0 + 0 + 0 2 - 0 - 1 - 3 - 0 - 26 560 150 + 0 + 0 + 0 + 3 560 150 - 0 - 0 - 0 - 1 + 0 + 0 + 26 -0.2353596 diff --git a/html-flask/flask-main.py b/html-flask/flask-main.py index e05d219..1cedf77 100644 --- a/html-flask/flask-main.py +++ b/html-flask/flask-main.py @@ -36,14 +36,14 @@ # Unterstützungsfunktionen def get_i2cdetect_output(): - try: - # Führen Sie den Befehl aus und erfassen Sie die Ausgabe - result = subprocess.run(['/usr/sbin/i2cdetect', '-y', '1'], capture_output=True, text=True, check=True) - output = result.stdout - except subprocess.CalledProcessError as e: - # Falls ein Fehler auftritt, geben Sie eine entsprechende Nachricht zurück - output = f"Ein Fehler ist aufgetreten: {e}" - return output + try: + # Führen Sie den Befehl aus und erfassen Sie die Ausgabe + result = subprocess.run(['/usr/sbin/i2cdetect', '-y', '1'], capture_output=True, text=True, check=True) + output = result.stdout + except subprocess.CalledProcessError as e: + # Falls ein Fehler auftritt, geben Sie eine entsprechende Nachricht zurück + output = f"Ein Fehler ist aufgetreten: {e}" + return output # definieren der zentralen Routen @@ -75,20 +75,24 @@ def list_logs(): size = os.path.getsize(file) # Letzte Änderung als Datum mtime = datetime.fromtimestamp(os.path.getmtime(file)).strftime('%Y-%m-%d %H:%M:%S') + # Letzten 15 Zeilen der Datei + with open(file, 'r', encoding='utf-8', errors='ignore') as f: + lines = f.readlines()[-30:] files_info.append({ 'name': os.path.basename(file), 'size': size, - 'mtime': mtime + 'mtime': mtime, + 'last_lines': lines }) files_info.sort(key=lambda x: x['name'].lower()) return render_template('list_logs.html', files_info=files_info) @app.route('/i2cdetect') def i2cdetect(): - # Rufen Sie die Funktion auf, um die i2cdetect-Ausgabe zu erhalten - i2cdetect_output = get_i2cdetect_output() - # Senden Sie die Ausgabe als Response zurück, hier als einfacher Text - return Response(i2cdetect_output, mimetype='text/plain') + # Rufen Sie die Funktion auf, um die i2cdetect-Ausgabe zu erhalten + i2cdetect_output = get_i2cdetect_output() + # Senden Sie die Ausgabe als Response zurück, hier als einfacher Text + return Response(i2cdetect_output, mimetype='text/plain') @app.route('/reboot') def reboot_system(): diff --git a/html-flask/static/js/build_menus.js b/html-flask/static/js/build_menus.js index 361db67..662578e 100644 --- a/html-flask/static/js/build_menus.js +++ b/html-flask/static/js/build_menus.js @@ -208,8 +208,6 @@ window.onload = function() { populateTestLinks(testsMenu); // Hauptmenü der Tests } - console.log("Aktoren Menü suchen ..."); - var aktorMenu = document.getElementById("aktorMenu"); console.log("Aktoren gefunden?", aktorMenu); diff --git a/html-flask/templates/config_caravanpi.html b/html-flask/templates/config_caravanpi.html index 84b11c6..641335d 100644 --- a/html-flask/templates/config_caravanpi.html +++ b/html-flask/templates/config_caravanpi.html @@ -59,6 +59,9 @@

CaravanPi Grundeinstellungen

+

+


+

@@ -194,7 +197,7 @@

CaravanPi Grundeinstellungen

Einblenden
- + @@ -203,30 +206,32 @@

CaravanPi Grundeinstellungen

Anzahl von Sensoren

-
-
- -
-
- +
+
+
+ +
+
+ +
-
-
-
- -
-
- +
+
+ +
+
+ +
-
-
-
- -
-
- +
+
+ +
+
+ +
@@ -235,58 +240,59 @@

CaravanPi Grundeinstellungen

Einstellungen für die Abfrageintervalle der Sensoren

- -
-
- -
-
- +
+
+
+ +
+
+ +
-
-
-
- -
-
- +
+
+ +
+
+ +
-
-
-
- -
-
- +
+
+ +
+
+ +
-
-
-
- -
-
- +
+
+ +
+
+ +
-
-
-
- -
-
- +
+
+ +
+
+ +
-
-
-
- -
-
- +
+
+ +
+
+ +
@@ -295,6 +301,7 @@

CaravanPi Grundeinstellungen


Liontron Battery Management

+
@@ -311,203 +318,205 @@

Sensoren, die einen aktustischen Alarm auslösen

Dies empfiehlt sich insbesondere beim Gassensor.

-

-
-

Gassensor

+
+

+
+

Gassensor

-
-
- -
-
- +
+
+ +
+
+ +
-
-
-
- -
-
- +
+
+ +
+
+ +
-
-
-
- -
-
- -
-
-
-
- -
-
- +
+
+ +
+
+ +
-
-
-
- +
+
+ +
+
+ +
-
- +
+
+ +
+
+ +
-
-

-
-

230V Überwachung

+

+
+

230V Überwachung

-
-
- -
-
- +
+
+ +
+
+ +
-
-
-
- -
-
- -
-
-
-
- -
-
- +
+
+ +
+
+ +
-
-
-
- +
+
+ +
+
+ +
-
- +
+
+ +
+
+ +
-
-

-
-

12V Bordbatterie Überwachung

+

+
+

12V Bordbatterie Überwachung

-
-
- -
-
- +
+
+ +
+
+ +
-
-
-
- -
-
- -
-
-
-
- -
-
- -
-
-
-
- -
-
- +
+
+ +
+
+ +
-
-
-
- +
+
+ +
+
+ +
-
- +
+
+ +
+
+ +
-
-
-
- +
+
+ +
+
+ +
-
- +
+
+ +
+
+ +
-
-

-
-

12V Auto Überwachung

+

+
+

12V Auto Überwachung

-
-
- -
-
- +
+
+ +
+
+ +
-
-
-
- -
-
- -
-
-
-
- -
-
- -
-
-
-
- -
-
- +
+
+ +
+
+ +
-
-
-
- +
+
+ +
+
+ +
-
- +
+
+ +
+
+ +
-
-
-
- +
+
+ +
+
+ +
-
- +
+
+ +
+
+ +
@@ -519,26 +528,27 @@

Sensoren, die einen aktustischen Alarm auslösen

-
-
- -
-
- +
+
+
+ +
+
+ +
-
-
-
- -
-
- +
+
+ +
+
+ +
-
@@ -586,16 +596,16 @@

Sensoren, die einen aktustischen Alarm auslösen

var send2MQTTCheckbox = document.querySelector('input[name="send2MQTT"]'); // Initialer Aufruf für den Fall, dass die Checkboxen bereits markiert sind - toggleSettings(write2DBCheckbox, '.db-settings', true); - toggleSettings(send2MQTTCheckbox, '.mqtt-settings', true); + toggleSettings(write2DBCheckbox, '.db-settings', false); + toggleSettings(send2MQTTCheckbox, '.mqtt-settings', false); // Event Listener für Änderungen write2DBCheckbox.addEventListener('change', function() { - toggleSettings(this, '.db-settings', true); + toggleSettings(this, '.db-settings', false); }); send2MQTTCheckbox.addEventListener('change', function() { - toggleSettings(this, '.mqtt-settings', true); + toggleSettings(this, '.mqtt-settings', false); }); }); diff --git a/html-flask/templates/list_logs.html b/html-flask/templates/list_logs.html index 20eea29..f1b2435 100644 --- a/html-flask/templates/list_logs.html +++ b/html-flask/templates/list_logs.html @@ -25,7 +25,7 @@

 

-

CaravanPi - LOG Dateien

+

CaravanPi - LOG Dateien


@@ -43,6 +43,17 @@ {% endfor %}
+

LOGs - jeweils letzte 30 Zeilen

+ + {% for file in files_info %} +
  • + {{ file.name }}
    +
    +
    {{ file.last_lines|join('\n') }}
    +


    +
  • + {% endfor %} +
    {% include 'footer.html' %} diff --git a/install_CaravanPi.sh b/install_CaravanPi.sh index 0b30977..94d86b3 100755 --- a/install_CaravanPi.sh +++ b/install_CaravanPi.sh @@ -377,7 +377,7 @@ config_protocolls() { # Überprüfen, ob die Zeile vorhanden ist if grep -q "$CHECK_STRING" "$CONFIG_FILE"; then echo "Die Änderung wurde bereits vorgenommen. Keine weiteren Aktionen erforderlich." - elifif grep -q "$SEARCH_STRING" "$BOOT_CONFIG_FILE"; then + elif grep -q "$SEARCH_STRING" "$BOOT_CONFIG_FILE"; then # Ersetze die Zeile durch den gewünschten Text # Benutze sed, um eine Sicherungskopie vor dem Ersetzen zu erstellen (.bak) sed -i.bak "/$SEARCH_STRING/c\\$REPLACE_STRING" "$BOOT_CONFIG_FILE" @@ -569,6 +569,14 @@ install_mariadb() { echo echo "Die Datenbank enthält nun folgende Tabellen:" run_cmd "sudo mysql -u'caravanpi' -p'$caravanpi_password' -e \"SHOW TABLES in CaravanPiValues\"" + + echo + echo "Speichere Passwort in CaravanPi Config xml" + rum_cmd "python3 $CARAVANPI_DIR/installation/caravanPiConfigItemWrite.py --element_path 'caravanpiDefaults/write2MariaDB' --value '1'" + rum_cmd "python3 $CARAVANPI_DIR/installation/caravanPiConfigItemWrite.py --element_path 'caravanpiDefaults/MariaDBhost' --value 'localhost'" + rum_cmd "python3 $CARAVANPI_DIR/installation/caravanPiConfigItemWrite.py --element_path 'caravanpiDefaults/MariaDBuser' --value 'caravanpi'" + rum_cmd "python3 $CARAVANPI_DIR/installation/caravanPiConfigItemWrite.py --element_path 'caravanpiDefaults/MariaDBpasswd' --value '$caravanpi_password'" + rum_cmd "python3 $CARAVANPI_DIR/installation/caravanPiConfigItemWrite.py --element_path 'caravanpiDefaults/MariaDBdatabase' --value 'CaravanPiValues'" } @@ -840,7 +848,8 @@ install_backup() { } -# Installation Python Module +# Installation StromPi3 + install_stromPi3() { echo "Python Modul für StromPi3 installieren ...." run_cmd "sudo apt-get install python3-serial" @@ -872,11 +881,37 @@ install_stromPi3() { sudo bash -c "echo 'enable_uart=1' >> /boot/config.txt" sudo bash -c "echo 'dtoverlay=miniuart-bt' >> /boot/config.txt" sudo apt-get install minicom - sudo minicom -D /dev/serial0 -b 38400 + # sudo minicom -D /dev/serial0 -b 38400 fi } +# Setzen Splash Screen + +set_splash_screen() { + echo "Willkommensbildschirm setzen ...." + + # Zielverzeichnis für den Splash Screen + local target_dir="/usr/share/plymouth/themes/CaravanPi" + + # Überprüfe, ob das Verzeichnis existiert, und lege es an, falls nicht + if [ ! -d "$target_dir" ]; then + echo "Erstelle Verzeichnis $target_dir ..." + sudo mkdir -p "$target_dir" + fi + + # Kopiere alle Dateien von CARAVANPI_DIR/.splashScreen in das Zielverzeichnis + echo "Kopiere Dateien von $CARAVANPI_DIR/.splashScreen nach $target_dir ..." + sudo cp -a "$CARAVANPI_DIR/.splashScreen/"* "$target_dir/" + + # Setze den neuen Splash Screen + echo "Setze CaravanPi als den neuen Splash Screen ..." + sudo plymouth-set-default-theme -R CaravanPi + + echo "Der Splash Screen wurde erfolgreich aktualisiert." +} + + next_steps() { @@ -907,11 +942,21 @@ next_steps() { echo " Ändern Sie die Crontab nach Ihren Bedürfnissen. Nehmen Sie z.B. Programme außer Betrieb, falls noch" echo " entsprechenden Sensoren verbaut wurden." echo - echo echo "- Sensoren in den Caravan einbauen und mit der CaravanPi Platine verbinden" echo " Der letzte Schritt ist dann natürlich die Hardware Sensoren in den Caravan einzubauen" echo " Auf dem CaravanPi Wiki finden Sie hierzu ausführliche Erläuterungen, wie ich das erledigt habe" echo + echo "- grafana Login durchführen, Passwort vergeben, Dashboards anlegen" + echo " Grafana wurde mit dem Standarduser 'admin' und dem Standardpasswort 'admin' installiert." + echo " Starten Sie die Grafana Website unter http://$ip_address:3000 und klicken Sie auf Login." + echo " Verwenden Sie 'admin'/'admin' zum einloggen und vergeben Sie nach Aufforderung ein neues Passwort für den User 'admin'." + echo " Legen Sie die Dashboards an, die Sie am MagicMirror anzeigen wollen. Anleitung finden Sie im CaravanPi Wiki." + echo + echo "- MagicMirror Module einfügen" + echo " Der MagicMirror zeigt aktuell noch keine Werte an. Nutzen Sie die Datei-basierten Module MMM-CaravanPi-xxx, die " + echo " durch dieses Skript bereits angelegt wurden. Eine Anleitung hier finden Sie im Wiki https://github.com/spitzlbergerj/CaravanPi/wiki " + echo " Oder binden Sie die Grafana Desktops mit den Werteverläufen ein. Anleitung ebenfalls im Wiki. " + echo echo } @@ -1306,6 +1351,15 @@ python3 $CARAVANPI_DIR/installation/caravanPiLibInit.py cd "$HOME" +# -------------------------------------------------------------------------- +# Splash Screen setzen +# -------------------------------------------------------------------------- +note "Willkommensbildschirm setzen" "cyan" + +set_splash_screen + +cd "$HOME" + # -------------------------------------------------------------------------- # StromPi3 installieren # -------------------------------------------------------------------------- diff --git a/installation/caravanPiConfigItemWrite.py b/installation/caravanPiConfigItemWrite.py new file mode 100644 index 0000000..99a5ad7 --- /dev/null +++ b/installation/caravanPiConfigItemWrite.py @@ -0,0 +1,44 @@ +#!/usr/bin/python3 +# coding=utf-8 +# +# CaravanPiConfigItemWrite +# +# ./CaravanPiConfigItemWrite.py 'caravanpiDefaults/MariaDBpasswd' 'neuesPasswort' +# +#------------------------------------------------------------------------------- + +import sys +import os +from datetime import datetime +import xml.etree.ElementTree as ET +import argparse + +# ----------------------------------------------- +# CaravanPi File/MARIADB/MQTT library einbinden +# ----------------------------------------------- +sys.path.append('/home/pi/CaravanPi/.lib') +from CaravanPiFilesClass import CaravanPiFiles + + +def parse_arguments(): + parser = argparse.ArgumentParser(description="Schreibe Konfigurationsitems in die CaravanPi-Konfigurationsdatei.") + parser.add_argument('--element_path', type=str, help="Der XML-Pfad des Elements, das aktualisiert oder hinzugefügt werden soll.") + parser.add_argument('--value', type=str, help="Der Wert, der für das Element gesetzt werden soll.") + return parser.parse_args() + +def main(): + args = parse_arguments() + + cplib = CaravanPiFiles() + + # Schreibe die übergebenen Werte in die XML-Datei + result = cplib.writeCaravanPiConfigItem(args.element_path, args.value) + if result != 0: + print(f"Fehler beim Schreiben der Konfiguration für {args.element_path}") + return -1 + + return 0 + +if __name__=="__main__": + result = main() + sys.exit(result) \ No newline at end of file diff --git a/levels/freshLevels2file.py b/levels/freshLevels2file.py index 2c28ea9..f91d095 100644 --- a/levels/freshLevels2file.py +++ b/levels/freshLevels2file.py @@ -30,9 +30,10 @@ import sys import os import getopt +from gpiozero import Button # import for GPIO Input tactile switches -import RPi.GPIO as GPIO +# import RPi.GPIO as GPIO # ----------------------------------------------- # libraries from CaravanPi @@ -87,7 +88,7 @@ def usage(): print (" -t welcher Tank soll abgefragt werden\n") -def interruptPumpOn(pin): +def interruptPumpOn(): # high = Pumpe laeuft nicht, low = Pumpe laeuft global pumpOnTime global waitAfterPumpSeconds @@ -116,7 +117,7 @@ def main(): # ----------------------------------------------- # Initialize the GPIO ports # ----------------------------------------------- - GPIO.setmode(GPIO.BCM) + # GPIO.setmode(GPIO.BCM) # ------------------------- # process call parameters @@ -189,9 +190,14 @@ def main(): # ------------------------- # Interrupt for switching on the pump # ------------------------- - GPIO.setup(pinPumpeAn, GPIO.IN) + # GPIO.setup(pinPumpeAn, GPIO.IN) # Wenn Pumpe wieder ausschaltet, dann Interruptbehandlung - GPIO.add_event_detect(pinPumpeAn, GPIO.RISING, callback = interruptPumpOn, bouncetime = 400) + # GPIO.add_event_detect(pinPumpeAn, GPIO.RISING, callback = interruptPumpOn, bouncetime = 400) + + Pump = Button(pinPumpeAn, pull_up=True, bounce_time=0.4) + Pump.when_pressed = interruptPumpOn + + # ------------------------- # set things for meassuring at startup @@ -258,15 +264,18 @@ def main(): time.sleep(waitAfterPumpSeconds) except KeyboardInterrupt: - GPIO.cleanup() + #GPIO.cleanup() + Pump.close() except: print("unprocessed Error:", sys.exc_info()[0]) - GPIO.cleanup() + #GPIO.cleanup() + Pump.close() # ------------------------- # Cleaning at the end # ------------------------- - GPIO.cleanup() + #GPIO.cleanup() + Pump.close() if __name__ == "__main__": main() diff --git a/levels/wasteLevels2file.py b/levels/wasteLevels2file.py index 4082c1e..6c9f935 100644 --- a/levels/wasteLevels2file.py +++ b/levels/wasteLevels2file.py @@ -32,7 +32,9 @@ import getopt # import for GPIO Input tactile switches -import RPi.GPIO as GPIO +# import RPi.GPIO as GPIO +from gpiozero import Button + # ----------------------------------------------- # libraries from CaravanPi @@ -100,7 +102,7 @@ def main(): # ----------------------------------------------- # Initialize the GPIO ports # ----------------------------------------------- - GPIO.setmode(GPIO.BCM) + # GPIO.setmode(GPIO.BCM) # ------------------------- # process call parameters @@ -215,15 +217,16 @@ def main(): time.sleep(waitAfterReadingSeconds) except KeyboardInterrupt: - GPIO.cleanup() + print("Keyboard Interrupt") + # GPIO.cleanup() except: print("unprocessed Error:", sys.exc_info()[0]) - GPIO.cleanup() + # GPIO.cleanup() # ------------------------- # Cleaning at the end # ------------------------- - GPIO.cleanup() + # GPIO.cleanup() if __name__ == "__main__": main() diff --git a/position/position2file.py b/position/position2file.py index 10a1834..08899b5 100644 --- a/position/position2file.py +++ b/position/position2file.py @@ -585,14 +585,18 @@ def main(): # beide Buttons liegen zwischen 3V3 und GPIO Pin # daher pull_up=False - buttonNowHorizontal = Button(pinSwitchNowHorizontal, pull_up=False, bounce_time=0.1) - buttonNowHorizontal.when_pressed = switchInterruptNowHorizontal - buttonLive = Button(pinSwitchLive, pull_up=False, bounce_time=0.1) - buttonLive.when_pressed = switchInterruptLive + try: + buttonNowHorizontal = Button(pinSwitchNowHorizontal, pull_up=False, bounce_time=0.1) + buttonNowHorizontal.when_pressed = switchInterruptNowHorizontal + + buttonLive = Button(pinSwitchLive, pull_up=False, bounce_time=0.1) + buttonLive.when_pressed = switchInterruptLive - LEDlive = LED(pinLEDLive) - LEDlive.off() + LEDlive = LED(pinLEDLive) + LEDlive.off() + except Exception as e: + print(f"gpiozero Fehler: {e}") # ------------------------- @@ -832,26 +836,39 @@ def main(): lastZ = z sleep(.5) + else: # Warten über Schleife, damit Tasten, Signale, etc. während des Schlafens nicht verloren gehen j=0 while j< 600 and liveMode == 0: # 600/.5 = 300 Sekunden = 5 Minuten j=j+1 sleep (.5) + # falls inzwsichen LEDtest gestartet wurde, alle LEDs aus ledOff() except KeyboardInterrupt: ledOff() # GPIO.cleanup() + + sleep(1) break except: print("unprocessed Error:", sys.exc_info()[0]) ledOff() # GPIO.cleanup() + + sleep(1) raise # GPIO.cleanup() + + try: + buttonNowHorizontal.close() + buttonLive.close() + LEDlive.close() + except Exception as e: + print(f"gpiozero Fehler: {e}") if __name__ == "__main__": main()