Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pkg/hap/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ const (

const DeviceAID = 1 // TODO: fix someday

// DefaultPIN is the HomeKit pairing PIN used when none is configured.
const DefaultPIN = "19550224"

type JSONAccessories struct {
Value []*Accessory `json:"accessories"`
}
Expand Down
16 changes: 8 additions & 8 deletions pkg/hksv/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func main() {

srv, err := hksv.NewServer(hksv.Config{
StreamName: "my-camera",
Pin: "27041991",
Pin: "19550224",
HKSV: true,
MotionMode: "detect",
Streams: &myStreamProvider{},
Expand Down Expand Up @@ -105,7 +105,7 @@ func main() {
```go
srv, err := hksv.NewServer(hksv.Config{
StreamName: "my-camera",
Pin: "27041991",
Pin: "19550224",
HKSV: true,
MotionMode: "detect",

Expand All @@ -124,7 +124,7 @@ srv, err := hksv.NewServer(hksv.Config{
```go
srv, err := hksv.NewServer(hksv.Config{
StreamName: "basic-cam",
Pin: "27041991",
Pin: "19550224",
HKSV: false, // no HKSV recording

Streams: &myStreamProvider{},
Expand All @@ -139,7 +139,7 @@ srv, err := hksv.NewServer(hksv.Config{
```go
srv, err := hksv.NewServer(hksv.Config{
StreamName: "proxied-cam",
Pin: "27041991",
Pin: "19550224",
ProxyURL: "homekit://192.168.1.100:51827?device_id=AA:BB:CC:DD:EE:FF&...",

Logger: logger,
Expand All @@ -152,7 +152,7 @@ srv, err := hksv.NewServer(hksv.Config{
```go
srv, err := hksv.NewServer(hksv.Config{
StreamName: "my-doorbell",
Pin: "27041991",
Pin: "19550224",
CategoryID: "doorbell", // creates doorbell accessory
HKSV: true,
MotionMode: "detect",
Expand Down Expand Up @@ -376,7 +376,7 @@ func (h *srtpLiveStreamHandler) StopStream(sessionID string, ct hksv.ConnTracker
type Config struct {
// Required
StreamName string // stream identifier (used for lookups)
Pin string // HomeKit pairing PIN, e.g. "27041991" (default)
Pin string // HomeKit pairing PIN, e.g. "19550224" (default)
Port uint16 // HAP HTTP port
Logger zerolog.Logger // structured logger
Streams StreamProvider // stream registry (required for HKSV/live/motion)
Expand Down Expand Up @@ -562,7 +562,7 @@ var entries []*mdns.ServiceEntry
for _, name := range cameras {
srv, _ := hksv.NewServer(hksv.Config{
StreamName: name,
Pin: "27041991",
Pin: "19550224",
HKSV: true,
MotionMode: "detect",
Streams: provider,
Expand Down Expand Up @@ -637,7 +637,7 @@ go build -o hksv-camera ./pkg/hksv/example
| Flag | Default | Description |
|------|---------|-------------|
| `-url` | (required) | RTSP stream URL |
| `-pin` | `27041991` | HomeKit pairing PIN |
| `-pin` | `19550224` | HomeKit pairing PIN |
| `-port` | `0` (auto) | HAP HTTP port |
| `-motion` | `detect` | Motion mode: `detect`, `continuous`, `api` |
| `-threshold` | `2.0` | Motion sensitivity (lower = more sensitive) |
Expand Down
4 changes: 2 additions & 2 deletions pkg/hksv/example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// go run ./pkg/hksv/example -url rtsp://admin:pass@192.168.1.100:554/h264
//
// Then open the Home app on your iPhone/iPad, tap "+" → "Add Accessory",
// and scan the QR code or enter the PIN manually (default: 270-41-991).
// and scan the QR code or enter the PIN manually (default: 1955-0224).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iOS has been using XXXX-XXXX for a while now, so I figured it's a good occasion to update it

package main

import (
Expand All @@ -33,7 +33,7 @@ import (

func main() {
streamURL := flag.String("url", "", "RTSP stream URL (required)")
pin := flag.String("pin", "27041991", "HomeKit pairing PIN")
pin := flag.String("pin", hap.DefaultPIN, "HomeKit pairing PIN")
port := flag.Int("port", 0, "HAP HTTP port (0 = auto)")
motion := flag.String("motion", "detect", "Motion mode: detect, continuous, api")
threshold := flag.Float64("threshold", 2.0, "Motion detection threshold (lower = more sensitive)")
Expand Down
6 changes: 3 additions & 3 deletions pkg/hksv/hksv.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//
// srv, err := hksv.NewServer(hksv.Config{
// StreamName: "camera1",
// Pin: "27041991",
// Pin: "19550224",
// HKSV: true,
// MotionMode: "detect",
// Streams: myStreamProvider,
Expand Down Expand Up @@ -91,7 +91,7 @@ type ConnTracker interface {
// Config for creating an HKSV server.
type Config struct {
StreamName string
Pin string // HomeKit pairing PIN (e.g., "27041991")
Pin string // HomeKit pairing PIN (e.g., "19550224")
Name string // mDNS display name (auto-generated if empty)
DeviceID string // MAC-like device ID (auto-generated if empty)
DevicePrivate string // ed25519 private key hex (auto-generated if empty)
Expand Down Expand Up @@ -150,7 +150,7 @@ type Server struct {
// NewServer creates a new HKSV server with the given configuration.
func NewServer(cfg Config) (*Server, error) {
if cfg.Pin == "" {
cfg.Pin = "27041991"
cfg.Pin = hap.DefaultPIN
}

pin, err := hap.SanitizePin(cfg.Pin)
Expand Down
7 changes: 7 additions & 0 deletions pkg/hksv/hksv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,13 @@ func TestNewServer_DefaultPin(t *testing.T) {
})
require.NoError(t, err)
require.NotNil(t, srv)

data, err := srv.MarshalJSON()
require.NoError(t, err)

var v map[string]any
require.NoError(t, json.Unmarshal(data, &v))
require.Equal(t, "195-50-224", v["setup_code"])
}

func TestNewServer_InvalidPin(t *testing.T) {
Expand Down