temper

package module
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2026 License: 0BSD Imports: 9 Imported by: 2 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

temper

Latest Release Software License Go ReportCard Go Doc

A zero-dependency library to read USB TEMPer thermometers on Linux.

Configuration

On Linux you need to set up some udev rules to be able to access the device as a non-root/regular user. Edit /etc/udev/rules.d/99-temper.rules and add these lines:

SUBSYSTEM=="hidraw", ATTRS{idVendor}=="1a86", ATTRS{idProduct}=="e025", GROUP="plugdev", SYMLINK+="temper%n"
SUBSYSTEM=="hidraw", ATTRS{idVendor}=="0c45", ATTRS{idProduct}=="7401", GROUP="plugdev", SYMLINK+="temper%n"
SUBSYSTEM=="hidraw", ATTRS{idVendor}=="0c45", ATTRS{idProduct}=="7402", GROUP="plugdev", SYMLINK+="temper%n"
SUBSYSTEM=="hidraw", ATTRS{idVendor}=="1130", ATTRS{idProduct}=="660c", GROUP="plugdev", SYMLINK+="temper%n"

Note that there are many versions of the TEMPer USB and your idVendor and idProduct ATTRs may differ.

Make sure your user is part of the plugdev group and reload the rules with sudo udevadm control --reload-rules. Unplug and replug the device.

Example Code

There are examples on how to use this repo in examples/main.go

Additionally, there is a cli-tool available at temper-cli

Acknowledgement

During my development I tested my code against the shell script found in this article.

As I only have one TEMPer device, I have sourced the product and vendor IDs for other TEMPer devices for the sample .rules file (above) from this repo.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrUninitializedTemper = errors.New("temper device is uninitialized")

ErrUninitializedTemper is returned when reading from a nil, zero-value, partially initialized, or closed Temper device.

Functions

This section is empty.

Types

type Temper

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

Temper represents a connection to a TEMPer USB thermometer device. It holds file descriptors for reading and writing to the HID device. Close must be called when the device is no longer needed to prevent file descriptor leaks.

func FindTempers added in v1.1.0

func FindTempers() ([]*Temper, error)

FindTempers returns a list of temper devices available in /dev.

Uses the recommended default timeout of 250ms. See FindTempersWithTimeout and FindTempersWithContext for more control.

func FindTempersWithContext added in v1.4.0

func FindTempersWithContext(ctx context.Context) ([]*Temper, error)

FindTempersWithContext scans /dev for temperXX devices (configured by udev), respecting the provided context for cancellation. Each candidate device is probed with a temperature read; if the read fails or the context is cancelled, the device is skipped and its file descriptors are closed.

func FindTempersWithTimeout added in v1.1.0

func FindTempersWithTimeout(timeout time.Duration) ([]*Temper, error)

FindTempersWithTimeout scans /dev for temperXX devices (configured by udev).

A timeout of 250ms is recommended but as YMMV, this function allows for an arbitrary timeout. Each candidate device is probed with a temperature read; devices that fail or time out are skipped.

func New

func New(descriptor string) (*Temper, error)

New opens a new Temper device at the given descriptor path. It is the caller's responsibility to call Close() to prevent a file descriptor leak.

func (*Temper) Close

func (t *Temper) Close() error

Close releases the file descriptors for the Temper device.

It is safe to call on a nil or partially initialized Temper.

func (*Temper) Descriptor added in v1.1.0

func (t *Temper) Descriptor() string

func (*Temper) ReadC

func (t *Temper) ReadC() (float32, error)

ReadC reads the internal sensor temperature in Celsius.

This is a convenience wrapper around ReadCWithContext using a background context. For cancellation or timeout support, use ReadCWithContext directly.

func (*Temper) ReadCWithContext added in v1.1.0

func (t *Temper) ReadCWithContext(ctx context.Context) (float32, error)

ReadCWithContext reads the internal sensor temperature in Celsius, respecting the provided context for cancellation/timeout.

The device I/O is genuine blocking I/O on a hidraw node; cancellation is implemented by driving the underlying file's read/write deadlines from the context, so an in-flight, unresponsive read is actually unblocked rather than abandoned. The device lock is held for the whole transaction, so reads are serialized and the descriptors are never touched concurrently.

func (*Temper) ReadF

func (t *Temper) ReadF() (float32, error)

ReadF reads the internal sensor temperature in Fahrenheit.

This is a convenience wrapper around ReadFWithContext using a background context. For cancellation or timeout support, use ReadFWithContext directly.

func (*Temper) ReadFWithContext added in v1.1.0

func (t *Temper) ReadFWithContext(ctx context.Context) (float32, error)

ReadFWithContext reads the internal sensor temperature in Fahrenheit, respecting the provided context for cancellation/timeout.

func (*Temper) String added in v1.1.0

func (t *Temper) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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