bambu

package module
v0.0.0-...-41f30bc Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 14, 2025 License: MIT Imports: 15 Imported by: 0

README

Bambu Go Client

Description

Bambu Go Client is a Go library designed to interact with BambuLab 3D printers via MQTT and HTTP. It allows subscribing to device reports, publishing events, and managing device connections seamlessly.

Installation

To use this library in your Go project, you can install it using:

go get github.com/dhiaayachi/bambu-go

Usage

Get an account token

Use the provided login-helper tool to retrieve a valid token as follow

cd login-helper
go build .
./login-helper --account '<email>' --password '<makers world password>'

provide the access code, sent to your configured email for 2FA auth.

The returned access token will be similar to Access Token: AACjxHoRLGcgKLlS8fQ.... and is valid for 3 months. pass that token to the bambu-go library.

Unfortunately, because of the 2FA limitation and the impossibility to get an access token without it, it's impossible to integrate the login flow in the library for now.

Creating a Client (Cloud)
package main

import (
	"fmt"
	"github.com/dhiaayachi/bambu-go/bambu"
)

func main() {
	client, err := bambu.NewBambuClientCloud("localhost", "1883", "your_token", "http://api.example.com")
	if err != nil {
		fmt.Println("Error creating client:", err)
		return
	}
	fmt.Println("Client created successfully")
}
Creating a Client (Cloud)
package main

import (
	"fmt"
	"log"
	"github.com/dhiaayachi/bambu-go/bambu"
)

func main() {
	client, err := bambu.NewBambuClientLan("192.168.2.2", "8883", "bblp", "device_token", "./ca_cert.pem")
	if err != nil {
		fmt.Println("Error creating client:", err)
		return
	}
	fmt.Println("Client created successfully")
}
Subscribing to Device Events
client.SubscribeAll(func(devID string, evt events.ReportEvent) {
	fmt.Printf("Received event from device %s: %v\n", devID, evt)
})

Running Tests

To run the tests for this library, use:

go test ./...

Running examples

Events Logger example
Lan
cd examples/events-logger
go build
./events-logger --lan --host <Printer IP> --port 8883 --token <Access code> --cert-file ./ca_cert.pem --user bblp --serial <device serial number>
Cloud
cd examples/events-logger
go build
./events-logger --port 8883 --token AADzIu7fPZrsdhasaaUubPbKWP8E2LvF6rAPwwQhyqD....
Togger Light example
Lan
cd examples/events-logger
go build
./toggle-light --lan --host <Printer IP> --port 8883 --token <Access code> --cert-file ./ca_cert.pem --user bblp --serial <device serial number>
Cloud
cd examples/events-logger
go build
./toggle-light --port 8883 --token AADzIu7fPZrsdhasaaUubPbKWP8E2LvF6rAPwwQhyqD....

License

This project is licensed under the MIT License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewBambuClientCloud

func NewBambuClientCloud(host string, port string, token string, url string) (*Client, error)

func NewBambuClientLan

func NewBambuClientLan(host string, port string, user string, password string, cert string, deviceSerial string) (*Client, error)

func (*Client) Connect

func (b *Client) Connect() error

func (*Client) Devices

func (b *Client) Devices() []string

func (*Client) Publish

func (b *Client) Publish(devId string, evt events.RequestEvent) error

func (*Client) SubscribeAll

func (b *Client) SubscribeAll(handler func(devId string, evt events.ReportEvent)) error

func (*Client) Unsubscribe

func (b *Client) Unsubscribe(devID string) error

func (*Client) UnsubscribeAll

func (b *Client) UnsubscribeAll() error

type ConnectionMode

type ConnectionMode string
const ConnectionModeCloud ConnectionMode = "cloud"
const ConnectionModeLan ConnectionMode = "lan"

type Device

type Device struct {
	DevId          string  `json:"dev_id"`
	Name           string  `json:"name"`
	Online         bool    `json:"online"`
	PrintStatus    string  `json:"print_status"`
	DevModelName   string  `json:"dev_model_name"`
	DevProductName string  `json:"dev_product_name"`
	DevAccessCode  string  `json:"dev_access_code"`
	NozzleDiameter float64 `json:"nozzle_diameter"`
	DevStructure   string  `json:"dev_structure"`
}

Directories

Path Synopsis
examples
events-logger command
toggle-light command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL