Stellarium
24.3
|
The RemoteControl plugin provides an HTTP-based interface to Stellarium, implemented on the server-side through implementations of AbstractAPIService. The APIController maintains the list of registered services, and dispatches HTTP requests to the right service. The API is accessible under the server path /api/
. For example, if you have the server running on the default port of 8090, you can access the operation find of the ObjectService to look for objects with moon
in their name by accessing
Instead of the HTTP remote interface you can also use tools like cURL to access the API remotely. For POST operations, you would use the flag -d
to pass parameters. For GET operations, you should use the additional flag -G
if parameters are required. Examples:
If authentication is enabled (see RemoteControl class), HTTP Basic access authentication is expected, with an empty username. HTTPS configuration is currently not implemented, even if the underlying QtWebApp library would allow it.
Most operations return data in the JSON format, allowing it to be easily used in web applications. The format of the returned JSON data is described for each operation below. Some operations return plain text if only simple data is requested, or to confirm the success of an operation: to indicate success "ok" may be returned, in an error case an HTTP error code may be returned together with a string "error: error message" in the response body. Other operations may return HTML or even image data, you can check the returned Content-Type header if you are not sure what to expect.
The simplest way to expose new data through the API is by using the StelProperty system for a property you want to access. In this way, the data is available through the MainService (allowing tracking of changes) and the StelPropertyService (giving a snapshot of current values, metadata information and allowing to change values). You do not need to change/implement a new service in any way for this case.
If you want to expose more complex behaviour, you may need to implement your own AbstractAPIService and register it with the APIController.
The default services are registered in the RequestHandler::RequestHandler() constructor. They are:
Service | Path | Description |
---|---|---|
MainService | main | Implements the main API services, including the status operation which can be repeatedly polled to find the current state of the main program, including time, view, location, StelAction and StelProperty state changes, movement, script status ... |
ObjectService | objects | Provides operations to look up objects in the Stellarium catalogs. |
ScriptService | scripts | |
SimbadService | simbad | Allows SIMBAD object lookups like SearchDialog uses. |
StelActionService | stelaction | Provides services related to StelAction. |
StelPropertyService | stelproperty | Provides services related to StelProperty. |
LocationService | location | Provides methods to look up location-related information, and change the current location. |
LocationSearchService | locationsearch | Provides predefined location search functionality, using the StelLocationMgr. |
ViewService | view | Provides services related to the view (landscape, sky culture, projection). |
Implemented by MainService::getImpl
Parameters: [actionId (Number)] [propId (Number)]
This operation can be polled every few moments to find out if some primary Stellarium state changed. It returns a JSON object with the following format:
The actionChanges
and propertyChanges
sections allow a remote interface to track boolean StelAction and/or StelProperty changes. On the initial poll, you should pass -2 as propId
and actionId
. This indicates to the service that you want a full list of properties/actions and their current values. When receiving the answer, you should set your local propId
/actionId
to the id contained in actionChanges
and propertyChanges
, and re-send it with the next request as parameter again. This allows the MainService to find out which changes must be sent to you (it maintains a queue of action/property changes internally, incrementing the ID with each change), and you only have to process the differences instead of everything.
Returns the list of all known plugins, as a JSON object of format:
Parameters: [coord (j2000|jNow|altAz) ] [ ref (on|off|auto) ]
Returns the current view direction, as a JSON object of format:
Without the optional coord
, all versions are returned. The returned values are 3D vectors.
x= | cos(δ)*cos(α) |
y= | cos(δ)*sin(α) |
z= | sin(δ) |
For the vector in altAz
system, the actually returned values are based on an azimuth Az' counted from South (x=1) towards East (y=1), Az'=180-Az.
x= | cos(alt)*cos(Az') |
y= | cos(alt)*sin(Az') |
z= | sin(alt) |
If the optional parameter ref
is given, it governs refraction setting and it applies to the jNow
output only. "On" applies refraction, "off" does not apply, and "auto" (or any other value) applies it when atmosphere setting is active.
Implemented by MainService::postImpl
Parameters: time (Number) timerate (Number)
Sets the current Stellarium simulation time and/or timerate. The time
parameter defines the current time (Julian day) as passed to StelCore::setJD. The timerate
parameter allows to change the speed at which the simulation time moves (in JDay/sec) as passed to StelCore::setTimeRate.
Parameters: [target (String) | position (JSON Number Array of size 3, i.e. Vec3d)] [mode (String)]
Sets the current app focus/selection. If no parameters are given, the current selection is cleared. If the target
parameter was given, the object to be selected is looked up by name (first the localized name is tried, then the english name). If the optional mode
parameter is given, it determines how to change the view. The default is 'center'
which selects the object and moves it into the view's center. If it is set to 'zoom'
, it automatically zooms in on the object (StelMovementMgr::autoZoomIn) on selection and automatically zooms out when the selection is cleared. If it is set to 'mark'
, the selection is just marked, but no view adjustment is done. If the position
parameter is used, it is interpreted as a coordinate in the J2000 frame, and focused using StelMovementMgr::moveToJ2000. The mode
parameter has no effect here. The target
parameter takes precedence over the position
parameter, if both are given.
Parameters: x (Number) y (Number)
Allows viewport movement, like using the arrow keys in the main program. This allows interfaces to create a "virtual joystick" to move the view manually. This operation defines the intended move direction. x
and y
define the intended move speed in azimuth and altitude (i.e. a negative x
means left). Values of +-1.0 correspond to the same speed as used for the arrow keys. This operation works in conjunction with the update() method - until the movement is stopped (i.e. x
and y
are zero), or no move
command has been received for a specified time (about a second), the movement is performed in the given directions.
Parameters: j2000 (Vec3d) | jNow (Vec3d) [ ref (on|off|auto) ] | altAz (Vec3d) | (az (Number) alt (Number))
Sets the view direction. When the j2000
parameter is given (interpreted as JSON Number Array of size 3), it sets the view in J2000 coordinates (see StelMovementMgr::setViewDirectionJ2000). When the jNow
parameter is given (interpreted as JSON Number Array of size 3), it sets the view in coordinates of current date. An optional parameter ref
governs refraction mode, default auto
. When the altAz
parameter is given, the 3-element vector is interpreted as if in the rectangular surface direction frame centered on the current location. For example, [1,0,0]
would point the view directly south, and [0,1,0]
directly east. The last parameter style provides the view in altitude/azimuth spherical coordinates/angles. az
and alt
must be given in radians. Omitting one value will keep the relevant coordinate unchanged.
Parameters: fov (Number)
Sets the current field-of-view using StelCore::setFov
Parameters: w (int) h (int)
Sets the window size using StelMainView::setWindowSize() This can be useful e.g. when Stellarium provides image background inserts via spout.
Implemented by ObjectService::getImpl
Parameters: str (String)
Finds objects which match the search string str
, which may contain greek/unicode characters like in the SearchDialog. Returns a JSON String array of search matches
Parameters: [name (String)]
Parameters: [format (String)]
(strings "json" or "map" for JSON, any other value provides HTML)
Returns an info string about the object identified by name
in HTML (StelObject::getInfoString) or JSON (StelObject::getInfoMap) format. If no parameter name
is given, the currently selected object is used.
Returns all object types available in the internal catalogs as a JSON array of objects of format
Parameters: type (String) [english (Number)]
Returns all objects of the specified type
. If english
is given and it evaluates to a "true" value, the english names will be returned, otherwise the localized names will be returned. Returns a JSON string array.
Implemented by ScriptService::getImpl
Lists all known script files, as a JSON string array.
Parameters: id (String) [html (any type)]
Returns information about the script identified by id
. If the optional parameter html
is present (its value is ignored), the info is formatted using StelScriptMgr::getHtmlDescription and suitable for inclusion into an iframe
element, otherwise this operation returns a JSON object of format:
Returns the current script status as a JSON object of format:
StelScriptMgr.runningScriptId
that can be used to find out the active script.Implemented by ScriptService::postImpl
Parameters: id (String)
Runs the script with the given id
. Will fail if a script is currently running.
Parameters: code (String) [useIncludes (Bool)]
Directly executes the given script code
. If useIncludes
is given and evaluates to true, the standard include folder will be used. Script execution will fail if a script is already running.
Stops the execution of a running script.
Implemented by SimbadService::getImpl
Parameters: str (String)
Performs a SIMBAD lookup for the string str
using the Stellarium-configured server and returns the results as a JSON object of format
Implemented by StelActionService::getImpl
Lists all registered StelActions, in the format
Implemented by StelActionService::postImpl
Parameters: id (String)
Triggers or toggles the StelAction specified by id
. If it was a boolean action, returns the new state of the action (strings "true"/"false").
Implemented by StelPropertyService::getImpl
Lists all registered StelProperties, in the format
Implemented by StelPropertyService::postImpl
Parameters: id (String) value (String)
Sets the StelProperty identified by id
to the value value
. The value is converted to the StelProperty type using QVariant logic, an error is returned if this is somehow not possible.
Implemented by LocationService::getImpl
Returns the list of all stored location IDs (keys of StelLocationMgr::getAllMap) as JSON string array
Returns the list of all known countries (StelLocaleMgr::getAllCountryNames), as a JSON array of objects of format
Returns the list of all solar system planet names (SolarSystem::getAllPlanetEnglishNames), as a JSON array of objects of format
Parameters: planet (String)
Returns the planet texture image for the planet
(english name)
Implemented by LocationService::postImpl
Parameters: id (String) | ( [latitude (Number)] [longitude (Number)] [altitude (Number)] [name (String)] [country (String)] [planet (String)] )
Changes and moves to a new location. If id
is given, all other parameters are ignored, and a location is searched from the named locations using StelLocationMgr::locationForString with the id
. Else, the other parameters change the specific field of the current StelLocation.
Implemented by LocationSearchService::getImpl
Parameters: term (String)
Searches the term
in the list of predefined locations of the StelLocationMgr, and returns a JSON string array of the results.
Parameters: [planet (String)] [latitude (Number)] [longitude (Number)] [radius (Number)]
Searches near the location defined by planet
, latitude
and longitude
for predefined locations (inside the given radius
) using StelLocationMgr::pickLocationsNearby, returns a JSON string array.
Implemented by ViewService::getImpl
Lists the installed landscapes as a JSON object of format
Note that the slash at the end is mandatory!
Provides virtual filesystem access to the current landscape directory. The operation can take a longer path in the URL. The remainder is used to access files in the landscape directory. If no longer path is given, the current HTML landscape description (as per LandscapeMgr::getCurrentLandscapeHtmlDescription) is returned. An example: landscapedescription/image.png
returns image.png
from the current landscape directory.
This operation allows to set up an HTML iframe
or similar for the landscape description, including all images, etc. embedded in the HTML description.
Lists the installed sky cultures as a JSON object of format
Note that the slash at the end is mandatory!
Provides virtual filesystem access to the current skyculture directory. The operation can take a longer path in the URL. The remainder is used to access files in the skyculture directory. If no longer path is given, the current HTML skyculture description (as per StelSkyCultureMgr::getCurrentSkyCultureHtmlDescription) is returned. An example: skyculturedescription/image.png
returns image.png
from the current skyculture directory.
This operation allows to set up an HTML iframe
or similar for the skycultures description, including all images, etc. embedded in the HTML description.
Lists the available projection types as a JSON object of format
Returns the HTML description of the current projection (StelProjector::getHtmlSummary)