allow unregistered sensors in config
This commit is contained in:
parent
9cc656e937
commit
c0d315a409
3 changed files with 17 additions and 2 deletions
|
@ -2,6 +2,7 @@ package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
// const influx stuff
|
// const influx stuff
|
||||||
|
@ -15,6 +16,9 @@ const mqttURL = "tcp://default-address.com:1883"
|
||||||
const mqttTopic = "sensor/#"
|
const mqttTopic = "sensor/#"
|
||||||
const defaultLocation = "default-location"
|
const defaultLocation = "default-location"
|
||||||
|
|
||||||
|
//other config stuff
|
||||||
|
const allowUnregisteredSensors = false
|
||||||
|
|
||||||
//influx config
|
//influx config
|
||||||
func GetInfluxUrl() string {
|
func GetInfluxUrl() string {
|
||||||
return getVariableWithDefault("WEATHER-API-INFLUX_URL", influxURL)
|
return getVariableWithDefault("WEATHER-API-INFLUX_URL", influxURL)
|
||||||
|
@ -41,6 +45,14 @@ func GetMqttTopic() string {
|
||||||
return getVariableWithDefault("WEATHER-API-MQTT_TOPIC", mqttTopic)
|
return getVariableWithDefault("WEATHER-API-MQTT_TOPIC", mqttTopic)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func AllowUnregisteredSensors() bool {
|
||||||
|
allow, err := strconv.ParseBool(os.Getenv("WEATHER-API-ALLOW_UNREGISTERED_SENSORS"))
|
||||||
|
if err != nil {
|
||||||
|
return allowUnregisteredSensors
|
||||||
|
}
|
||||||
|
return allow
|
||||||
|
}
|
||||||
|
|
||||||
//helper
|
//helper
|
||||||
func getVariableWithDefault(variableKey, defaultValue string) string {
|
func getVariableWithDefault(variableKey, defaultValue string) string {
|
||||||
variable := os.Getenv(variableKey)
|
variable := os.Getenv(variableKey)
|
||||||
|
|
|
@ -10,5 +10,7 @@ Set-Item -Path "Env:WEATHER-API-INFLUX_BUCKET" -Value "default-bucket"
|
||||||
Set-Item -Path "Env:WEATHER-API-MQTT_URL" -Value "tcp://default-address.com:1883"
|
Set-Item -Path "Env:WEATHER-API-MQTT_URL" -Value "tcp://default-address.com:1883"
|
||||||
Set-Item -Path "Env:WEATHER-API-MQTT_TOPIC" -Value "sensor/#"
|
Set-Item -Path "Env:WEATHER-API-MQTT_TOPIC" -Value "sensor/#"
|
||||||
|
|
||||||
|
Set-Item -Path "Env:WEATHER-API-ALLOW_UNREGISTERED_SENSORS" -Value "true"
|
||||||
|
|
||||||
#start application
|
#start application
|
||||||
Start-Process "main.exe" -Wait -NoNewWindow
|
Start-Process "main.exe" -Wait -NoNewWindow
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
"weather-data/config"
|
||||||
"weather-data/storage"
|
"weather-data/storage"
|
||||||
|
|
||||||
mqtt "github.com/eclipse/paho.mqtt.golang"
|
mqtt "github.com/eclipse/paho.mqtt.golang"
|
||||||
|
@ -71,8 +72,8 @@ func (source *mqttWeatherSource) mqttMessageHandler() mqtt.MessageHandler {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !source.sensorRegistry.ExistSensorId(sensorId) {
|
if !config.AllowUnregisteredSensors() && !source.sensorRegistry.ExistSensorId(sensorId) {
|
||||||
fmt.Println("sensor not registered")
|
fmt.Println("sensor have to be registered:", sensorId)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue