2013-12-16 00:47:06 +00:00
|
|
|
.. _sec-api-connection:
|
|
|
|
|
|
|
|
|
|
*******************
|
|
|
|
|
Connection handling
|
|
|
|
|
*******************
|
|
|
|
|
|
2013-12-21 12:01:18 +00:00
|
|
|
.. contents::
|
2013-12-16 00:47:06 +00:00
|
|
|
|
|
|
|
|
.. _sec-api-connection-current:
|
|
|
|
|
|
|
|
|
|
Get connection settings
|
|
|
|
|
=======================
|
|
|
|
|
|
2013-12-22 01:01:48 +00:00
|
|
|
.. http:get:: /api/connection
|
2013-12-16 00:47:06 +00:00
|
|
|
|
|
|
|
|
Retrieve the current connection settings, including information regarding the available baudrates and
|
|
|
|
|
serial ports and the current connection state.
|
|
|
|
|
|
2014-03-24 21:50:56 +00:00
|
|
|
**Example**
|
2013-12-16 00:47:06 +00:00
|
|
|
|
|
|
|
|
.. sourcecode:: http
|
|
|
|
|
|
2014-02-14 19:33:53 +00:00
|
|
|
GET /api/connection HTTP/1.1
|
2013-12-16 00:47:06 +00:00
|
|
|
Host: example.com
|
|
|
|
|
X-Api-Key: abcdef...
|
|
|
|
|
|
|
|
|
|
.. sourcecode:: http
|
|
|
|
|
|
|
|
|
|
HTTP/1.1 200 OK
|
|
|
|
|
Content-Type: application/json
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
"current": {
|
|
|
|
|
"state": "Operational",
|
|
|
|
|
"port": "/dev/ttyACM0",
|
2014-12-02 10:57:03 +00:00
|
|
|
"baudrate": 250000,
|
|
|
|
|
"printerProfile": "_default"
|
2013-12-16 00:47:06 +00:00
|
|
|
},
|
|
|
|
|
"options": {
|
|
|
|
|
"ports": ["/dev/ttyACM0", "VIRTUAL"],
|
|
|
|
|
"baudrates": [250000, 230400, 115200, 57600, 38400, 19200, 9600],
|
2014-12-02 10:57:03 +00:00
|
|
|
"printerProfiles": [{"name": "Default", id: "_default"}],
|
2013-12-16 00:47:06 +00:00
|
|
|
"portPreference": "/dev/ttyACM0",
|
|
|
|
|
"baudratePreference": 250000,
|
2014-12-02 10:57:03 +00:00
|
|
|
"printerProfilePreference": "_default",
|
2013-12-16 00:47:06 +00:00
|
|
|
"autoconnect": true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
:statuscode 200: No error
|
|
|
|
|
|
|
|
|
|
.. _sec-api-connection-command:
|
|
|
|
|
|
|
|
|
|
Issue a connection command
|
|
|
|
|
==========================
|
|
|
|
|
|
2013-12-22 01:01:48 +00:00
|
|
|
.. http:post:: /api/connection
|
2013-12-16 00:47:06 +00:00
|
|
|
|
|
|
|
|
Issue a connection command. Currently available command are:
|
|
|
|
|
|
|
|
|
|
connect
|
|
|
|
|
Instructs OctoPrint to connect to the printer. Additional parameters are:
|
|
|
|
|
|
|
|
|
|
* ``port``: Optional, specific port to connect to. If not set the current ``portPreference`` will be used, or if
|
|
|
|
|
no preference is available auto detection will be attempted.
|
|
|
|
|
* ``baudrate``: Optional, specific baudrate to connect with. If not set the current ``baudratePreference`` will
|
|
|
|
|
be used, or if no preference is available auto detection will be attempted.
|
2014-12-02 10:57:03 +00:00
|
|
|
* ``printerProfile`` Optional, specific printer profile to use for connection. If not set the current default printer
|
|
|
|
|
profile will be used.
|
2013-12-16 00:47:06 +00:00
|
|
|
* ``save``: Optional, whether to save the request's ``port`` and ``baudrate`` settings as new preferences. Defaults
|
|
|
|
|
to ``false`` if not set.
|
|
|
|
|
* ``autoconnect``: Optional, whether to automatically connect to the printer on OctoPrint's startup in the future.
|
|
|
|
|
If not set no changes will be made to the current configuration.
|
|
|
|
|
|
|
|
|
|
disconnect
|
|
|
|
|
Instructs OctoPrint to disconnect from the printer.
|
|
|
|
|
|
|
|
|
|
**Example Connect Request**
|
|
|
|
|
|
|
|
|
|
.. sourcecode:: http
|
|
|
|
|
|
2014-02-14 19:33:53 +00:00
|
|
|
POST /api/connection HTTP/1.1
|
2013-12-16 00:47:06 +00:00
|
|
|
Host: example.com
|
|
|
|
|
Content-Type: application/json
|
|
|
|
|
X-Api-Key: abcdef...
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
"command": "connect",
|
|
|
|
|
"port": "/dev/ttyACM0",
|
|
|
|
|
"baudrate": 115200,
|
2014-12-02 10:57:03 +00:00
|
|
|
"printerProfile": "my_printer_profile",
|
2013-12-16 00:47:06 +00:00
|
|
|
"save": true,
|
|
|
|
|
"autoconnect": true
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-24 21:50:56 +00:00
|
|
|
.. sourcecode:: http
|
|
|
|
|
|
|
|
|
|
HTTP/1.1 204 No Content
|
|
|
|
|
|
2013-12-16 00:47:06 +00:00
|
|
|
**Example Disconnect Request**
|
|
|
|
|
|
|
|
|
|
.. sourcecode:: http
|
|
|
|
|
|
2014-02-14 19:33:53 +00:00
|
|
|
POST /api/connection HTTP/1.1
|
2013-12-16 00:47:06 +00:00
|
|
|
Host: example.com
|
|
|
|
|
Content-Type: application/json
|
|
|
|
|
X-Api-Key: abcdef...
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
"command": "disconnect"
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-24 21:50:56 +00:00
|
|
|
.. sourcecode:: http
|
|
|
|
|
|
|
|
|
|
HTTP/1.1 204 No Content
|
|
|
|
|
|
2013-12-16 00:47:06 +00:00
|
|
|
:json string command: The command to issue, either ``connect`` or ``disconnect``
|
|
|
|
|
:json string port: ``connect`` command: The port to connect to. If left out either the existing ``portPreference``
|
|
|
|
|
will be used, or if that is not available OctoPrint will attempt auto detection. Must be part
|
|
|
|
|
of the available ports.
|
|
|
|
|
:json number baudrate: ``connect`` command: The baudrate to connect with. If left out either the existing
|
|
|
|
|
``baudratePreference`` will be used, or if that is not available OctoPrint will attempt
|
|
|
|
|
autodetection. Must be part of the available baudrates.
|
2014-12-02 10:57:03 +00:00
|
|
|
:json string printerProfile: ``connect`` command: The id of the printer profile to use for the connection. If left out the current
|
|
|
|
|
default printer profile will be used. Must be part of the available printer profiles.
|
2013-12-16 00:47:06 +00:00
|
|
|
:json boolean save: ``connect`` command: Whether to save the supplied connection settings as the new preference.
|
|
|
|
|
Defaults to ``false`` if not set.
|
|
|
|
|
:json boolean autoconnect: ``connect`` command: Whether to attempt to automatically connect to the printer on server
|
|
|
|
|
startup. If not set no changes will be made to the current setting.
|
2014-02-15 06:51:27 +00:00
|
|
|
:statuscode 204: No error
|
2013-12-16 00:47:06 +00:00
|
|
|
:statuscode 400: If the selected `port` or `baudrate` for a ``connect`` command are not part of the available
|
|
|
|
|
options.
|