Astro HTTP API is a general purpose HTTP API for N.I.N.A designed for use with AstroApp.io
- Install this plugin either directly from N.I.N.A. or by downloading the latest release from the releases page and extracting it into
%localappdata%\NINA\Plugins
- On the plugin page, set
Web Server Enabled
- Find your local IP address by running
ipconfig
in Command Prompt (typically192.168.x.x
or10.x.x.x
) - Open your browser and navigate to
http://<local-ip>:<port>
where<local-ip>
is your local IP address and<port>
is the port you set in the plugin settings (default is8181
). It should prompt for a login and you'll see the user/password in the plugin settings.
By default, you'll only be able to access the API from your local network (e.g. same WiFi network) and will need to setup SSL if you want to use it with astroapp.io.
SSL Setup Instructions (Windows)
To generate a self-signed SSL certificate using PowerShell:
- Open PowerShell as Administrator and run:
$cert = New-SelfSignedCertificate -DnsName "localhost" -CertStoreLocation "cert:\LocalMachine\My" -NotAfter (Get-Date).AddYears(10) -KeySpec KeyExchange
$pwd = ConvertTo-SecureString -String "YourPasswordHere" -Force -AsPlainText # Change this to your desired password
$path = "C:\Users\Shriv\Desktop\certificate.pfx" # Change this to the path you want to save the certificate to
Export-PfxCertificate -Cert $cert -FilePath $path -Password $pwd
-
Update the plugin settings with:
- SSL Certificate Path: Path to the generated .pfx file (e.g.,
C:\Users\Shriv\Desktop\certificate.pfx
) - SSL Certificate Password: The password you used in the PowerShell command (e.g.,
YourPasswordHere
)
- SSL Certificate Path: Path to the generated .pfx file (e.g.,
-
If you want to use this with astroapp.io, in Chrome, enable
chrome://flags/#allow-insecure-localhost
and restart.
Note: Self-signed certificates will show security warnings in browsers.
There are a ton of options for exposing this server to the internet and allowing N.I.N.A. to be controlled from anywhere. See awesome-tunneling for list of options.
The typical best option is cloudflare tunnels. It's free and easy to setup. You can find a guide here.
Keep in mind that exposing your N.I.N.A. server to the internet can be a security risk. It's recommended to not run this server for long periods of time (24/7) if you have sensitive data on the same system that N.I.N.A. is running on.
For full endpoint documentation see the API Documentation.
import requests
status = requests.post(
"http://localhost:8181/api/v1/camera/capture",
auth=("user", "#password#"),
json={"ExposureTime": 1.0}
).json()
print(status)
import websockets
import asyncio
import json
async def connect():
async with websockets.connect("ws://localhost:8181/events/v1") as websocket:
await asyncio.sleep(0.1)
await websocket.send(json.dumps({'ApiKey': '#password#'}))
while True:
try:
event = json.loads(await websocket.recv())
print(event)
except websockets.ConnectionClosed:
break
asyncio.run(connect())
fetch("http://localhost:8181/api/v1/camera/capture", {
method: "POST",
headers: {
"Authorization": "Basic " + btoa("user:#password#"),
"Content-Type": "application/json"
},
body: JSON.stringify({ExposureTime: 1.0})
}).then(res => res.json()).then(console.log)
const ws = new WebSocket("ws://localhost:8181/events/v1")
ws.onopen = () => ws.send(JSON.stringify({ApiKey: "#password#"}))
ws.onmessage = event => console.log(JSON.parse(event.data))
There are plenty of N.I.N.A. features that are not yet implemented in this API just because I wasn't using them. If you need a feature that is not yet implemented, please let me know and I can add it.
Submit an issue on GitHub or this form.
Shout out to https://github.com/christian-photo/ninaAPI which was used as a reference for this project.