mirror of
https://github.com/nikdoof/hapz2m.git
synced 2026-01-30 00:58:22 +00:00
Add config options for ListenAddr & Interfaces
These options are helpful when the bridge is running on a multi-homed device like a wireless router.
This commit is contained in:
19
README.md
19
README.md
@@ -28,6 +28,25 @@ To compile `hap-z2m`, use:
|
|||||||
|
|
||||||
go build -v -trimpath -ldflags="-s -w" ./cmd/...
|
go build -v -trimpath -ldflags="-s -w" ./cmd/...
|
||||||
|
|
||||||
|
Configuration
|
||||||
|
==============
|
||||||
|
|
||||||
|
The MQTT broker that Zigbee2MQTT connects to is specified using the following:
|
||||||
|
|
||||||
|
- Server
|
||||||
|
- Username
|
||||||
|
- Password
|
||||||
|
|
||||||
|
Additionally, these options control networking aspects for the bridge:
|
||||||
|
|
||||||
|
- `ListenAddr` can be used to bind to a specific port and/or address,
|
||||||
|
useful for selecting a fixed port for firewall rules.
|
||||||
|
|
||||||
|
- `Interfaces` limit which interfaces mDNS broadcasts appear on,
|
||||||
|
and which addresses to use when broadcasting.
|
||||||
|
|
||||||
|
These settings are optional and can be left blank.
|
||||||
|
|
||||||
License
|
License
|
||||||
========
|
========
|
||||||
|
|
||||||
|
|||||||
@@ -51,6 +51,10 @@ type Bridge struct {
|
|||||||
Username string
|
Username string
|
||||||
Password string
|
Password string
|
||||||
|
|
||||||
|
// address and interfaces to bind to
|
||||||
|
ListenAddr string
|
||||||
|
Interfaces []string
|
||||||
|
|
||||||
DebugMode bool
|
DebugMode bool
|
||||||
|
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
@@ -118,6 +122,9 @@ func (br *Bridge) StartHAP() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
br.server.Addr = br.ListenAddr
|
||||||
|
br.server.Ifaces = br.Interfaces
|
||||||
|
|
||||||
if br.DebugMode {
|
if br.DebugMode {
|
||||||
haplog.Debug.Enable()
|
haplog.Debug.Enable()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
@@ -29,7 +30,11 @@ var (
|
|||||||
debugMode = flag.Bool("debug", false, "enable debug messages")
|
debugMode = flag.Bool("debug", false, "enable debug messages")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// config struct
|
||||||
type config struct {
|
type config struct {
|
||||||
|
ListenAddr string
|
||||||
|
Interfaces []string
|
||||||
|
|
||||||
Server, Username, Password string
|
Server, Username, Password string
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,6 +78,17 @@ func main() {
|
|||||||
br.Password = cfg.Password
|
br.Password = cfg.Password
|
||||||
br.DebugMode = *debugMode
|
br.DebugMode = *debugMode
|
||||||
|
|
||||||
|
// validate ListenAddr if specified
|
||||||
|
if cfg.ListenAddr != "" {
|
||||||
|
_, _, err := net.SplitHostPort(cfg.ListenAddr)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("invalid ListenAddr: %v", err)
|
||||||
|
}
|
||||||
|
br.ListenAddr = cfg.ListenAddr
|
||||||
|
}
|
||||||
|
|
||||||
|
br.Interfaces = cfg.Interfaces
|
||||||
|
|
||||||
err = br.ConnectMQTT()
|
err = br.ConnectMQTT()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("cannot connect to MQTT: %s", err)
|
log.Printf("cannot connect to MQTT: %s", err)
|
||||||
|
|||||||
@@ -1,4 +1,12 @@
|
|||||||
{
|
{
|
||||||
|
// specify a host:port to listen on
|
||||||
|
// if not specified, a random port will be used
|
||||||
|
//"ListenAddr": ":8585",
|
||||||
|
|
||||||
|
// limit interfaces to use for DNS-SD (mDNS)
|
||||||
|
// leave blank for all interfaces
|
||||||
|
//"Interfaces": ["eth0", "eth1"],
|
||||||
|
|
||||||
// MQTT server credentials
|
// MQTT server credentials
|
||||||
"Server": "tcp://localhost:1883",
|
"Server": "tcp://localhost:1883",
|
||||||
"Username": "hapz2m",
|
"Username": "hapz2m",
|
||||||
|
|||||||
Reference in New Issue
Block a user