Yet another tp-link HS100 library for golang
- 1.16
- 1.17
- 1.18
Please make sure to have go-modules enabled.
Run within your go project folder: go get -u github.com/jaedle/golang-tplink-hs100
use the following code as main and replace YOUR_HS100_DEVICE
with the
address of your HS100-device.
package main
import (
"github.com/jaedle/golang-tplink-hs100/pkg/configuration"
"github.com/jaedle/golang-tplink-hs100/pkg/hs100"
"os"
)
func main() {
h := hs100.NewHs100("YOUR_HS100_DEVICE", configuration.Default())
info, err := h.GetInfo()
if err != nil {
println("Error on accessing device")
os.Exit(1)
}
println("Name of device: " + info.Name)
}
It is possible to discover devices automatically.
Because this library uses tcp communication this requires to specify a subnet by CIDR notation.
For this example 192.168.2.0/24
all ips from 192.168.2.1
to 192.168.2.255
will be tried to reached.
By using withTimeout(time.Duration)
a custom timeout can be specified instead of the default timeout.
The discovery process will take at least the time of the default timeout.
package main
import (
"github.com/jaedle/golang-tplink-hs100/pkg/configuration"
"github.com/jaedle/golang-tplink-hs100/pkg/hs100"
"log"
"time"
)
func main() {
devices, err := hs100.Discover("192.168.2.0/24",
configuration.Default().WithTimeout(time.Second),
)
if err != nil {
panic(err)
}
log.Printf("Found devices: %d", len(devices))
for _, d := range devices {
info, _ := d.GetInfo()
log.Printf("Found device (name, id): %s, %s", info.Name, info.DeviceId)
}
}
-
tplink-smarthome-api: Thanks for the inspiration!
-
tplink-smarthome-crypto Thanks for the excellent documentation/test-cases for encrypting/decrypting the communication
-
tplink-smarthome-simulator Thanks for providing a device simulator for integration tests!
-
hs1xxplug: Thanks for the blueprint in golang!
- go-task
- docker
This project tries to stick as close as possible to the golang standard project layout
The public parts for this library are located in /pkg
.
All files in /cmd
are for demo purposes only.