Skip to content

REST API

printpal.io edited this page Sep 8, 2023 · 2 revisions

REST API

The PrintWatch AI plugin provides a REST API for the DWC to interact with. This API can be used to create a frontend component for any 3D printing system like Klipper, Duet, etc.


POST /machine/printwatch/set_settings

Description:

Update a setting on the backend

Inputs:

Request Body:

Type: application/json

{
  [Optional] api_key : string,
  [Optional] printer_id : string,
  [Optional] duet_ip : string,
  [Optional] camera_ip : string,
  [Optional] email_addr : string,
  [Optional] test_mode : bool,
  [Optional] monitoring_on: bool,
  [Optional] notication_threshold : float,
  [Optional] action_threshold : float,
  [Optional] buffer_length : int,
  [Optional] buffer_percent : int,
  [Optional] notify_action : bool,
  [Optional] pause_action : bool,
}

Output:

Type: application/json

{
  status : int = 8000 | 8001
}

Possible values of status are:

8000: Request successful.

8001: Request Error


GET /machine/printwatch/get_settings

Description:

Retrieve settings stored in the backend

Inputs: None

Output:

Type: application/json

{
  status : int = 8000,
  settings : dict = {
                "api_key" : "",
                "printer_id" : "",
                "duet_ip" : "",
                "camera_ip" : "",
                "email_addr" : "",
                "test_mode" : False,
                "monitoring_on" : False,
                "thresholds" : {
                    "notification" : 0.3,
                    "action" : 0.6,
                    "display" : 0.6
                },
                "buffer_length" : 16,
                "buffer_percent" : 60,
                "actions": {
                    "pause" : False,
                    "cancel" : False,
                    "notify" : False,
                    "extruder_off" : False,
                    "macro" : False
                }
            }
}

Possible values of status are:

8000: Request successful.


GET /machine/printwatch/monitor

Description:

Retrieves tracking variables for the active AI loop.

Inputs: None

Output:

Type: application/json

{
  status : int = 8000 | 8001,
  items : dict = {
    status : dict = {
      scores : list = [0, 0, 0, ..., 0],
      levels : list = [false, false],
      buffer : list = [[0, 0, 0], ..., [0, 0, 0]]
    }
  }
}

Possible values of status are:

8000: Request successful.

8001: Request Error

The scores and buffer responses correspond to the circular buffers used for tracking the defectiveness score. To obtain the most recent value for either list, retrieve the last entry of the list:

most_recent_score = scores[-1]
most_recent_sma = buffer[-1][0] # buffer contains a list of length 3 at each index.

GET /machine/printwatch/preview

Description:

Retrieves the latest detection preview with bounding boxes drawn.

Inputs: None

Output:

Type: application/json

{
  status : int = 8000 | 8001,
  items : dict = {
    status : dict = {
      preview : string = ''
    }
  }
}

Possible values of status are:

8000: Request successful.

8001: Request Error

The preview output is a base64 encoded image string.


GET /machine/printwatch/monitor_init

Description:

Force initialize the monitor. This starts the monitoring loop on the backend.

Inputs: None

Output:

Type: application/json

{
  status : int = 8000 | 8001,
}

Possible values of status are:

8000: Request successful.

8001: Request Error - the monitor loop already exists


GET /machine/printwatch/monitor_off

Description:

Force initialize the monitor. This starts the monitoring loop on the backend.

Inputs: None

Output:

Type: application/json

{
  status : int = 8000 | 8001,
}

Possible values of status are:

8000: Request successful.

8001: Request Error