bcevent

package
v0.2.14 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0 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.

Documentation

Overview

Package bcevent interprets the cloud event reports a battery camera emits (bcudp cf31 packets) as motion, recording and status. A sniffer sitting on the camera's path to its cloud server can decode these in real time, which gives a near-instant local motion signal — the camera sends event 3 the moment it wakes on motion, long before an FTP upload or an SD recording is finished — without the camera's cloud account or any change to the camera.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Battery

type Battery struct {
	Current     int `json:"bc"`
	Millivolts  int `json:"bv"`
	TempC       int `json:"tm"`
	ChargeState int `json:"cs"`
	Low         int `json:"low"`
	Pct         int `json:"pct"`
}

Battery is the battery sub-object of a status report. Current is milliamps, negative while discharging; Millivolts is the pack voltage; TempC is the pack temperature in Celsius; Pct is the state of charge.

type Kind

type Kind string

Kind is the sort of report an event number names.

const (
	Motion       Kind = "motion"        // event 3: the camera woke on motion
	RecordingEnd Kind = "recording_end" // event 4: a clip finished (carries duration)
	Status       Kind = "status"        // event 12: battery, power, wifi, time
	Codec        Kind = "codec"         // event 8: stream parameters
	Firmware     Kind = "firmware"      // event 0: firmware/summary
	Unknown      Kind = "unknown"
)

type Packet

type Packet struct {
	Src, Dst netip.AddrPort
	Event    bcudp.Event
}

Packet is one captured, decoded cloud event with the UDP endpoints it was sent between.

type Report

type Report struct {
	Event int             `json:"event"`
	Kind  Kind            `json:"-"`
	Raw   json.RawMessage `json:"-"`

	// RecordingEnd (event 4).
	DurationMS    int `json:"duration"`
	TotalDuration int `json:"totalduration"`
	Reason        int `json:"reason"`

	// Status (event 12).
	HostPwr  int      `json:"hostpwr"`
	Battery  *Battery `json:"bat"`
	WifiRSSI int      `json:"wifi_rssi"`
	Time     int64    `json:"time"`
}

Report is a decoded event. Fields outside the one that matched Kind are left at their zero value; Raw holds the original JSON for anything not modeled here.

func Parse

func Parse(body []byte) (Report, error)

Parse decodes one event body (the JSON from a bcudp.Event) and classifies it. The body is kept verbatim in Raw.

func (Report) Awake

func (r Report) Awake() bool

Awake reports whether a status event shows the camera's main SoC powered (recording or otherwise busy) rather than back in low-power sleep.

type Sniffer

type Sniffer struct {
	// Iface is the interface to capture on, e.g. "enp1s0" or "br-lan".
	Iface string
	// Promisc puts the interface in promiscuous mode. Needed when the
	// camera's frames are bridged past (not addressed to) this host, which
	// is the usual case on a router or bridge. Default when zero value is
	// used via NewSniffer.
	Promisc bool
	// NoFilter skips the kernel BPF and filters in userspace instead. For
	// diagnostics only; the kernel filter is far cheaper on a busy link.
	NoFilter bool
	// Debug logs a count of raw frames seen, to tell "no packets arrive"
	// from "packets arrive but do not decode".
	Debug bool
}

Sniffer passively reads a battery camera's cloud event reports off a network interface. It must run where the camera's traffic to its cloud server is visible — the gateway or bridge the camera sits behind, or a mirror of that port — and needs CAP_NET_RAW (typically root). It never transmits and never touches the camera.

func (*Sniffer) Run

func (s *Sniffer) Run(ctx context.Context, fn func(Packet)) error

Run captures until ctx is canceled, calling fn for every valid cf31 event. fn runs on the capture goroutine, so it must not block for long; hand work to a channel if it might.

Jump to

Keyboard shortcuts

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