Documentation
¶
Overview ¶
Package arlo is a client for Arlo's cloud API.
Index ¶
- Variables
- func Login(ctx context.Context, cfg Config) error
- type Client
- func (c *Client) LastImages(ctx context.Context, cameraID string) (LastImages, error)
- func (c *Client) Library(ctx context.Context, from, to time.Time) ([]Recording, error)
- func (c *Client) Run(ctx context.Context, handle func(Event)) error
- func (c *Client) SetCameraOn(ctx context.Context, cameraID string, on bool) error
- func (c *Client) SetMode(ctx context.Context, mode Mode) error
- func (c *Client) Snapshot(ctx context.Context, cameraID string) error
- func (c *Client) Stream(ctx context.Context, cameraID string) (string, error)
- type CodeFunc
- type Config
- type Connection
- type Device
- type DeviceState
- type Devices
- type Event
- type LastImages
- type Mode
- type ModeChanged
- type Motion
- type Recording
- type RecordingAdded
- type SnapshotReady
Constants ¶
This section is empty.
Variables ¶
var ErrAlreadyRunning = errors.New("arlo: Run already running")
ErrAlreadyRunning is Run's error while another Run of the same Client is going.
var ErrNotRunning = errors.New("arlo: Run not running")
ErrNotRunning is a command's error when Run has returned and not been called again, or returns while the command waits for its connection.
Functions ¶
func Login ¶ added in v0.3.0
Login opens a Session once and saves it, then returns: to set it up ahead of Run, for instance through the first email two-factor. Never run it while a Client's Run uses the same SessionPath: each authentication rotates the trust cookie, and the loser's copy costs a new two-factor.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client talks to Arlo on behalf of one account.
func (*Client) LastImages ¶ added in v0.4.0
LastImages returns a camera's latest pictures from memory, without a request: Run keeps them from the device list it reads on every connection and token renewal, less than two hours apart, and from SnapshotReady. It waits for Run's connection.
func (*Client) Library ¶ added in v0.4.0
Library lists the recordings of the days from to to, as Arlo orders them. It waits for Run's connection.
func (*Client) Run ¶
Run follows Arlo's event stream until ctx ends, logging in, renewing the token and reconnecting as needed, with a backoff that spares Arlo's auth rate limit. handle is called from Run's goroutine, one event at a time. Run returns ctx's error, or an error retrying cannot fix.
func (*Client) SetCameraOn ¶ added in v0.6.0
SetCameraOn turns a camera on or off; off, it neither detects, records nor streams. The camera reports the change as a DeviceState. It waits for Run's connection.
func (*Client) SetMode ¶
SetMode sets the mode of the account's location, once Run is connected, and reports the new mode as a ModeChanged event.
func (*Client) Snapshot ¶ added in v0.4.0
Snapshot asks a camera for a full-frame snapshot, reported as SnapshotReady some seconds later. It wakes the camera, so it costs battery. It waits for Run's connection.
func (*Client) Stream ¶ added in v0.4.0
Stream starts a camera's live stream and returns its RTSPS URL. Called while the stream runs, it returns a new URL to the same stream; both can be read at once. Arlo sets no time limit and stops the stream when nothing reads it. It wakes the camera, so it costs battery. It waits for Run's connection.
type CodeFunc ¶
CodeFunc returns the 6-digit code Arlo emails for two-factor authentication. since is when the code was requested.
type Config ¶
type Config struct {
Email string
Password string
// SessionPath is the file holding the session between runs: it spares
// the two-factor step, so it must survive restarts.
SessionPath string
// Code supplies the two-factor code. Only needed until the client is a
// trusted browser.
Code CodeFunc
// DumpDir, when set, receives every HTTP response and MQTT message with
// secrets redacted, to debug without spending auth attempts.
DumpDir string
Log *slog.Logger
}
Config configures a Client.
type Connection ¶
type Connection struct{ Up bool }
Connection reports whether the client follows Arlo's event stream. The token renewal every two hours does not show: only real outages do.
type Device ¶
type Device struct {
ID string // serial number
Name string
Model string
Type string // "basestation" or "camera"
BaseID string // parent base station; empty for a base station
}
Device is a base station or a camera of the account.
type DeviceState ¶
type DeviceState struct {
ID string
Connected *bool
Battery *int // percent
On *bool // a camera's; false while turned off
}
DeviceState is what Arlo reports about a device; nil fields were not part of the report.
type Devices ¶
type Devices []Device
Devices lists the account's devices. Run reports it on every connection.
type Event ¶
type Event interface {
// contains filtered or unexported methods
}
Event is what Run reports. DeviceState, Motion and ModeChanged report states, which may repeat: a base station sends its packets once per client subscribed to it, such as an open Arlo app of any account sharing it.
type LastImages ¶ added in v0.4.0
type LastImages struct {
Image string // 640×357, uploaded after each recording or stream
Snapshot string // 1920×1072, the latest full-frame snapshot, whoever asked
}
LastImages are a camera's latest pictures, read without waking it. Each is a presigned JPEG URL, valid 24 hours; the Last-Modified header of its GET dates the picture.
type Mode ¶
type Mode string
Mode is a location's alarm mode. An active custom mode is reported as Arlo names it, "custom".
type ModeChanged ¶
ModeChanged reports a location's mode, on connection and on every change.
type Motion ¶
Motion reports whether a camera sees motion: on connection, then as it starts or stops.
type Recording ¶ added in v0.4.0
type Recording struct {
CameraID string
Created time.Time
Duration time.Duration
ContentType string // "video/mp4" or "image/jpg"
Reason string // what triggered it, as Arlo names it
Object string // what the camera saw: "person", "vehicle", …; often empty
URL string
ThumbnailURL string
}
Recording is an entry of the account's media library: a video, or a snapshot. Its URLs are presigned: a plain GET fetches them, for a while.
type RecordingAdded ¶ added in v0.5.0
type RecordingAdded struct{ Recording }
RecordingAdded reports a new recording in the library once its upload ends, its URLs readable at once. Arlo's notice holds less than Library: Duration, Reason and Object are unknown, and Created and ContentType come from the URL's object name. Arlo was seen to announce each recording once; CameraID and Created identify it should one repeat. Recordings made while Run is disconnected are not announced: Library has them.
type SnapshotReady ¶ added in v0.4.0
SnapshotReady reports a camera's new full-frame snapshot, whoever asked for it. URL is a presigned JPEG: a plain GET fetches it, for a while.