Skip to content

Commit 0931fd4

Browse files
authored
Add influxdb v2 support (#143)
1 parent 0d6f45f commit 0931fd4

6 files changed

Lines changed: 147 additions & 196 deletions

File tree

cmd/confighandler.go

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -24,31 +24,31 @@ type Config struct {
2424
Devices []DeviceConfig
2525
}
2626

27-
// commandLine areguments are embedded into Config to allow validating
27+
// commandLine arguments are embedded into Config to allow validating
2828
// surplus keys in config file
2929
type commandLine struct {
30-
Adapter interface{} `mapstructure:"adapter"`
31-
Baudrate interface{} `mapstructure:"baudrate"`
32-
Comset interface{} `mapstructure:"comset"`
33-
Config interface{} `mapstructure:"config"`
34-
Help interface{} `mapstructure:"help"`
35-
InfluxDatabase interface{} `mapstructure:"influx-database"`
36-
InfluxInterval interface{} `mapstructure:"influx-interval"`
37-
InfluxMeasurement interface{} `mapstructure:"influx-measurement"`
38-
InfluxPassword interface{} `mapstructure:"influx-password"`
39-
InfluxPrecision interface{} `mapstructure:"influx-precision"`
40-
InfluxURL interface{} `mapstructure:"influx-url"`
41-
InfluxUser interface{} `mapstructure:"influx-user"`
42-
MqttBroker interface{} `mapstructure:"mqtt-broker"`
43-
MqttClientID interface{} `mapstructure:"mqtt-clientid"`
44-
MqttHomie interface{} `mapstructure:"mqtt-homie"`
45-
MqttPassword interface{} `mapstructure:"mqtt-password"`
46-
MqttQos interface{} `mapstructure:"mqtt-qos"`
47-
MqttTopic interface{} `mapstructure:"mqtt-topic"`
48-
MqttUser interface{} `mapstructure:"mqtt-user"`
49-
Raw interface{} `mapstructure:"raw"`
50-
RTU interface{} `mapstructure:"rtu"`
51-
Verbose interface{} `mapstructure:"verbose"`
30+
Adapter interface{} `mapstructure:"adapter"`
31+
Baudrate interface{} `mapstructure:"baudrate"`
32+
Comset interface{} `mapstructure:"comset"`
33+
Config interface{} `mapstructure:"config"`
34+
Help interface{} `mapstructure:"help"`
35+
InfluxURL interface{} `mapstructure:"influx-url"`
36+
InfluxDatabase interface{} `mapstructure:"influx-database"`
37+
InfluxMeasurement interface{} `mapstructure:"influx-measurement"`
38+
InfluxOrganization interface{} `mapstructure:"influx-organization"`
39+
InfluxToken interface{} `mapstructure:"influx-token"`
40+
InfluxPassword interface{} `mapstructure:"influx-password"`
41+
InfluxUser interface{} `mapstructure:"influx-user"`
42+
MqttBroker interface{} `mapstructure:"mqtt-broker"`
43+
MqttClientID interface{} `mapstructure:"mqtt-clientid"`
44+
MqttHomie interface{} `mapstructure:"mqtt-homie"`
45+
MqttPassword interface{} `mapstructure:"mqtt-password"`
46+
MqttQos interface{} `mapstructure:"mqtt-qos"`
47+
MqttTopic interface{} `mapstructure:"mqtt-topic"`
48+
MqttUser interface{} `mapstructure:"mqtt-user"`
49+
Raw interface{} `mapstructure:"raw"`
50+
RTU interface{} `mapstructure:"rtu"`
51+
Verbose interface{} `mapstructure:"verbose"`
5252
}
5353

5454
// MqttConfig describes the mqtt broker configuration
@@ -64,13 +64,13 @@ type MqttConfig struct {
6464

6565
// InfluxConfig describes the InfluxDB configuration
6666
type InfluxConfig struct {
67-
Database string
68-
Interval time.Duration
69-
Measurement string
70-
Password string
71-
Precision string
72-
URL string
73-
User string
67+
URL string
68+
Database string
69+
Measurement string
70+
Organization string
71+
Token string
72+
User string
73+
Password string
7474
}
7575

7676
// AdapterConfig describes device communication parameters

cmd/run.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,14 @@ any type is considered valid.
128128
"InfluxDB measurement",
129129
)
130130
runCmd.PersistentFlags().String(
131-
"influx-precision",
132-
"s",
133-
"InfluxDB precision",
131+
"influx-organization",
132+
"",
133+
"InfluxDB organization",
134134
)
135-
runCmd.PersistentFlags().Duration(
136-
"influx-interval",
137-
30*time.Second,
138-
"InfluxDB write interval",
135+
runCmd.PersistentFlags().String(
136+
"influx-token",
137+
"",
138+
"InfluxDB token (optional)",
139139
)
140140
runCmd.PersistentFlags().String(
141141
"influx-user",
@@ -157,7 +157,7 @@ any type is considered valid.
157157
bindPFlagsWithPrefix(pflags, "mqtt", "broker", "topic", "user", "password", "clientid", "qos", "homie")
158158

159159
// influx
160-
bindPFlagsWithPrefix(pflags, "influx", "url", "database", "measurement", "precision", "interval", "user", "password")
160+
bindPFlagsWithPrefix(pflags, "influx", "url", "database", "measurement", "organization", "token", "user", "password")
161161
}
162162

163163
// checkVersion validates if updates are available
@@ -300,11 +300,10 @@ func run(cmd *cobra.Command, args []string) {
300300
viper.GetString("influx.url"),
301301
viper.GetString("influx.database"),
302302
viper.GetString("influx.measurement"),
303-
viper.GetString("influx.precision"),
304-
viper.GetDuration("influx.interval"),
303+
viper.GetString("influx.organization"),
304+
viper.GetString("influx.token"),
305305
viper.GetString("influx.user"),
306306
viper.GetString("influx.password"),
307-
viper.GetBool("verbose"),
308307
)
309308

310309
tee.AttachRunner(server.NewSnipRunner(influx.Run))

docs/mbmd_run.md

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -13,45 +13,45 @@ mbmd run [flags]
1313
### Options
1414

1515
```
16-
--api string REST API url. Use 127.0.0.1:8080 to limit to localhost. (default "0.0.0.0:8080")
17-
-d, --devices strings MODBUS device type and ID to query, multiple devices separated by comma or by repeating the flag.
18-
Example: -d SDM:1,SDM:2 -d DZG:1.
19-
Valid types are:
20-
RTU
21-
ABB ABB A/B-Series meters
22-
DZG DZG Metering GmbH DVH4013 meters
23-
IEM3000 Schneider Electric iEM3000 series
24-
INEPRO Inepro Metering Pro 380
25-
JANITZA Janitza B-Series meters
26-
MPM Bernecker Engineering MPM3PM meters
27-
ORNO1P ORNO WE-514 & WE-515
28-
ORNO3P ORNO WE-516 & WE-517
29-
SBC Saia Burgess Controls ALE3 meters
30-
SDM Eastron SDM630
31-
SDM220 Eastron SDM220
32-
SDM230 Eastron SDM230
33-
SDM72 Eastron SDM72
34-
TCP
35-
SUNS Sunspec-compatible MODBUS TCP device (SMA, SolarEdge, KOSTAL, etc)
36-
To use an adapter different from default, append RTU device or TCP address separated by @.
37-
If the adapter is a TCP connection (identified by :port), the device type (SUNS) is ignored and
38-
any type is considered valid.
39-
Example: -d SDM:1@/dev/USB11 -d SMA:126@localhost:502
40-
--influx-database string InfluxDB database
41-
--influx-interval duration InfluxDB write interval (default 30s)
42-
--influx-measurement string InfluxDB measurement (default "data")
43-
--influx-password string InfluxDB password (optional)
44-
--influx-precision string InfluxDB precision (default "s")
45-
-i, --influx-url string InfluxDB URL. ex: http://10.10.1.1:8086
46-
--influx-user string InfluxDB user (optional)
47-
-m, --mqtt-broker string MQTT broker URI. ex: tcp://10.10.1.1:1883
48-
--mqtt-clientid string MQTT client id (default "mbmd")
49-
--mqtt-homie string MQTT Homie IoT discovery base topic (homieiot.github.io). Set empty to disable. (default "homie")
50-
--mqtt-password string MQTT password (optional)
51-
--mqtt-qos int MQTT quality of service 0,1,2 (default 0)
52-
--mqtt-topic string MQTT root topic. Set empty to disable publishing. (default "mbmd")
53-
--mqtt-user string MQTT user (optional)
54-
-r, --rate duration Rate limit. Devices will not be queried more often than rate limit. (default 1s)
16+
--api string REST API url. Use 127.0.0.1:8080 to limit to localhost. (default "0.0.0.0:8080")
17+
-d, --devices strings MODBUS device type and ID to query, multiple devices separated by comma or by repeating the flag.
18+
Example: -d SDM:1,SDM:2 -d DZG:1.
19+
Valid types are:
20+
RTU
21+
ABB ABB A/B-Series meters
22+
DZG DZG Metering GmbH DVH4013 meters
23+
IEM3000 Schneider Electric iEM3000 series
24+
INEPRO Inepro Metering Pro 380
25+
JANITZA Janitza B-Series meters
26+
MPM Bernecker Engineering MPM3PM meters
27+
ORNO1P ORNO WE-514 & WE-515
28+
ORNO3P ORNO WE-516 & WE-517
29+
SBC Saia Burgess Controls ALE3 meters
30+
SDM Eastron SDM630
31+
SDM220 Eastron SDM220
32+
SDM230 Eastron SDM230
33+
SDM72 Eastron SDM72
34+
TCP
35+
SUNS Sunspec-compatible MODBUS TCP device (SMA, SolarEdge, KOSTAL, etc)
36+
To use an adapter different from default, append RTU device or TCP address separated by @.
37+
If the adapter is a TCP connection (identified by :port), the device type (SUNS) is ignored and
38+
any type is considered valid.
39+
Example: -d SDM:1@/dev/USB11 -d SMA:126@localhost:502
40+
--influx-database string InfluxDB database
41+
--influx-measurement string InfluxDB measurement (default "data")
42+
--influx-organization string InfluxDB organization
43+
--influx-password string InfluxDB password (optional)
44+
--influx-token string InfluxDB token (optional)
45+
-i, --influx-url string InfluxDB URL. ex: http://10.10.1.1:8086
46+
--influx-user string InfluxDB user (optional)
47+
-m, --mqtt-broker string MQTT broker URI. ex: tcp://10.10.1.1:1883
48+
--mqtt-clientid string MQTT client id (default "mbmd")
49+
--mqtt-homie string MQTT Homie IoT discovery base topic (homieiot.github.io). Set empty to disable. (default "homie")
50+
--mqtt-password string MQTT password (optional)
51+
--mqtt-qos int MQTT quality of service 0,1,2 (default 0)
52+
--mqtt-topic string MQTT root topic. Set empty to disable publishing. (default "mbmd")
53+
--mqtt-user string MQTT user (optional)
54+
-r, --rate duration Rate limit. Devices will not be queried more often than rate limit. (default 1s)
5555
```
5656

5757
### Options inherited from parent commands

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ require (
1313
github.com/grid-x/modbus v0.0.0-20200108122021-57d05a9f1e1a
1414
github.com/grid-x/serial v0.0.0-20191104121038-e24bc9bf6f08 // indirect
1515
github.com/hashicorp/go-version v1.2.0 // indirect
16+
github.com/influxdata/influxdb-client-go v1.4.0
1617
github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d
1718
github.com/mitchellh/mapstructure v1.2.2 // indirect
1819
github.com/mjibson/esc v0.2.0

0 commit comments

Comments
 (0)