Skip to content

mixcode/broadlink

Repository files navigation

broadlink

A Go package to control BroadLink RM mini 3 "Black Bean" IR remote controller.

Disclaimer

I built this package just to control my own home appliances, and the RM mini 3 is the only device I have. For other devices, you can fork and implement yourselves. :p

Code Sample

Detect all reachable BroadLink devices

devs, err := broadlink.DiscoverDevices(100*time.Millisecond, 0)
fmt.Println(devs)
// d := devs[0]

Register and auth local machine to detected BroadLink device

myname := "my test server"  // Your local machine's name.
myid := make([]byte, 15)    // Must be 15 bytes long.
// Fill myid[] with some unique ID for your local machine.

err = d.Auth(myid, myname) // d.ID and d.AESKey will be updated on success.

Capture an IR Remote code

var rtype RemoteType
var ircode []byte

// Enter capturing mode.
err = d.StartCaptureRemoteControlCode()

// Point a remote controller toward the device and press a button to have some signal.

// Poll captured data. (Certainly you can do much better than this ;p)
ok := false
for i:=0; i<30; i++ {
	remotetype, ircode, err = d.ReadCapturedRemoteControlCode()
	if err == nil {
		ok = true
		break
	}
	if err != ErrNotCaptured {
		return err // real error
	}
	time.Sleep(time.Second)
	continue
}

if ok {
	// ircode now have captured data
}

Fire an IR code

err = d.SendIRRemoteCode(ircode, 1)	// 1 means once, 2 is twice, ...
// Note that sending IR signals may take a few hundred milliseconds. Set network timout accordingly.

Try to connect a New BroadLink device to local Wifi network

err = broadlink.SetupDeviceWifi("YOUR_WIFI_SSID", "YOUR_WIFI_PASSWORD", broadlink.WIFI_SECURITY_WPA_TKIP, nil)
// try to detect devices below
// devs, err := broadlink.DiscoverDevices(100*time.Millisecond, 0)

References

Note that references may have incorrect and inconsistent information.

About

A Go package to control BroadLink RM mini 3 IR controller.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages