ASCOM Alpaca API Reference
ASCOM Alpaca API Reference
Abstract
This document is the technical reference for the ASCOM Alpaca APIs and describes how to
use the API. It also describes the Alpaca Discovery protocol and some of the fundamental
behavioural principles that underly the APIs and their effective exploitation.
Term Meaning
Alpaca Device Hardware or software that supports the Alpaca Management and Alpaca
Device API protocols to provide access to one or more ASCOM Devices.
ASCOM Device An implementation of an ASCOM device interface such as ITelescope or
IFocuser that can be accessed through the Alpaca Device API protocol.
ASCOM Device Type One of ASCOM’s supported hardware device types e.g. telescopes,
focusers, rotators and cameras.
IP Endpoint The host / IP address and port number on which the Alpaca device is
operating
Must This is an absolute, mandated, requirement; no deviation is possible.
Should This is highly recommended best practice, but is not mandated
Could This is optional at the implementor’s discretion
The simplest Alpaca Device would present a single ASCOM Device, such as a focuser or filter wheel,
and would be dedicated to this single task. This approach will work well for existing devices that
support serial or USB connections for example and that are to be updated to support network
connectivity.
A complex Alpaca Device may present multiple1 ASCOM Devices of several different ASCOM Device
Types through its single IP Endpoint. For example, a single Alpaca Device could present a dome, a
mount, several focusers, a filter wheel and a rotator together with some observing conditions
devices.
1 Each Alpaca device can support up to 2,147,483,647 instances of each of the supported ASCOM Device Types.
1.3 Consolidation
The Alpaca API supports consolidation of multiple downstream Alpaca Devices into one virtual
Alpaca Device that presents a single aggregated device tree under one IP end point. This opens the
way to creation of physical devices that proxy Alpaca requests and to the use of web servers as
reverse proxies that front multiple Alpaca Devices.
To start exploring, go to the above URL and select either the “Device API” or the “Management API”
description using the drop-down at the top of the screen. You can then click a grey Show/Hide link to
expand one of the sets of methods and then click the blue GET or orange PUT methods for detailed
information on that API call.
Anyone who is familiar with the ASCOM COM based APIs should feel at home with the functionality
available through the Alpaca API.
1.6 Discovery
For the best astronomer user experience, Alpaca Devices should also implement the Alpaca
Discovery protocol (see section 4, Alpaca Discovery)
Alpaca clients and devices should behave in line with the robustness principle. For example:
• Alpaca clients should ensure that their commands adhere exactly to the API specification.
• Alpaca devices should ensure that their responses adhere exactly to the API specification.
• Alpaca clients and devices should not return errors when optional elements such as ClientID
or ServerTransactionID are not present.
• Alpaca clients and devices should not return errors when unrecognised parameters are
received.
2.1.4 Parameters
Many ASCOM methods require parameter values. All methods that use the HTTP GET verb should
include parameters as query string name-value pairs.
All methods that use the HTTP PUT verb should include name-value parameters in the body using the
"application/x-www-form-urlencoded" media type.
For example, these are valid API parameters on an HTTP GET transaction:
/api/v1/telescope/0/canslew?clientid=231&clienttransactionid=23
This is the same behaviour as defined for HTTP header keys in RFC 2616 (HTTP/1.X) and RFC7540
(HTTP/2).
Clients and drivers must expect incoming query parameter keys to have arbitrary casing.
E.g. 23.456 is a valid value to supply when setting the Telescope.TargetRightAscension property,
while 23,456 is not a valid value.
Alpaca Clients must expect to receive decimal values in this invariant culture format and to interpret
them accordingly.
e.g. Clients must parse the value returned by the Telescope.SiteElevation property using period as
the decimal separator, regardless of the locale in which they are running.
Alpaca is essentially a presentation layer for the ASCOM interface “business logic” and this
distinction between transport mechanic behaviour and ASCOM interface business logic behaviour is
reflected in Alpaca’s use of HTTP status codes.
Figure 1 - Alpaca HTTP status decision tree shows this separation, with HTTP 3XX and 4XX status codes
reflecting issues in the HTTP and Alpaca protocols, such as lack of authentication, badly formed or
missing parameters. These HTTP statuses indicate that the device:
• Refused to carry out the command for some reason e.g. could not authenticate the user
• Did not understand the operation it was being asked to perform
A 200 status indicates that the “business logic” ASCOM interface command was understood, and
that the device attempted to carry it out using ASCOM’s “Do it or return an error” mechanic. The
resultant JSON response includes an ErrorNumber value that the client can inspect to determine
whether the operation was successful in an ASCOM interface sense.
The following flow diagram shows how to decide which HTTP status code to return.
Access control
YES
Execute in accordance with the
2.6 ID Fields
To aid operational management and debugging, three ID fields are defined for use in read and write
transactions:
ID Maintained by Description
ClientID Client This is a 32-bit unsigned integer that the client can
choose to identify itself. It is recommended that values
should be within the range 0::65535 so that log files
appear orderly and readable!
ClientTransactionID Client This is a 32-bit unsigned integer that the client
maintains. The value should start at 1 and be
incremented by the client on each request to the
Alpaca device.
ServerTransactionID Alpaca Device This is a 32-bit unsigned integer that the Alpaca device
maintains. The value should start at 1 and be
incremented by the Alpaca device on each request.
The client id and transaction numbers should be supplied by the client in the request to uniquely
identify the client instance and specific transaction. The Alpaca device must return the client
Alpaca devices should record client ids and transaction numbers in their logs so that issues can be
tied back to specific transactions and outcomes correlated with client-side logs.
The server transaction id must be returned by the Alpaca device with every response so that issues
identified on the client side can easily be correlated with Alpaca device logs.
In addition, the JSON response will include the output from the command (if any) in the “Value”
parameter. This example is from the Telescope Simulator SupportedActions property:
GET /api/v1/telescope/0/supportedactions?ClientID=1&ClientTransactionID=6
{"Value":["AssemblyVersionNumber","SlewToHA","AvailableTimeInThisPointingState","TimeUntilPo
intingStateCanChange"],"ClientTransactionID":6,"ServerTransactionID":6, "ErrorNumber":0,
"ErrorMessage":"" }
This example shows the response from the Telescope simulator’s CanSlewAsync property:
GET /api/v1/telescope/0/canslewasync?ClientID=1&ClientTransactionID=20
{"Value":true,"ClientTransactionID":20,"ServerTransactionID":168, "ErrorNumber":0,
"ErrorMessage":"" }
Each exception has an associated HResult code in the range 0x80040400 to 0x80040FFF for historic
reasons related to Microsoft’s approach to error handling for COM applications. When expressed as
signed integers these exception numbers translate into very large and unwieldy negative numbers
e.g. 0x80040400 becomes -2,147,220,480 and 0x80040FFF becomes -2,147,217,409.
{"ClientTransactionID":23,"ServerTransactionID":55,"ErrorNumber":1025,
"ErrorMessage":"SiteElevation set - '-400' is an invalid value. The valid range is: -300 to 10000."}
For backward compatibility, a device can support more than one interface version. A list of
supported interface versions is available through the Alpaca management API as described in section
3.2.1.
Examples of breaking changes that would require a new Alpaca API version number:
• Changing element 1 from “api” to “alpacaApi”
• Changing the element 2 version number format from “v1” to “v1.0.0.0”
• Introducing a new element 6
The ASCOM Device InterfaceVersion defines the behaviour of the specified ASCOM Device when
presented with commands through the Alpaca API. InterfaceVersions will change as device APIs are
developed, however these changes are independent of the Alpaca API presentation elements and so
do not require that the Alpaca API version be changed as well.
In addition, the API defines a dedicated URL for each ASCOM Device presented by the Alpaca Device
so that ASCOM Device specific configuration can be set. This API is intended to facilitate
configuration of a single ASCOM Device, in a similar fashion to the COM SetupDialog method.
At minimum this must provide manufacturer and device descriptive information. This could be a
good place to enable the astronomer user to change the Alpaca discovery port number and any
other “whole device” configuration settings.
Please note that there is no Alpaca API version number in the apiversions URL.
This is by design so that this URL will work regardless of any Alpaca interface version number
changes in the future.
To provide backward compatibility, an Alpaca device can simultaneously support more than one
Alpaca interface version, and this is indicated by returning more than one integer version number in
the apiversions array.
At the time of writing only interface version 1 is defined and consequently all Alpaca devices should
return an integer array, containing the single value 1, as the response to this command.
The “configureddevices” endpoint should return an array of device configuration objects that
describe the ASCOM Device’s that are presented by the Alpaca Device. Each device description must
include the device’s name, it’s ASCOM device type, the device number that must be used to
communicate with this particular ASCOM Device and a globally unique id for this particular device.
The Alpaca management API path for these commands consists of three elements:
/management/vversion_number/command
http://api.peakobservatory.com/management/v1/configureddevices
The purpose of UIDs is to support “re-discovery” of Alpaca Devices in the event that a device’s IP
address changes but where client configurations are not automatically revised to match. For further
information please see section 0.
4.2 Definitions
Within this section “Device” refers to something (a driver or device) that exposes the Alpaca
interface and “Client” refers to client applications that want to locate and use the Device's API(s).
• DISCOVERY PORT: the port to which the Client Broadcasts the discovery message and on
which the Device listens. The Alpaca default discovery port is 32227.
• DISCOVERY MESSAGE: the message broadcast by the client on the DISCOVERY PORT.
• RESPONSE MESSAGE: is the message that the Device sends back via unicast to the client.
• ALPACA PORT: is the port on which the Alpaca management and device APIs are available.
• ASCOM DEVICE: An implementation of an ASCOM device interface such as ITelescope or
IFocuser that can be accessed through the Alpaca Device API protocol.
• UNIQUE ID: A string identifier for an ASCOM DEVICE that is globally unique.
• ALPACA DEVICE: Hardware or software that supports the Alpaca Management and Alpaca
Device API protocols to provide access to one or more ASCOM DEVICES.
Yes
Return Alpaca
Parse Alpaca RESPONSE MESSAGE
RESPONSE MESSAGE
to extract the device s ALPACA PORT
containing the ALPACA PORT
Yes
Valid Device
ASCOM DEVICE through the
API request?
Alpaca Device API.
Yes
The current, version 1, discovery message therefore contains 16 bytes, comprising 15 bytes from the
ASCII text: “alpacadiscovery” together with a single ASCII version byte:
alpacadiscovery1
Hex: 0x61, 0x6C, 0x70, 0x61, 0x63, 0x61, 0x64, 0x69, 0x73, 0x63, 0x6F, 0x76, 0x65, 0x72, 0x79, 0x31
The discovery message “alpacadiscovery” has been registered to ASCOM in the IANA service
registry:
https://www.iana.org/assignments/service-names-port-numbers
The UID is an ASCII string that MUST be unique to each ASCOM DEVICE. Its purpose is to help clients
re-discover a previously used ASCOM DEVICE if its IP address changes.
1. The UID must be derived from a 48bit or larger space and converted to an ASCII string.
2. The UID must be exposed through the UniqueID field of the Alpaca Management API
ConfiguredDevices response.
3. Manufacturers and developers must use appropriate algorithms to ensure that otherwise
identical devices have different UIDs.
4. Alpaca Devices MUST send the same UIDs on every network interface to which the device is
attached.
5. Once a UID has been assigned to an ASCOM DEVICE, it must never change. This means that:
a. An ASCOM DEVICE served by an ALPACA DEVICE will always be uniquely identifiable
through the assigned UID.
b. UID must be retained when devices are powered down.
4.8.2 IP versions
All Alpaca devices should support IPv4 to ensure widest adoption and best compatibility with client
devices and astronomy equipment. Devices could also support IPv6 at the discretion of the
manufacturer / software author.
• Routine Operations: Interface design always involves some negotiations between the
parties. Inevitably, a device maker may wish to have included in the interface some clever
means to make their device stand out above those of his competitors. On the other hand,
client programmers don't want to be writing code to manage an ever-expanding set of
these clever functions. It defeats the purpose of the standardized API. The ASCOM API was
therefore designed at its outset to cover routine operations only.
For example, a mount really only needs "point to these coordinates" and "track the
apparent motion of my object". The more accurately it does these things, the better. As a
client program developer, I don't want to be concerned about PEC or encoder resolutions or
servo currents.
• Synchronous vs Asynchronous Methods: One may think of a method call as one that returns
only when the requested operation has completed, which is a synchronous call. But some
types of operations can benefit by starting the operation and returning immediately. For
example, the Rotator.Move() method may return immediately.
If so, its return means only that the rotation was successfully started. Rotators are typically
slow, and the system can benefit by overlapping mount and rotator movement, so both
provide asynchronous calls. The status properties such as Rotator.IsMoving and
Telescope.IsSlewing are used to monitor progress of asynchronous calls.
• "Can" Properties: Some ASCOM APIs have "can" properties, which tell the client whether or
not a corresponding capability is available. For example, in the Telescope API, the
CanSlewAltAz property tells the client whether this specific mount can successfully execute
For example, a client can tell that the mount provides its positional azimuth by trying to read
the Azimuth property; it will either get an answer or a "not implemented" error. However, a
client cannot tell whether a mount can slew to alt/az coordinates without calling the method
and possibly changing the mount’s position. This is why a CanSlewAltAz property is provided
for the SlewToAltAz() method.