Skip to content

wmarchesi123/go-3dprint-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-3dprint-client

A Go client library for interacting with 3D printing services, including OctoPrint and Spoolman.

Features

  • OctoPrint Client: Full API client for OctoPrint with printer control, job monitoring, and temperature management
  • Spoolman Client: API client for Spoolman filament tracking
  • Configuration Management: Shared configuration loader for multi-printer setups
  • Type-Safe Models: Comprehensive data models for all API responses

Installation

go get github.com/wmarchesi123/go-3dprint-client

Usage

Configuration

The library expects environment variables for configuration:

# Spoolman API URL
SPOOLMAN_URL=http://spoolman:7912

# Printer 1 Configuration
PRINTER_1_NAME=Purple-MK4S
PRINTER_1_URL=http://purple-octoprint
PRINTER_1_KEY=your-api-key-here

# Printer 2 Configuration
PRINTER_2_NAME=Original-MK4S
PRINTER_2_URL=http://original-octoprint
PRINTER_2_KEY=your-api-key-here

Loading Configuration

import "github.com/wmarchesi123/go-3dprint-client/config"

cfg, err := config.LoadConfig()
if err != nil {
    log.Fatal(err)
}

Using the OctoPrint Client

import "github.com/wmarchesi123/go-3dprint-client/octoprint"

// Create a client
client := octoprint.NewClient("http://octoprint-url", "api-key")

// Get printer state
state, err := client.GetPrinterState()
if err != nil {
    log.Fatal(err)
}

// Get current job
job, err := client.GetJob()
if err != nil {
    log.Fatal(err)
}

// Set temperatures
err = client.SetToolTemperature(0, 215.0)  // Tool 0 to 215°C
err = client.SetBedTemperature(60.0)       // Bed to 60°C

// Get current spool
spoolID, err := client.GetCurrentSpool(0)  // Tool 0

// Set active spool
err = client.SetActiveSpool("123", 0)      // Spool ID 123 on tool 0

// Get thumbnail URL
thumbnailURL := client.GetThumbnail("/path/to/file.gcode")

Using the Spoolman Client

import "github.com/wmarchesi123/go-3dprint-client/spoolman"

// Create a client
client := spoolman.NewClient("http://spoolman-url")

// Get a specific spool
spool, err := client.GetSpool("123")
if err != nil {
    log.Fatal(err)
}

// Get all spools
spools, err := client.GetAllSpools()
if err != nil {
    log.Fatal(err)
}

// Format spool info for display
info := spoolman.FormatSpoolInfo(spool)
fmt.Printf("Spool: %s, Material: %s, Remaining: %.1fg\n", 
    info["name"], info["material"], info["remaining"])

API Reference

OctoPrint Client Methods

  • GetPrinterState() - Get printer state and temperatures
  • GetJob() - Get current print job information
  • GetCurrentSpool(tool) - Get the currently selected spool ID
  • SetActiveSpool(spoolID, tool) - Set the active spool for a tool
  • GetThumbnail(path) - Get the thumbnail URL for a G-code file
  • SetToolTemperature(tool, target) - Set hotend temperature
  • SetBedTemperature(target) - Set bed temperature

Spoolman Client Methods

  • GetSpool(id) - Get a specific spool by ID
  • GetAllSpools() - Get all spools
  • FormatSpoolInfo(spool) - Format spool data for display

Configuration Call

  • LoadConfig() - Load configuration from environment variables

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages