Documentation
¶
Overview ¶
Package discover finds Shelly devices on a network in three ways, each confirmed with the device's GET /shelly:
- DNS-SD: Gen2+ devices announce _shelly._tcp (with gen, app and ver in TXT) and _http._tcp; Gen1 devices announce _http._tcp with an instance name starting with "shelly". MDNS browses both through the application's mDNS browser (a Browser), so this package needs no mDNS code of its own; github.com/cB-Sigma/mdns is one browser (see the README for the five lines that connect it).
- CoIoT: Gen1 devices multicast their status every few seconds; FromCoIoT turns a message received with shelly.ListenCoIoT into a candidate.
- A scan: Scan asks every address of a prefix for GET /shelly, for networks where multicast does not reach.
It is a separate package so the shelly package stays small; it uses only the standard library and the shelly package.
Index ¶
- Constants
- func ListenCoIoT(ctx context.Context, l *shelly.CoIoTListener, o Options, found func(Device)) error
- type Browser
- type Device
- func FromCoIoT(m shelly.CoIoTMessage, from *net.UDPAddr) (Device, bool)
- func FromService(s Service) (Device, bool)
- func MDNS(ctx context.Context, b Browser, o Options) ([]Device, error)
- func Probe(ctx context.Context, hc *http.Client, addr string) (Device, error)
- func Scan(ctx context.Context, prefix netip.Prefix, o Options) ([]Device, error)
- type Options
- type Service
Constants ¶
const ( ServiceShelly = "_shelly._tcp" // Gen2 and later ServiceHTTP = "_http._tcp" // every generation )
Service types Shelly devices announce.
Variables ¶
This section is empty.
Functions ¶
func ListenCoIoT ¶
ListenCoIoT reads CoIoT messages from l until ctx ends and calls found once per device (by id), confirmed with GET /shelly unless o.NoProbe.
Types ¶
type Browser ¶
Browser browses one DNS-SD service type ("_shelly._tcp") on the local link and returns what answered.
type Device ¶
type Device struct {
// Addr is host:port of its HTTP API.
Addr string
// ID is the Gen2+ id or, for Gen1, shelly<type>-<MAC> as announced
// (or the MAC alone when only CoIoT saw it).
ID string
// Gen is the generation (1, 2, 3, 4); 0 while unknown.
Gen int
// Model is the model or Gen1 type when known; App is the Gen2+
// application name; Ver the firmware.
Model, App, Ver string
// Via says how it was found: mdns, coiot or scan.
Via string
// Info is GET /shelly's answer when it was read.
Info *shelly.Info
}
Device is a Shelly device found on the network.
func FromCoIoT ¶
FromCoIoT turns a CoIoT message from a Gen1 device into a candidate at the sender's address, port 80.
func FromService ¶
FromService turns a DNS-SD answer into a candidate; ok is false when it is not a Shelly device.
func MDNS ¶
MDNS browses _shelly._tcp and _http._tcp with b and returns the Shelly devices, one per address, confirmed with GET /shelly unless o.NoProbe. Devices that answer neither are left out.
type Options ¶
type Options struct {
// HTTP is used for GET /shelly; a 3 s timeout client when nil.
HTTP *http.Client
// NoProbe returns DNS-SD candidates without reading GET /shelly.
NoProbe bool
// Workers bounds concurrent probes (16 when 0).
Workers int
// Port is the port Scan probes (80 when 0).
Port int
}
Options configure MDNS and Scan.