UPS with Codesys

arj3090
2019-10-28
2019-11-08
  • arj3090 - 2019-10-28

    I have a Pi based device with a UPS. The relay output from the UPS is wired to GPIO0. I created a Python script to save persistent data when the UPS loses power and the GPIO0 signal changes. This is the code I am using:

    Β  Β  Β  if GPIO.input(0):
    Β  Β  Β  Β  subprocess.run("sudo bash /etc/init.d/codesyscontrol stop", shell=True, check=True)
    Β  Β  Β  else:
    Β  Β  Β  Β  subprocess.run("sudo bash /etc/init.d/codesyscontrol start", shell=True, check=True)
    

    It does not seem very graceful to fully stop the Codesys service and restart when power is restored. Is there a better method to tell Codesys to save the persistent values?

     
  • eschwellinger

    eschwellinger - 2019-10-29

    Hi,
    if you do this manually do you agree that this works?
    I think if you trigger this by a GPIO and your UPS triggers a Linux shutdown - and as you told switch off Ethernet nic
    at the same time.. this will not work properly. ( As I remember from an older post)
    Is using a different UPS an option PI for you? For example: l viewtopic.php?f=23&t=5872&p=10867#p13721 l

    BR
    Edwin

     
  • arj3090 - 2019-10-29

    This is a different device with an external UPS. I was never able to get the first device with the built-in UPS to work because of the power being removed from the Ethernet ports

    On the new device I cannot shut down Linux because the power may return before the UPS is completely drained. If Linux were shut down and the input power returned to the UPS, then Linux would not restart. So I need some way to force Codesys to save the data.

     
  • eschwellinger

    eschwellinger - 2019-10-30

    Hi,
    I would try:

    if GPIO.input(0):
    subprocess.run("sudo shutdown -h now", shell=True, check=True)
    .
    .
    This is a graceful shudown of Linux which will lead to a graceful shutdown of the plc runtime -
    I assume this will then lead to a valid retain file too.

    BR
    Edwin

     
  • i-campbell

    i-campbell - 2019-10-30

    Archie, are you going about this the wrong way?
    Have you tried the persistence manager which specifically implements what you are after?
    https://help.codesys.com/webapp/f_appli ... n=3.5.14.0

    Recipes is also an option, but Persistence Manager just has everything you could want. Redundant files.. write on change or write on demand.
    Ian

     
  • arj3090 - 2019-10-31

    Edwin Schwellinger hat geschrieben:
    Hi,
    I would try:
    if GPIO.input(0):
    subprocess.run("sudo shutdown -h now", shell=True, check=True)
    .
    .
    This is a graceful shudown of Linux which will lead to a graceful shutdown of the plc runtime -
    I assume this will then lead to a valid retain file too.

    The reason I cannot do this is because the power may return before the UPS is fully drained. In this case the Pi would not boot back up. It would require someone to manually disconnect the power from the Pi or remove power into the UPS for about 60 seconds to let it fully drain.

     
  • arj3090 - 2019-11-01

    I-Campbell hat geschrieben:
    Archie, are you going about this the wrong way?
    Have you tried the persistence manager which specifically implements what you are after?
    https://help.codesys.com/webapp/f_appli ... n=3.5.14.0
    Recipes is also an option, but Persistence Manager just has everything you could want. Redundant files.. write on change or write on demand.
    Ian
    I briefly checked the Persistent Manager, but haven't got it to work yet. I am missing a step or two somewhere. I do like the Save On Change feature. It would be really nice if the normal Persistent Variables had the feature.

     
  • i-campbell

    i-campbell - 2019-11-02

    I couldn't find a nice tutorial for Persistence Manager, just the online help which details the components of Persistence Manager. They go through this in the training courses.

    Application Composer for free from the store, showing the Modules View, and pressing the generate button.

    It is kind of designed for exactly what you want.

    I see you have already found the application manager store example which has the functions to store the var persistent retain data to a file and restore it... I haven't needed to try to get these to work though as Persistence Manager does it all for me. (Perhaps turn off the default "OnPowerfail" storage recovery with these two lines in your .cfg)
    [CmpApp]
    RetainType.Applications=None

     
  • hence.persson - 2019-11-08

    There always are a problem using UPS and raspberry as raspberry doesnt have a BIOS with auto start option..
    The Raspberry needs to shutdown and have 0V input a short time before power applied..
    There are UPSes that work this way see attached picture for Andino-UPS different states.. If you had a "real" industrial computer the normal working UPSes would work.

    Pictures taken from here: https://github.com/andino-systems/Andin ... master/src m

    IMG: fsm

    IMG: states1.png

     

Log in to post a comment.