Simple, idiomatic and working API to access a TP-Link HS100 or HS110 smartplug.
The focus is on presenting the minimum code needed to query the smartplug. There are about 50 calls documented to control the device. Only a handful of calls are implemented here although extending it should be fairly trivial.
Here's a minimal program to retrieve Power and Current metrics.
package main
import (
"fmt"
"github.com/gittycat/smartplug"
)
func main() {
p := smartplug.NewSmartplug("192.168.1.9", "9999") // ip, port
info, err := p.Meter()
if err != nil {
panic(err)
}
fmt.Printf("Power: %d mW Current: %d mA\n", info.PowerMw, info.CurrentMa)
}
The included example/example.go
program shows how to retrieve the metrics at intervals.
The encryption and decryption is based on the python code from SoftsCheck
This API is possible due to the reverse engineering work done by Lubomir Stroetmann and Tobias Esser at SoftsCheck. https://www.softscheck.com/en/reverse-engineering-tp-link-hs110/
They also include a command line python app to query and control the device.