UPS and Safety Monitor

Dear Forum-members,

recently a friend and I added a UPS to our observatories. It shuts down the pc and, while doing so, the pc runs a batch file to park and turn off the mount. This all works fine, but I would prefer to have SGP taking over control prior to the shutdown to run an end-of-sequence routine so that the camera can be warmed up and disconnected, the dome parked, and of course the mount being parked and turned off. Finally SGP would have to run the shutdown command for the pc (or make the pc wait for it to finish).

Is there a way to do this using, for instance, the Safety Monitor?

NicolĂ s

I think the Safety Monitor is the way to do this.

You need an ASCOM SafetyMonitor driver for your UPS. It takes the signal that the UPS sends to say the power has failed and sets IsSafe to False when it fails.

Then SGP can select the UPS safety monitor in the Safety setup and use this to close the observatory.

Hi Nicolas

I have posted this on the 10 micron forum as a simple solution and it may suit what you want to achieve:-

In my home observatory I have the power for the AAG CW/Lunatico Solo connected to the UPS but in the non-protected power side. Thus in a power cut, the CW/Solo will power down immediately on the power loss thus the safety file that SGP monitors will return unsafe. As all other equipment is protected by the UPS, the unsafe call will trigger the End of Sequence Events terminating the sequence, parking the scope, closing the obs roof, warming ccd, disconnecting equipment etc.

This works well as a simple solution. I use the Lunatico DragonFly and I also have the phyiscal relay output from my AAG CW wired into one of the sensors and this is a back up to SGP’s safety monitor. I have a script that is triggered on the change of state of the sensor, it commences with a 180s countdown to allow SGP to run its End of Sequence Events and after that then runs a script to park and power down the mount and equipment in the event that something fails in SGP (of course if SGP has indeed shutdown the obs, the back-up script has no effect).

Barry

Hi Chris and Barry,

@Chris: I agree that the SafetyMonitor is the way to go, but where to get an ASCOM driver for a (my specific?) UPS?
@BarryWilson: I have seen your solution and although it is nice, I think this should be possible using software only as all the necessary triggers are already present, but simply not used.

NicolĂ s

It needs someone to write one, in an ideal world the UPS manufacturer but in reality someone with some interest in this.

What sort of message does the UPS send to the PC? That could be used to update the Safety Monitor (SM) safety state. A SM driver should be pretty simple, one property to implement, almost everything else provided by the ASCOM development help.

What’s the make and model of the UPS?

Hi Chris,

thanks. The UPS is a APC Back-UPS XS 1400U.

The ASCOM driver should be configurable in the sense that it should allow to warm up the camera, depending on the state of the UPS and that this action is started after a configurable number of minutes power outage.

Sadly enough I have not yet found any documentation on how exactly the UPS communicates its status to the PC. Another APC UPS I have can be read using WinNUT, which does so via a port number on the connected PC (or NAS in my case), but so far I have been unable to do so with this new UPS.

NicolĂ s

Found some information, there’s an application provided by APC and I’m trying to install it but it doesn’t seem to want to. Ah, it’s busy disabling Windows power management, hope I don’t regret this…

No, it won’t install unless there is an APC UPS connected. Nothing I can do.
I don’t understand why they are so precious about their software, or the communication details, they are selling hardware. Isn’t the UPS a big enough dongle?

1 Like

Hi Chris,

thank your very much for your effort in this, hope it did not ruin your power management…

I guess you found APC’s PowerChute. I have that running and it takes care of the shutdown. As it normally hibernates the pc I tweaked Windows (10 professional, that is) so that it does not hibernate, but actually shutdown. Then I have a batch file running upon logoff which parks the mount and switches it off. Once that is accomplished the batch file stops executing and shutdown continues. So far all goes perfect.

This means a command could also be sent to SGP, perhaps that provides a solution? As long as the batch file runs Windows will wait with the final shutdown.

Regarding the communication details: I will try to contact APC to see if they can shed some light on this.

NicolĂ s

Hi Chris,

in addition to my previous mail I found on the APC forum that their UPS that accept USB communication use standard HID Power Device protocol. . There seems to be some visual basic code samples in it (to me it looks like that, but then I am only used to Java and PHP).

