Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added basic integration to the Spoolman filament manager #651

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ The format is based on [Keep a Changelog].
- **metadata**: Added support for OrcaSlicer
- **zeroconf**: Added support for a configurable mDNS hostname.
- **zeroconf**: Added support for UPnP/SSDP Discovery.
- **spoolman**: Added integration to the
[Spoolman](https://github.com/Donkie/Spoolman) filament manager.

### Fixed

Expand Down
16 changes: 16 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -2609,6 +2609,22 @@ state_response_template:
{set_result("energy", notification["aenergy"]["by_minute"][0]|float * 0.000001)}
```

### `[spoolman]`

Enables integration with the [Spoolman](https://github.com/Donkie/Spoolman)
filament manager. Moonraker will automatically send filament usage updates to
the Spoolman database.

Front ends can also utilize this config to provide a built-in management tool.

```ini
# moonraker.conf

[spoolman]
server: http://192.168.0.123:7912
# URL to the Spoolman instance. This parameter must be provided.
```

## Include directives

It is possible to include configuration from other files via include
Expand Down
148 changes: 144 additions & 4 deletions docs/web_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -3798,7 +3798,7 @@ JSON-RPC request:
{
"jsonrpc": "2.0",
"method": "server.webcams.get_item",
"parmams": {
"params": {
"name": "cam_name"
},
"id": 4654
Expand Down Expand Up @@ -3862,7 +3862,7 @@ JSON-RPC request:
{
"jsonrpc": "2.0",
"method": "server.webcams.post_item",
"parmams": {
"params": {
"name": "cam_name",
"snapshot_url": "/webcam?action=snapshot",
"stream_url": "/webcam?action=stream"
Expand Down Expand Up @@ -3948,7 +3948,7 @@ JSON-RPC request:
{
"jsonrpc": "2.0",
"method": "server.webcams.delete_item",
"parmams": {
"params": {
"name": "cam_name"
},
"id": 4654
Expand Down Expand Up @@ -3997,7 +3997,7 @@ JSON-RPC request:
{
"jsonrpc": "2.0",
"method": "server.webcams.test",
"parmams": {
"params": {
"name": "cam_name"
},
"id": 4654
Expand Down Expand Up @@ -5211,6 +5211,127 @@ An object containing all measurements for every configured sensor:
}
```

### Spoolman APIs
The following APIs are available to interact with the Spoolman integration:

#### Set active spool
Set the ID of the spool that Moonraker should report usage to Spoolman of.

HTTP request:
```http
POST /spoolman/spool_id
Content-Type: application/json

{
"spool_id": 1
}
```
JSON-RPC request:
```json
{
"jsonrpc": "2.0",
"method": "spoolman.post_spool_id",
"params": {
"spool_id": 1
},
"id": 4654
}
```

Returns:

The id of the now active spool:

```json
{
"spool_id": 1
}
```

!!! note
Send an empty object, `{}`, to un-set the spool ID and stop any reporting.
The response `spool_id` will then be set to *null*

#### Get active spool
Retrieve the ID of the spool to which Moonraker reports usage for Spoolman.

HTTP request:
```http
GET /spoolman/spool_id
```
JSON-RPC request:
```json
{
"jsonrpc": "2.0",
"method": "spoolman.get_spool_id",
"id": 4654
}
```

Returns:

The id of the active spool:

```json
{
"spool_id": 1
}
```

!!! note
The `spool_id` can be *null* if there is no active spool.

#### Proxy

Moonraker supplies a proxy endpoint where you have full access to the Spoolman
API without having to configure the endpoint yourself.

See Spoolman's [OpenAPI Description](https://donkie.github.io/Spoolman/) for
detailed information about it's API.

HTTP request:
```http
POST /spoolman/proxy
Content-Type: application/json

{
"request_method": "POST",
"path": "/v1/spool",
"query": "a=1&b=4",
"body": {
"filament_id": 1
}
}
```

JSON-RPC request:
```json
{
"jsonrpc": "2.0",
"method": "spoolman.post_proxy",
"params": {
"request_method": "POST",
"path": "/v1/spool",
"query": "a=1&b=4",
"body": {
"filament_id": 1
}
},
"id": 4654
}
```

The following parameters are available. `request_method` and `path` are required, the rest are optional.

- `request_method`: The HTTP request method, e.g. `GET`, `POST`, `DELETE`, etc.
- `path`: The endpoint, including API version, e.g. `/v1/filament`.
- `query`: The query part of the URL, e.g. `filament_material=PLA&vendor_name=Prima`.
- `body`: The request body for the request.

Returns:

The json response from the Spoolman server.

### OctoPrint API emulation
Partial support of OctoPrint API is implemented with the purpose of
allowing uploading of sliced prints to a moonraker instance.
Expand Down Expand Up @@ -6623,6 +6744,25 @@ webcam is added, removed, or updated.
The `webcams` field contans an array of objects like those returned by the
[list webcams](#list-webcams) API.

#### Spoolman active spool ID changed

Moonraker will emit the `notify_active_spool_set` event when the active spool
ID for the Spoolman integration has been changed.

See the [Spoolman API](#spoolman-apis) for more information.

```json
{
"jsonrpc": "2.0",
"method": "notify_active_spool_set",
"params": [
{
"spool_id": 1
}
]
}
```

#### Agent Events
Moonraker will emit the `notify_agent_event` notification when it
an agent event is received.
Expand Down
Loading