Helpdesk

Guten Tag,


ich habe einen Strompi3 auf einem Raspi4B, Wide Eingang auf 24V, keine Batterie, Kondensatoren aktiviert.


Ich habe das shutdown.py Skript dahingehend erweitert, dass es die Konfiguration des Strompis überprüft und gegebenenfalls korrigiert,[nbsp] bevor es den normalen Betrieb beginnt.
Leider ist es so, dass das dirty Bit nach jedem Stromausfall gesetzt ist, der Shutdown also nicht korrekt ausgeführt wird. Im syslog sehe ich, dass mein Skript ausgeführt wird, sehe aber nie die Meldung eines Stromausfalles.


Ist in meinem Skript ein Fehler, oder reicht die Reserve der Kondensatoren nicht für ein sauberes Shutdown?[nbsp]
Am Schluss bleibt die rote LED des Raspis lange Zeit an, also wäre die nötige Energie noch vorhanden...


Wo liege ich falsch?


Vielen Dank für die Unterstützung und freundliche Grüsse,


Mathias


[nbsp]


import serial
from time import sleep
import datetime
import syslog
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()
syslog.syslog(syslog.LOG_INFO, "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 -[gt] Wide',
2: 'Wide -[gt] mUSB',
3: 'mUSB -[gt] Battery',
4: 'Wide -[gt] Battery',
5: "mUSB -[gt] Wide -[gt] Battery",
6: "Wide -[gt] mUSB -[gt] 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')

def CheckModus(ExpectedValue, ActualValue, MustInitialize, DisplayText):
if int(ExpectedValue) [lt][gt] int(ActualValue):
print (DisplayText + ': ' + str(ExpectedValue).rstrip('\n') + ' [lt][gt] ' + str(ActualValue).rstrip('\n'))
return True
return MustInitialize

def ConfigWrite(Register, Value):
breakS = 0.1
breakL = 0.2
print (str.encode('set-config ' + str(Register).rstrip('\n') + ' ' + str(Value).rstrip('\n')))
serial_port.write(str.encode('set-config ' + str(Register).rstrip('\n') + ' ' + str(Value).rstrip('\n')))
sleep(breakS)
serial_port.write(str.encode('\x0D'))
sleep(breakL)

#######################################################################################################################
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_enable = int(sp3_poweroff_time_enable.decode())
if int(sp3_poweroff_time_enable) == 1:
sp3_alarm_mode = "4"
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).rstrip('\n').zfill(2))
powerofftime_enabletest = (str(sp3_poweroff_time_enable).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

# Target setup:
# - powerpath wide-[gt]battery
# - warning enabled
# - battery shutdown @ 50%
# - shutdown 20"
# - minute wakeup alarm, 2 minutes

modusreset = CheckModus(4, sp3_modus, False, '4 = Wide -[gt] Battery')
#modusreset = CheckModus(2, sp3_modus, False, '2 = Wide -[gt] mUSB')
modusreset = CheckModus(1, sp3_warning_enable, modusreset, '1 = shutdown enable')
modusreset = CheckModus(1, sp3_shutdown_enable, modusreset, '1 = shutdown enable')
modusreset = CheckModus(20, sp3_shutdown_time, modusreset, '20" shutdown time')
modusreset = CheckModus(3, sp3_batLevel_shutdown, modusreset, '50% battery level shutdown')
modusreset = CheckModus(4, sp3_alarm_mode, modusreset, '4 = minute wakeup alarm mode')
modusreset = CheckModus(2, sp3_poweroff_time, modusreset, '2 = wakeup minutes')
modusreset = CheckModus(0, sp3_intervalAlarm, modusreset, '0 = interval alarm disable')

if modusreset:
print('[StromPi-Mode: ' + sp3_modus.decode(encoding='UTF-8', errors='strict').rstrip('\n') + ' (' + strompi_mode_converter((int(sp3_modus))) + ')]')
print('[Raspberry Pi Shutdown: ' + enabled_disabled_converter(int(sp3_shutdown_enable)) + ']')
print('[Shutdown-Timer: ' + str(sp3_shutdown_time).rstrip('\n') + ' seconds' + ']')
print('[Battery-Level Shutdown: ' + batterylevel_shutdown_converter(int(sp3_batLevel_shutdown)) + ']')
print('[Serial-Less Mode: ' + enabled_disabled_converter(int(sp3_serialLessMode)) + ']')
print('[Power Save Mode: ' + enabled_disabled_converter(int(sp3_powersave_enable)) + ']')
print('[Powerfail Warning: ' + enabled_disabled_converter(int(sp3_warning_enable)) + ']')
print('[PowerOn-Button: ' + enabled_disabled_converter(int(sp3_powerOnButton_enable)) + ']')
print('Interval-Alarm: ' + enabled_disabled_converter(int(sp3_intervalAlarm)))
print('[Alarm mode: ' + str(sp3_alarm_mode).rstrip('\n'))
print(' Minute wakeup time: ' + str(sp3_poweroff_time).rstrip('\n') + ' minutes]')
print('must update setup!')
syslog.syslog(syslog.LOG_INFO, "Setup update")
else:
print('setup is OK, run')
syslog.syslog(syslog.LOG_INFO, "setup is OK, run")


if modusreset:
print('\n----------------------------------------------')
print(' Transfer Configuration to the StromPi 3')
print(' \n###Please Wait###')
print('-----------------------------------------------')

breakS = 0.1
breakL = 0.2



ConfigWrite(1, 4) # set mode = 4
# ConfigWrite(1, 2) # set mode = 4
ConfigWrite(0,1) # write the config

# sp3_alarm_mode == "4":
ConfigWrite(2,0)
ConfigWrite(3,0)
ConfigWrite(4,0)
ConfigWrite(26,1)
#print (str.encode('alarm-mode 4'))
##serial_port.write(str.encode('alarm-mode 4'))
#sleep(breakS)
#serial_port.write(str.encode('\x0D'))
#sleep(breakL)

ConfigWrite(27,2) # poweroff time 2'
ConfigWrite(5,0) # alarm power off
ConfigWrite(6,0) # alarm min
ConfigWrite(7,0) # alarm hour
ConfigWrite(8,0) # alarm off min
ConfigWrite(9,0) # alarm off hour
ConfigWrite(10,1) # alarm day
ConfigWrite(11,1) # alarm month
ConfigWrite(12,1) # alarm weekday
ConfigWrite(13,1) # alarm enable
ConfigWrite(14,1) # shutdown enable
ConfigWrite(15,20) # shutdown time
ConfigWrite(16,1) # warning enable
ConfigWrite(17,0) # serialless mode
ConfigWrite(18,3) # battery level shutdown
ConfigWrite(19,0) # interval alarm
ConfigWrite(20,0) # interval alarm on time
ConfigWrite(21,0) # interval alarm off time
ConfigWrite(22,0) # power on button enable
ConfigWrite(23,30) # power on button time
ConfigWrite(24,0) # powersave enable
ConfigWrite(25,0) # poweroff mode
ConfigWrite(28,0) # wakeup weekend enable

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).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 [gt] wide_range_volt_min:
wide_range_volt = str(sp3_ADC_Wide) + 'V'
else:
wide_range_volt = ' not connected'