APC also refers to the third party daemon apcupsd especially developed for APC.

NicolĂ s

That’s interesting Nicolas, by batch file I guess you mean something like a VBS file.

Perhaps a command sequence like this could be used:

set safety = CreateObject(“ASCOM.Script.SafetyMonitor”)
safety.IsSafe = false

That needs a safetymonitor which has multiple connections and the IsSafe property can be set.
Or perhaps your batch file could write to a file, rather like the Boltwood does, then a generic SafetyMonitor could read that file:

Dim fso, safetyFile
Set fso = CreateObject(“Scripting.FileSystemObject”)
Set safetyFile = fso.CreateTextFile(“c:\safety.txt”, True)
safetyFile.WriteLine(“Unsafe.”)
safetyFile.Close

I’ll think about this, there could be a way through without a lot of effort.

Hi Chris,

sorry, but no, by batch file I mean the old fashion DOS batch (.bat) batch file. I am past Abraham, started programming some 35 years ago, but got stuck in 3rd generation languages like Pascal. I manage a bit in Java, but nothing serious…

My batch file looks like this (MountCMD is a java command-line application I wrote and sends commands over ethernet to the mount):

@echo off

rem #### The path to the location of MountCMD directory ######
cd C:\Users\InFINNity\Desktop\MountCMD

rem #### Introducing a short delay that allows us to stop this script by closing the CMD window #####
echo Going to stop the mount in 10 seconds
timeout /T 10

rem #### set the park position of the mount and slew the scopes to it ########
echo Setting the park position in altitude
java MountCMD 10.0.1.151 3492 :Sa+0000:00# >> MountCMD-log.txt
echo Setting the park position in azimuth
java MountCMD 10.0.1.151 3492 :Sz+90
00:00# >> MountCMD-log.txt
echo Trying to slew the mount to the above defined position
java MountCMD 10.0.1.151 3492 :MA# >> MountCMD-log.txt

rem #### Introducing a short delay that allows the mount to finish its slew before >shutdown is requested #####
echo Waiting 30 seconds for mount to park
timeout /T 30

rem #### this performs a shutdown on the mount ######
echo Trying to shutdown the mount
java MountCMD 10.0.1.151 3492 :shutdown# >> MountCMD-log.txt

It is this code that is run on logoff.

NicolĂ s

A newcomer, I started in 1966 on Algol 60, a precursor to Pascal. :slight_smile:

Nice to see that your coding style has ignored current trends such as comments being unnecessary.

It looks as if hooking some code to write an appropriate message to a fle is the way to go.

This is going to take a bit of time, if there isn’t progress in a month wake me up.

Hi Chris,

Algol, interesting, I recently did some tests with an old script I found it in a modern interpreter of it. Good fun!

I am in no hurry at all, so will be patient and wake you up somewhere next month.

Appreciate your effort in this, I think more people will!

best wishes,
NicolĂ s

I couldn’t leave it half done and didn’t have much else on today so here it is:
Generic Safety Setup.zip (593.9 KB)

That will install a Generic Safety monitor which will monitor a file and check the first line for some text indicating the two states and use them to update the IsSafe property of the safety monitor

writing to the file can easily be done in a batch file with a line such as:
echo safe > safety.txt
or
echo unsafe > safety.txt

This writes the text to the file safety.txt, on my system that’s in the C:\Users,username>\ folder but could be elsewhere.

I can use it to change the colour of the safety light in SGP, I guess it should do what you want.

Have fun!

Hi Chris,

you’re amazing, thanks!
So, if I understand well, the Safety Monitor will only check the file by reading its content, which needs to be provided by the UPS or a script that monitors the UPS.

Currently I do so on logoff, but as soon as my batch file finishes, the computer goes down, which I can only delay by adding a long enough wait for the safety monitor to do its job. I can however only give a guestimate for the remaining battery lifespan, while the UPS has a good idea of it.

So, instead of the setting the unsafe mode I would like to monitor the UPS status as soon as it indicates that power is down, without setting the safety status to Unsafe as that will immediately cause End-of-Sequence options to be activated.

