feat: add dynamic config reload, unique device identity (UUID), and MQTT support
- New StreamManager for dynamic RTSP/FLV stream lifecycle - Dynamic worker scaling for inference - Device UUID generation and persistence - Telegraf config and NPU monitoring scripts - .gitignore for build artifacts
This commit is contained in:
@@ -1,14 +1,21 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
DeviceUUID string `yaml:"device_uuid"`
|
||||
EdgeID string `yaml:"edge_id"`
|
||||
CloudURL string `yaml:"cloud_url"`
|
||||
MqttBroker string `yaml:"mqtt_broker"`
|
||||
MqttUser string `yaml:"mqtt_user"`
|
||||
MqttPass string `yaml:"mqtt_pass"`
|
||||
EdgeToken string `yaml:"edge_token"`
|
||||
RTSPURLs []string `yaml:"rtsp_urls"`
|
||||
InferSocket string `yaml:"infer_socket"`
|
||||
@@ -16,12 +23,14 @@ type Config struct {
|
||||
InferWorkers int `yaml:"infer_workers"`
|
||||
ConfThreshold float64 `yaml:"conf_threshold"`
|
||||
DedupWindowSec int `yaml:"dedup_window_sec"`
|
||||
OTAUrl string `yaml:"ota_url"`
|
||||
Version string `yaml:"version"`
|
||||
configPath string `json:"-"`
|
||||
}
|
||||
|
||||
func Load(path string) *Config {
|
||||
cfg := &Config{
|
||||
EdgeID: "edge-demo-001",
|
||||
EdgeID: "edge-unknown",
|
||||
CloudURL: "http://localhost:8004",
|
||||
InferSocket: "/tmp/edge-infer.sock",
|
||||
InferFPS: 5,
|
||||
@@ -29,12 +38,15 @@ func Load(path string) *Config {
|
||||
ConfThreshold: 0.5,
|
||||
DedupWindowSec: 30,
|
||||
Version: "1.0.0",
|
||||
configPath: path,
|
||||
}
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return cfg
|
||||
|
||||
cfg.loadUUID()
|
||||
|
||||
if data, err := os.ReadFile(path); err == nil {
|
||||
_ = yaml.Unmarshal(data, cfg)
|
||||
}
|
||||
_ = yaml.Unmarshal(data, cfg)
|
||||
|
||||
if cfg.InferWorkers <= 0 {
|
||||
cfg.InferWorkers = 1
|
||||
}
|
||||
@@ -43,3 +55,31 @@ func Load(path string) *Config {
|
||||
}
|
||||
return cfg
|
||||
}
|
||||
|
||||
func (c *Config) loadUUID() {
|
||||
uuidPath := "/opt/tianyan-edge/device.uuid"
|
||||
if data, err := os.ReadFile(uuidPath); err == nil {
|
||||
c.DeviceUUID = string(data)
|
||||
} else {
|
||||
b := make([]byte, 16)
|
||||
rand.Read(b)
|
||||
c.DeviceUUID = hex.EncodeToString(b)
|
||||
os.MkdirAll(filepath.Dir(uuidPath), 0755)
|
||||
os.WriteFile(uuidPath, []byte(c.DeviceUUID), 0644)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Config) Save() error {
|
||||
data, err := yaml.Marshal(c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return os.WriteFile(c.configPath, data, 0644)
|
||||
}
|
||||
|
||||
func (c *Config) GetDeviceIdentity() string {
|
||||
if c.DeviceUUID != "" {
|
||||
return c.DeviceUUID
|
||||
}
|
||||
return c.EdgeID
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user