refactor(db): add flag to run without MQTT part
Use for local test for developement Signed-off-by: Klagarge <remi@heredero.ch>
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
|||||||
"gateway/rest"
|
"gateway/rest"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@@ -92,18 +93,21 @@ func influxConnection() *influx.InfluxGateway {
|
|||||||
// @BasePath /api/v1
|
// @BasePath /api/v1
|
||||||
// @securityDefinitions.basic BasicAuth
|
// @securityDefinitions.basic BasicAuth
|
||||||
func main() {
|
func main() {
|
||||||
|
noMqtt := slices.Contains(os.Args[1:], "--no-mqtt")
|
||||||
|
|
||||||
// Load mapping configuration (reloaded dynamically on each access)
|
// Load mapping configuration (reloaded dynamically on each access)
|
||||||
mappingPath := getEnv("MAPPING_CONFIG_PATH", "mapping.json")
|
mappingPath := getEnv("MAPPING_CONFIG_PATH", "mapping.json")
|
||||||
mapping := NewDynamicMapping(mappingPath)
|
mapping := NewDynamicMapping(mappingPath)
|
||||||
|
|
||||||
mqttGateway := mqttConnection()
|
|
||||||
defer mqttGateway.Disconnect()
|
|
||||||
|
|
||||||
influxGateway := influxConnection()
|
influxGateway := influxConnection()
|
||||||
defer influxGateway.Close()
|
defer influxGateway.Close()
|
||||||
|
|
||||||
measurementName := getEnv("CAMPUS", "provence")
|
measurementName := getEnv("CAMPUS", "provence")
|
||||||
|
|
||||||
|
if !noMqtt {
|
||||||
|
mqttGateway := mqttConnection()
|
||||||
|
defer mqttGateway.Disconnect()
|
||||||
|
|
||||||
// Create measurement for provence topic
|
// Create measurement for provence topic
|
||||||
provenceMeasurement := point.CreateMeasurement[ProvenceData](measurementName)
|
provenceMeasurement := point.CreateMeasurement[ProvenceData](measurementName)
|
||||||
// The incoming MQTT topic structure is: <gateway_id>/<node_id>/update
|
// The incoming MQTT topic structure is: <gateway_id>/<node_id>/update
|
||||||
@@ -171,6 +175,9 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
log.Println("[Main] MQTT disabled (--no-mqtt flag set)")
|
||||||
|
}
|
||||||
|
|
||||||
// Initialize and start REST Gateway
|
// Initialize and start REST Gateway
|
||||||
restUsername := getEnv("REST_USERNAME", "user")
|
restUsername := getEnv("REST_USERNAME", "user")
|
||||||
|
|||||||
Reference in New Issue
Block a user