The `indihub-agent` is a command line interface tool to connect your astro-photography equipment to [INDIHUB](https://indihub.space) network. The network can be used to share you equipment with others, use others' equipment remotely or just use your equipment without sharing but still contribute your images to INDIHUB-network.
NOTE: all astro-photos taken via INDIHUB-network (with auto-guiding or main imaging cameras) will be processed by INDIHUB cloud pipeline and used for scientific purposes.
## Prerequisites
0. You have a desire to contribute to Space exploration and sustainability projects.
1. You have motorized astro-photography equipment connected to your home network.
2. Your equipment is controlled by [INDI-server](https://github.com/indilib/indi), manuals and docs can be found on [INDI-lib](http://indilib.org) Web-site.
3. INDI-server is controlled by [INDI Web Manager](https://github.com/knro/indiwebmanager).
4. You have ready to use INDI-profile created with INDI Web Manager.
5. Raspberry PI (or computer) where you run `indihub-agent` is connected to Internet so it can register your equipment on INDIHUB-network.
## Registration on INDIHUB-network as a host
Registration is very easy - you don't have to do anything.
The `indihub-agent` doesn't require any signup or token to join INDIHUB.
When you first run `indihub-agent` and it is connected to INDIHUB-network successfully - it receives token from network and saves in the same folder in the file `indihub.json`. Please keep this file there and don't loose it as it identifies you as a host on INDIHUB-network. Also, this file will be read and used automatically for all next runs of `indihub-agent`.
1.`share` - open remote access to your equipment via INDIHUB-network of telescopes, so you can provide remote imaging sessions to your guests.
2.`solo` - use you equipment without opening remote access but equipment is still connected to INDIHUB-network and all images taken are contributed for scientific purposes.
The only mandatory parameter is `-indi-profile` where you specify profile name created with [INDI Web Manager](https://github.com/knro/indiwebmanager). All other parameters have default valyes. I.e. `-mode` default value is `solo`.
The latest `indihub-agent` release can be downloaded from [releases](https://github.com/indihub-space/agent/releases) or [indihub.space](https://indihub.space) Web-site.
There is an API-server running as part of `indihub-agent` and listening on port `:2020` (or on port specified via `-api-port=N` parameter) which provides two different APIs to control or use `indihub-agent`:
- Websocket API to control equipment via websocket-connections
By default API-server works over HTTP-protocol. You can switch it to work over TLS by providing `-api-tls` parameter. This will make `indihub-agent` to generate self-signed CA and certificate.
### RESTful API
You can use this simple RESTful API to control `indihub-agent`.
NOTE: CORS protection can be specified with comma-separated list of allowed origins via agent parameter:
`-api-origins=host1,host2,hostN`.
Also, all examples assume `indihub-agent` is running on host `raspberrypi.local`.
#### 1. Get indihub-agent status (public)
`curl -X GET http://raspberrypi.local:2020/status`
Response example:
```json
{
"indiProfile": "NEO-remote",
"indiServer": "raspberrypi.local:7624",
"mode": "solo",
"phd2Server": "",
"status": "running",
"supportedModes": [
"solo",
"share",
"robotic"
],
"version": "1.0.3"
}
```
#### 2. Restart indihub-agent current mode (public)
#### 3. Switch indihub-agent mode (protected via token)
You need to do HTTP-request `POST "http://indihub-agent-host:2020/mode/{mode}"` specifying required mode in a `mode` URI-parameter and supplying your token in `Authorization` header, i.e.:
NOTE: we connect to `raspberrypi.local:2020` which is `indihub-agent` API-server and we provide token via `token` query string parameter.
This will open WS-connection to you your equipment via `indihub-agent` API-server where all outgoing messages will be INDI-protocol commands and all incoming messages will be INDI-protocol replies from your equipment.
#### 2. Message format for INDI-server Websocket connection
All commands are expected to be in JSON-format where INDI-command XML attributes translate to fields with `attr_`-prefix.
I.e. to send this INDI XML-command over WS-connection:
```xml
<getPropertiesversion="1.7"/>
```
You will need to send message over WS-connection in JSON-format:
```json
{
"getProperties": {
"attr_version":"1.7"
}
}
```
The INDI-protocol responses will be converted from XML to JSON-messages and sent over WS-connection as messages.
I.e. this INDI-response about telescopes installed on the mount in XML-format:
You will need to install [Golang](https://golang.org/dl/).
There are `make` build-commands for different platforms available:
-`make build-macos64` - build for macOS (64 bit)
-`make build-linux64` - build for Linux (64 bit)
-`make build-unix64` - build for Unix (64 bit)
-`make build-win64` - build for Windows (64 bit)
-`make build-win32` - build for Windows (32 bit)
-`make build-raspberrypi` - build for Raspberry Pi (ARM5)
## Contributing
PRs and issues are highly appreciated. TODO: `indihub-agent` speaks to the INDIHUB-cloud so special dev-server will be added for development purposes soon.
The INDIHUB-network is in its beta release at the moment. We board new hosts on the network, collect data and most importantly - feedback from our first hosts.