feat: add yutong mqtt ingestion
This commit is contained in:
@@ -68,6 +68,28 @@ func main() {
|
||||
}
|
||||
}()
|
||||
}
|
||||
if envBool("YUTONG_MQTT_ENABLED", false) {
|
||||
client, err := gateway.NewMQTTClient(gateway.MQTTClientConfig{
|
||||
EndpointName: env("YUTONG_MQTT_ENDPOINT", "yutong"),
|
||||
Broker: env("YUTONG_MQTT_URI", ""),
|
||||
ClientID: env("YUTONG_MQTT_CLIENT_ID", "lingniu-go-yutong-mqtt"),
|
||||
Username: env("YUTONG_MQTT_USERNAME", ""),
|
||||
Password: env("YUTONG_MQTT_PASSWORD", ""),
|
||||
Topics: splitCSV(env("YUTONG_MQTT_TOPICS", env("YUTONG_MQTT_TOPIC", "/ytforward/shln/+"))),
|
||||
QoS: byte(envInt("YUTONG_MQTT_QOS", 2)),
|
||||
Sink: sink,
|
||||
Logger: logger,
|
||||
})
|
||||
if err != nil {
|
||||
logger.Error("build yutong mqtt client failed", "error", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
if err := client.Start(ctx); err != nil {
|
||||
logger.Error("start yutong mqtt client failed", "error", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
logger.Info("yutong mqtt client started")
|
||||
}
|
||||
|
||||
logger.Info("vehicle gateway started")
|
||||
select {
|
||||
@@ -122,6 +144,14 @@ func envInt(key string, fallback int) int {
|
||||
return out
|
||||
}
|
||||
|
||||
func envBool(key string, fallback bool) bool {
|
||||
value := strings.ToLower(strings.TrimSpace(os.Getenv(key)))
|
||||
if value == "" {
|
||||
return fallback
|
||||
}
|
||||
return value == "1" || value == "true" || value == "yes" || value == "on"
|
||||
}
|
||||
|
||||
func splitCSV(value string) []string {
|
||||
var out []string
|
||||
for _, item := range strings.Split(value, ",") {
|
||||
|
||||
Reference in New Issue
Block a user