broadlinkgo

package module
Version: v0.0.0-...-f031acd Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2021 License: MIT Imports: 12 Imported by: 0

README

Broadlinkgo

Broadlink golang http server api

Overview

This api allows access to the Broadlink family of devices for IR/RM control via an http api. There is a web portal for basic management as well.

Image of Home

Getting Started

Start the program

broadlinkgo --port=8000 --cmdpath=./ 

Cmdpath is the location where a "commands" folder exists (it will be created if not present) this is where learned codes will be placed.

For linux/systemd systems a service file is included, the default command dir is "/etc/broadlinkgo" and the systemd unit file is looking for the binary in /usr/local/bin

The program will look for devices on the network and then once found start the server listening on the port. It will continually scan for devices so if more are added later they will be auto added without needing to re-start

Building from source

The program uses rice (https://github.com/GeertJohan/go.rice) to embed html

Once you have the rice tool build:

cd cmd
rice embed-go
go build -o broadlinkgo

This will package up everything into a binary "broadlinkgo". I've included a few popular build types binaries in releases.

Web Interface

This page gives overall status and ability to manage learned commands, the web interface is available on the host running the software at the port you started with (default port is 8000)

Adding Devices

Add the Broadlink devices to your network per the manufacturer instructions, once the broadlinkgo software is started it will find them on the network using a discovery process and make them available in the web interface.

Sometimes a network has issues doing self discover, there is a manual mode for that. Restart the software with the manual mode flag and you can add a device using the ip and mac address directly

broadlinkgo --port=8000 --cmdpath=./ --mode=manual

A button will appear on the interface allowing you to add a device manually skipping the discovery step. Special care should be taken to make sure you pick the correct device type to connect to when using this mode.

Learning

Learning is super simple, just go to /learn via the home page and you'll get prompted for what to do.

Image of Home

Api

After learning codes the commands to use the api are dead simple

Sending a command

GET /cmd/{name}

Sends a command using the name from learn, so if you did tv_on in learn then you would trigger it by using

GET /cmd/tv_on

Sending a command that repeats

GET /cmd/{name}:repeatn

For some buttons like volume, you will want to repeat them so you can use :N to repeat N times

GET /cmd/tv_volup:5

This will repeat the tv_volup command 5 times

Sending multiple commands as a macro

GET /macro/{name}:repeat/{name}:repeat

You may also want to turn up the volume and say change source, so do that with the macro end point

GET /macro/tv_power/tv_volup:5/tv_source/tv_source_hdmi1

There is also a magic "delay" command (1s) that will put in a delay for devices that can't handle the default 10ms break

GET /macro/tv_power/tv_volup:5/tv_source/delay/delay/tv_source_hdmi1

Add a 2 second delay in the macro

App Status

GET /status

Returns json for devices and commands that are configured

Sending a command to a specific device

You can send to a specific device by using the mac enumerated in the web page under devices

GET /device/{MAC}/cmd/....
GET /device/{MAC}/macro/....

For example, send tv_on to device 8f:47:4E:I9

GET /device/8f:47:4E:I9/cmd/tv_on

Removing a command

POST /remove/{name}

Removing the volup command for a vizio tv

POST /remove/vizio_volup

Sending command to a specifc device

Using the mac address listed in devices on the web portal you can send the above commands to a specific device

Credit

This builds upon the work of a few other projects most notably https://github.com/kwkoo/golang_broadlink_rm

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SortMapStringSlice

func SortMapStringSlice(m map[string][]string) map[string][]string

Types

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

Broadlink keeps a track of all the devices and sockets.

func NewBroadlink() Broadlink

NewBroadlink creates and initializes a new Broadlink struct.

func (*Broadlink) AddManualDevice

func (b *Broadlink) AddManualDevice(ip string, macs string, deviceType int) error

func (Broadlink) Count

func (b Broadlink) Count() int

Count returns the number of devices that were discovered.

func (Broadlink) DeviceExists

func (b Broadlink) DeviceExists(id string) bool

func (Broadlink) DeviceIds

func (b Broadlink) DeviceIds() map[string][]string

func (Broadlink) DeviceTypes

func (b Broadlink) DeviceTypes() map[int]string

func (*Broadlink) Discover

func (b *Broadlink) Discover() error

Discover will populate the Broadlink struct with a slice of Devices.

func (*Broadlink) Execute

func (b *Broadlink) Execute(id, s string) error

Execute looks at the device type and decides if it should call send() or setPowerState().

func (*Broadlink) GetPowerState

func (b *Broadlink) GetPowerState(id string) (bool, error)

GetPowerState queries a WiFi-enabled power outlet and returns its state (on or off).

func (*Broadlink) Learn

func (b *Broadlink) Learn(id string) (string, error)

Learn sends a learn command to the specified device. If id is an empty string it selects the first device.

func (*Broadlink) LearnRF

func (b *Broadlink) LearnRF(id string) (string, error)

LearnRF sends an RF Sweep command to the specified device. If id is an empty string it selects the first device.

func (*Broadlink) RemoveDevice

func (b *Broadlink) RemoveDevice(key string)

func (*Broadlink) WithTimeout

func (b *Broadlink) WithTimeout(t int) *Broadlink

WithTimeout sets the timeout for all subsequent read operations.

type Response

type Response struct {
	Type ResponseType
	Data []byte
}

Response represents a decrypted payload from the device.

type ResponseType

type ResponseType int

ResponseType denotes the type of payload.

const (
	Unknown ResponseType = iota
	AuthOK
	DeviceError
	Temperature
	CommandOK
	RawData
	RawRFData
	RawRFData2
)

Enumerations of PayloadType.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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