golang-tplink-hs100

module
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2021 License: MIT

README

Yet another tp-link HS100 library for golang. Forked from jaedle/golang-tplink-hs100

Usage

With a project using go modules

install library go get github.com/shauncampbell/golang-tplink-hs100

Without using go modules

install library go get github.com/shauncampbell/golang-tplink-hs100/...

Usage example

use the following code as main and replace YOUR_HS100_DEVICE with the address of your HS100-device.

package main

import (
	"github.com/shauncampbell/golang-tplink-hs100/pkg/configuration"
	"github.com/shauncampbell/golang-tplink-hs100/pkg/hs100"
	"os"
)

func main() {
	h := hs100.NewHs100("YOUR_HS100_DEVICE", configuration.Default())

	name, err := h.GetName()
	if err != nil {
		println("Error on accessing device")
		os.Exit(1)
	}

	println("Name of device: " + name)
}

Device discovery

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/shauncampbell/golang-tplink-hs100/pkg/configuration"
	"github.com/shauncampbell/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 {
		name, _ := d.GetName()
		log.Printf("Device name: %s", name)
	}
}

Acknowledgements

Development

Prerequisites
  1. go-task
  2. docker

Project structure

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.

License

MIT

Directories

Path Synopsis
cmd
internal
connector
Package connector provides utilities for connecting and interfacing with an hs1xx device.
Package connector provides utilities for connecting and interfacing with an hs1xx device.
pkg
hs100
Package hs100 is a public facing package for communicating with hs1xx devices.
Package hs100 is a public facing package for communicating with hs1xx devices.

Jump to

Keyboard shortcuts

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