Skip to content

Commit

Permalink
Merge pull request #6 from ablyler/influxdb2
Browse files Browse the repository at this point in the history
Add support for InfluxDB 2.x
  • Loading branch information
cdzombak authored Jul 9, 2021
2 parents b40efeb + a0e02e9 commit b975f9c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions config.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"influx_bucket": "MYHOME",
"influx_user": "",
"influx_password": "",
"influx_token": "",
"influx_org": "",
"always_write_weather_as_current": false,
"write_heat_pump_1": false,
"write_heat_pump_2": false,
Expand Down
8 changes: 6 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ type Config struct {
WorkDir string `json:"work_dir,omitempty"`
ThermostatID string `json:"thermostat_id"`
InfluxServer string `json:"influx_server"`
InfluxOrg string `json:"influx_org,omitempty"`
InfluxUser string `json:"influx_user,omitempty"`
InfluxPass string `json:"influx_password,omitempty"`
InfluxToken string `json:"influx_token,omitempty"`
InfluxBucket string `json:"influx_bucket"`
WriteHeatPump1 bool `json:"write_heat_pump_1"`
WriteHeatPump2 bool `json:"write_heat_pump_2"`
Expand Down Expand Up @@ -134,7 +136,9 @@ func main() {
const influxTimeout = 3 * time.Second
authString := ""
if config.InfluxUser != "" || config.InfluxPass != "" {
authString = fmt.Sprintf("%s:%s", config.InfluxUser, config.InfluxPass)
authString = fmt.Sprintf("%s:%s", config.InfluxUser, config.InfluxPass)
} else if config.InfluxToken != "" {
authString = fmt.Sprintf("%s", config.InfluxToken)
}
influxClient := influxdb2.NewClient(config.InfluxServer, authString)
ctx, cancel := context.WithTimeout(context.Background(), influxTimeout)
Expand All @@ -146,7 +150,7 @@ func main() {
if health.Status != "pass" {
log.Fatalf("InfluxDB did not pass health check: status %s; message '%s'", health.Status, *health.Message)
}
influxWriteApi := influxClient.WriteAPIBlocking("", config.InfluxBucket)
influxWriteApi := influxClient.WriteAPIBlocking(config.InfluxOrg, config.InfluxBucket)
_ = influxWriteApi

lastWrittenRuntimeInterval := 0
Expand Down

0 comments on commit b975f9c

Please sign in to comment.