Python or CMD/.bat to control PegasusAstro via Unity API?

Feature requests / 3rd party software development
Post Reply
airscottdenning
Posts: 3
Joined: Sun Jul 02, 2023 2:30 pm

Python or CMD/.bat to control PegasusAstro via Unity API?

Post by airscottdenning »

I am trying to write scripts to perform some basic tasks on my imaging equipment using the PegasusAstro Unity API. I found the API docs but have so far failed to get access to my Pegasus PowerBox Advance through Unity.

In particular, I'd like to be able to:
Check for dew conditions (relative humidity above a threshold)
Power off the PPBA at the end of the night if (and only if) the dew heater is no longer needed
Cycle power on camera or focuser (in case something won't connect)
Cycle USB3 Ports (in case something won't connect)

I see that Hans Kostense has published PyUPB to directly control the Pegasus Universal PowerBox, but I think that's the older (deprecated) API and won't work for PPBA anyway.

Does anybody know how to do this? Or better yet, can anybody provide example python or .bat scripts?

Many thanks!
Scott
airscottdenning
Posts: 3
Joined: Sun Jul 02, 2023 2:30 pm

Re: Python or CMD/.bat to control PegasusAstro via Unity API?

Post by airscottdenning »

Please help if you can.

I am trying to follow the methods in the PegasusAstro ApiDocs to communicate with my Pocket PowerBox Advance through the Unity server.

This is in Windows 11 with Unity Release Version : 1.10.1868.47.

I have no problem controlling the PPBA through the Unity app (or the legacy PPB.exe app). But I want to be able to script the PPBA. The documentation for the REST API seems fine, but I can't get a uniqueKey for my PPBA for some reason.

I can start the server from a CMD window with 'START C:\"Program Files (x86)"\"Pegasus Astro"\"Unity Platform"\server\Peg.Server.exe' and I can see server logs scrolling in a separate CMD window as I call the API using curl.

I'm certainly connecting to the server, and it's responding with JSON. But the data[] field in the JSON response is blank.

Without a uniqueKey I can't do anything to the PPBA.

Here's what I see using /Server/Start and /Reporting/Device:

C:\Users\airsc>curl -v http://localhost:32000/Server/Start
* Trying 127.0.0.1:32000...
* Connected to localhost (127.0.0.1) port 32000 (#0)
> GET /Server/Start HTTP/1.1
> Host: localhost:32000
> User-Agent: curl/8.0.1
> Accept: */*
>
< HTTP/1.1 405 Method Not Allowed
< Date: Sun, 02 Jul 2023 17:23:51 GMT
< Server: Kestrel
< Content-Length: 0
< Allow: PUT
<
* Connection #0 to host localhost left intact

C:\Users\airsc>curl http://localhost:32000/Reporting/Device
{"status":"success","code":200,"message":"Devices with available report.","data":[]}
C:\Users\airsc>curl http://localhost:32000/Server/DeviceManager/Connected
{"status":"success","code":200,"message":"Connected Devices :0","data":[]}
C:\Users\airsc>curl -v http://localhost:32000/Server/DeviceManager/Connected
* Trying 127.0.0.1:32000...
* Connected to localhost (127.0.0.1) port 32000 (#0)
> GET /Server/DeviceManager/Connected HTTP/1.1
> Host: localhost:32000
> User-Agent: curl/8.0.1
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Sun, 02 Jul 2023 17:28:31 GMT
< Content-Type: application/json; charset=utf-8
< Server: Kestrel
< Transfer-Encoding: chunked
<
{"status":"success","code":200,"message":"Connected Devices :0","data":[]}* Connection #0 to host localhost left intact

C:\Users\airsc>

AND HERE'S THE SERVER LOG:
2023-07-02 11:39:44.8176|INFO|Startup|Process.MainModule.Path:C:\Program Files (x86)\Pegasus Astro\Unity Platform\server|
2023-07-02 11:39:44.8561|INFO|Startup|Current.Directory.Path:C:\Users\airsc|
2023-07-02 11:39:44.8561|INFO|Startup|User.Path:C:\Users\airsc\AppData\Roaming\PegasusAstroUnityPlatform\Production\Server|
2023-07-02 11:39:45.1093|INFO|Microsoft.Hosting.Lifetime|Now listening on: http://[::]:32000|
2023-07-02 11:39:45.1161|INFO|Microsoft.Hosting.Lifetime|Application started. Press Ctrl+C to shut down.|
2023-07-02 11:39:45.1161|INFO|Microsoft.Hosting.Lifetime|Hosting environment: Production|
2023-07-02 11:39:45.1161|INFO|Microsoft.Hosting.Lifetime|Content root path: C:\Users\airsc|
2023-07-02 11:40:15.3867|WARN|SqliteConnectionFactory|Looking for schema transformation.|
2023-07-02 11:40:15.4879|WARN|SqliteConnectionFactory|Schema transformation not required.|
vland
Posts: 4
Joined: Thu May 04, 2023 5:58 pm

Re: Python or CMD/.bat to control PegasusAstro via Unity API?

Post by vland »

try with PUT /Server/Start
Post Reply