arlo

package module
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: MIT Imports: 34 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

go-arlo

A Go client for Arlo's cloud API: log in (with email two-factor and trusted browser pairing), follow the event stream, and read and set the location mode. The protocol was observed on Arlo's servers and cross-checked against pyaarlo 0.8.0.23.

Scope is deliberately small: device connectivity, battery, motion, the location's alarm mode, the recordings library, the cameras' latest pictures, snapshots on demand, live stream URLs and turning cameras on or off. Tested with a VMB4000 base station and Arlo Pro 2 cameras on an account using location (V3) modes, from a granted-access account.

Library

c := arlo.New(arlo.Config{
	Email:       email,
	Password:    password,
	SessionPath: "/var/lib/app/arlo-session.json",
	Code:        arlo.IMAPCode("imap.example.com:993", imapUser, imapPassword),
})

go func() {
	err := c.Run(ctx, func(e arlo.Event) {
		switch e := e.(type) {
		case arlo.Connection:  // event stream up or down
		case arlo.Devices:     // base stations and cameras, on each connection
		case arlo.DeviceState: // connected, battery and/or on of one device
		case arlo.Motion:      // motion started or stopped on a camera
		case arlo.ModeChanged: // the location's mode
		case arlo.SnapshotReady: // a camera's new snapshot, whoever asked
		case arlo.RecordingAdded: // a new recording in the library, with its URLs
		}
	})
	// err: ctx ended, or a failure retrying cannot fix
}()

err := c.SetMode(ctx, arlo.ArmHome) // waits for Run's connection; arlo.ErrNotRunning without Run
rs, err := c.Library(ctx, from, to) // recordings of these days, with presigned URLs
err := c.Snapshot(ctx, cameraID)    // SnapshotReady follows within seconds; wakes the camera
u, err := c.Stream(ctx, cameraID)   // rtsps:// URL; read it within ~30 s, skipping TLS verification
li, err := c.LastImages(ctx, cameraID) // latest picture and snapshot URLs, without waking the camera
err := c.SetCameraOn(ctx, cameraID, false) // DeviceState with On follows; off, the camera does nothing

Run blocks. It logs in, connects to Arlo's MQTT broker, pings the base stations every minute, asks them for their devices' state every ten minutes, renews the two-hour token before it expires, and reconnects with a backoff. The handler is called from Run's goroutine, one event at a time. Commands (SetMode, Library, …) execute on that same goroutine once Run is connected: they wait through reconnections, so bound them with ctx, as Run may be in a backoff of up to an hour. They return arlo.ErrNotRunning when Run is not running or stops meanwhile. A second Run of the same client returns arlo.ErrAlreadyRunning.

arlo.Login(ctx, cfg) logs in once and saves the session, to get through the first email two-factor ahead of Run. Never alongside a Run on the same session file.

Things Arlo imposes

  • Auth attempts are rate limited with a long cooldown. A login never retries, reuses the saved token while it is valid, and Run waits at least a minute (an hour after a refused auth) between attempts.
  • Two-factor is by email until the client is a trusted browser. The first login needs a code (Config.Code: IMAPCode, or anything returning the code); later ones do not.
  • One owner per session file. Every trusted login rotates the browser_trust cookie and voids the previous one: a copied session file, or one shared by two hosts, falls back to email two-factor.
  • Concurrent sessions of one account are tolerated: several processes and MQTT connections, and new logins, do not disconnect each other.

docs/NOTES.md records what Arlo actually sends, as observed.

CLI

nix develop   # Go toolchain
go build ./cmd/arlo
arlo login -email … -password-file … [-imap-user … -imap-password-file …]
arlo watch  (same flags)   # print events
arlo mode   (same flags) [standby|armHome|armAway]
arlo library (same flags) [-days 7] [-urls]
arlo snapshot (same flags) <camera id>
arlo stream (same flags) [-play mpv] <camera id>
arlo lastimage (same flags) [-o newest.jpg] <camera id>

Without -imap-user the code is typed on stdin. Responses and MQTT messages are dumped, secrets redacted, to -dump (default debug/, empty to disable): debug from the dumps rather than by spending auth attempts.

Acknowledgements

pyaarlo, by Steve Herrell (twrecked), maps much of Arlo's undocumented protocol; go-arlo cross-checked its own observations against it. go-arlo contains no pyaarlo code.

License

MIT, see LICENSE.

Documentation

Overview

Package arlo is a client for Arlo's cloud API.

Index

Constants

This section is empty.

Variables

View Source
var ErrAlreadyRunning = errors.New("arlo: Run already running")

ErrAlreadyRunning is Run's error while another Run of the same Client is going.

View Source
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

func Login(ctx context.Context, cfg Config) error

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 New

func New(cfg Config) *Client

New returns a client. It does not touch the network: see Run.

func (*Client) LastImages added in v0.4.0

func (c *Client) LastImages(ctx context.Context, cameraID string) (LastImages, error)

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

func (c *Client) Library(ctx context.Context, from, to time.Time) ([]Recording, error)

Library lists the recordings of the days from to to, as Arlo orders them. It waits for Run's connection.

func (*Client) Run

func (c *Client) Run(ctx context.Context, handle func(Event)) error

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

func (c *Client) SetCameraOn(ctx context.Context, cameraID string, on bool) error

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

func (c *Client) SetMode(ctx context.Context, mode Mode) error

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

func (c *Client) Snapshot(ctx context.Context, cameraID string) error

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

func (c *Client) Stream(ctx context.Context, cameraID string) (string, error)

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

type CodeFunc func(ctx context.Context, since time.Time) (string, error)

CodeFunc returns the 6-digit code Arlo emails for two-factor authentication. since is when the code was requested.

func IMAPCode

func IMAPCode(addr, user, password string) CodeFunc

IMAPCode returns a CodeFunc that waits for Arlo's code email in the INBOX of an IMAPS mailbox (addr is host:port). Bound the wait with ctx.

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".

const (
	Standby Mode = "standby"
	ArmHome Mode = "armHome"
	ArmAway Mode = "armAway"
)

type ModeChanged

type ModeChanged struct {
	LocationID   string
	LocationName string
	Mode         Mode
}

ModeChanged reports a location's mode, on connection and on every change.

type Motion

type Motion struct {
	ID     string
	Active bool
}

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

type SnapshotReady struct {
	ID  string
	URL string
}

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.

Directories

Path Synopsis
cmd
arlo command
Command arlo exercises the go-arlo library by hand.
Command arlo exercises the go-arlo library by hand.

Jump to

Keyboard shortcuts

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