In an ideal world, the Generic Safety module would monitor the status of the UPS and only take appropriate action when battery lifespan is becoming too short. For this of course there are a few considerations:

  • a power failure should not cause immediate shutdown;
  • depending on the expected battery life the Safety Monitor should be allowed to overcome the power failure (I think my UPS has a 20 minutes lifetime, but need to test that).
  • My camera is set to warm up in 10 minutes, so the Unsafe status should be set 10 minutes (plus perhaps 2 minutes margin) before the UPS will fail (would be great if that is directly read from the camera settings in SGP).
  • In the meanwhile the sequence could continue, unless the remaining integration time of the current frame extends beyond the UPS’s remaining battery time.
  • What to do when power is restored, while End-of-Sequence options have been started?

Shutdown of the pc will be done by the UPS, depending on the UPS or Windows settings.

Now I do realise that this is a lot more than I initially asked for, but hope you want to consider it and I do appreciate your comments on my thoughts! For now I will start to use your Generic Safety Setup with this additional wait at the end of my batch file (as mentioned above) and see how that works.

Thanks a bunch!
best wishes,
NicolĂ s

PS: just realised that when I use my .bat file to set the Unsafe status SGP is already killed… Will need WinNUT to do so… so more to think about…

Yes, that’s it.

Yes, in an ideal world. If the UPS were to write data to a file, the first line of which changed when the power failed then the Generic Safety Monitor (GSM) could monitor this file.

I implemented this solution because we didn’t have any information on how the UPS provides information about the power status. All I had was your information about what you were doing.

The problem I have is that I’ve strayed too close to a slippery slope, at the bottom of which is the swamp of unending support. I’m not going to risk falling down there. I’m not going to get sucked into a never ending cycle of speculating about how to detect a power failure, trying something, finding it doesn’t work and so on, indefinitely.

This leaves much of this to you. If you can detect the power failure and change a file then the GSM can pass this to SGP. That should be able to do all the close down that’s required.

Ideally SGP would signal that it had finished and that would trigger the rest of the close down process.

10 minutes warm up with a 20 minutes battery life seems a bit tight, can you reduce this? 5 minutes would be better than the power going off.

Hi Chris,

I appreciate your fear of the slippery slope, can’t blame you. :slight_smile:
I guess the 10 minute warm-up time is a default SGP setting, no idea where I otherwise got it from, will reduce it to 5 minutes. Thanks for this useful comment!

Maybe it is time to dive in the world of VB… :frowning:

cheers and thanks for your support so far,
NicolĂ s

I’ve had a Good Idea, possibly verging on brilliant :slight_smile:

if you (or anyone else) are running on a laptop then the PowerStatus information available in the laptop can be used to set the safety state.

So I’ve added a checkbox to the GSM setup - “Unsafe if mains power is off”
With this checked SGP will get an unsafe notification within a few seconds of the power to the laptop failing. SGP can then can do all the shutdown while the UPS desperately provides power to everything else.

The laptop is not powered by the UPS while everything else is, maybe everything else is powered by a battery that’s got a float charger to keep it topped up. Lots of possibilities.

This is what the setup looks like, having an empty file name means that this is not checked.
image

I think this could a lot of applicability. It avoids the issue of needing to have multiple safety monitors for all the different UPSs and in many cases could avoid needing a UPS entirely.

Here’s the new installer
Generic Safety Setup.zip (594.5 KB)

Have fun.

Chris

Hi Chris,

thanks for this addition, especially for people in the field this will be quite useful. Coming weekend I will test to see if Windows-behind-a -UPS acts like a laptop-Windows, so perhaps the trigger works on my NUC as well.

NicolĂ s

It looks as if a UPS should use the PowerStatus class to allow the system to manage everything so it will be well worth trying.

And of course everybody else. Once I get some feedback I’ll probably try to publish it on the ASCOM downloads site.

I tried it with SGP 2.6.1.114 (don’t have 3.x) and found that it would shut down a sequence, parking the mount, parking the dome and closing the shutter. The Camera cooler was set to warm up on sequence end but didn’t.

When the power failed I got a messaqe box giving me the option to cancel the shutdown and a 30 second countdown. I tried restoring the power, simulating a short power failure, but the shut down continued. It WBN if SGP could have seen the power restore and resumed.

This is with version 2 and I expect this has been updated for later versions.

Chris

www.mainsequencesoftware.com