if sp3_ADC_BAT [gt] 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 [gt] 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).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).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).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).rstrip('\n').zfill(2) + ':' + str(sp3_alarm_min).rstrip('\n').zfill(2))
print(' Alarm-Date: ' + str(sp3_alarm_day).rstrip('\n').zfill(2) + '.' + str(sp3_alarm_month).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).rstrip('\n').zfill(2) + ':' + str(sp3_alarm_min_off).rstrip('\n').zfill(2))
print(' ')
print('Interval-Alarm: ' + enabled_disabled_converter(int(sp3_intervalAlarm)))
print(' Interval-On-Time: ' + str(sp3_intervalAlarmOnTime).rstrip('\n').zfill(2) + ' minutes')
print(' Interval-Off-Time: ' + str(sp3_intervalAlarmOffTime).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(' ')

##############################################################################
wait_for_shutdowntimer = 5;
##############################################################################

t=0 #Temporary time-variable

counter=0
syslog.syslog(syslog.LOG_INFO, "serialShutdown.py has started")
#print ("serialShutdown has started")
while 1:
x=serial_port.readline()
y = x.decode(encoding='UTF-8')
if y==('xxxShutdownRaspberryPixxx\n'):
syslog.syslog(syslog.LOG_INFO | syslog.LOG_NOWAIT, "PowerFail - Raspberry Pi Shutdown")
# print ("PowerFail - Raspberry Pi Shutdown")
t= wait_for_shutdowntimer + 1
elif y==('xxx--StromPiPowerBack--xxx\n'):
syslog.syslog(syslog.LOG_INFO, "PowerBack - Raspberry Pi Shutdown aborted")
#print ("PowerBack - Raspberry Pi Shutdown aborted")
t=0
elif y!=(''):
#print ('sShutdown Rx', y)
syslog.syslog(syslog.LOG_INFO, y)
if t[gt]0:
t-=1
if t == 1:
syslog.syslog(syslog.LOG_INFO | syslog.LOG_NOWAIT, "Issuing sudo shutdown -h now")
os.system("sudo shutdown -h now")

Mathias

05.01.22 18:48

Hallo Mathias,


für einen sauberen Shutdown benötigt der StromPi eine zweite Spannungsquelle.
Die Kondensatoren reichen dafür nicht aus. Sie sind nur dafür da, um den Umschaltmoment zwischen den Spannungsversorgungen zu überbrücken.


Mit freundlichen Grüßen


Tim Joy-IT)

Tim

06.01.22 11:07