Simple MJPEG streamer for ESPHome cameras.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

51 lines
930 B

package main
import (
"time"
"maze.io/x/esphome"
)
const (
DefaultConfigPath = "/etc/esphome"
clientTimeout = 5 * time.Second
)
type Device struct {
Name string
Addr string
Version string
Info esphome.DeviceInfo
Camera *Camera
Last time.Time
client *esphome.Client
secret string
connecting uint32
}
func NewDevice(name, addr string) *Device {
return &Device{
Name: name,
Addr: addr,
}
}
func (d *Device) Connect(secret string, timeout time.Duration) error {
var err error
if d.client, err = esphome.DialTimeout(d.Addr, timeout); err != nil {
return err
}
d.client.Timeout = timeout
if err = d.client.Login(secret); err != nil {
return err
}
if d.Info, err = d.client.DeviceInfo(); err != nil {
return err
}
return nil
}
// IsAvailable checks if the device has an active connection.
func (d *Device) IsAvailable() bool {
return d.client != nil
}