Skip to content

Commit a715f77

Browse files
committed
config file
1 parent 46375ea commit a715f77

File tree

11 files changed

+62
-185
lines changed

11 files changed

+62
-185
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
/sofar
2+
sofar_g3_lsw3_logger_reader
3+
config.yaml

adapters/comms/serial/serial.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"io"
55
"time"
66

7-
"git.xelasys.ro/sigxcpu/sofar/ports"
7+
"github.com/kubaceg/sofar_g3_lsw3_logger_reader/ports"
88
"go.bug.st/serial"
99
)
1010

adapters/comms/tcpip/tcpip.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"net"
66
"time"
77

8-
"git.xelasys.ro/sigxcpu/sofar/ports"
8+
"github.com/kubaceg/sofar_g3_lsw3_logger_reader/ports"
99
)
1010

1111
type tcpIpPort struct {

adapters/databases/influx/influx.go

Lines changed: 0 additions & 124 deletions
This file was deleted.

adapters/databases/mosquitto/mqtt.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ import (
99
mqtt "github.com/eclipse/paho.mqtt.golang"
1010
)
1111

12+
type MqttConfig struct {
13+
Url string `yaml:"url"`
14+
User string `yaml:"user"`
15+
Password string `yaml:"password"`
16+
Prefix string `yaml:"prefix"`
17+
}
18+
1219
type MosquittoConnection struct {
1320
client mqtt.Client
1421
prefix string
@@ -22,16 +29,24 @@ var connectLostHandler mqtt.ConnectionLostHandler = func(client mqtt.Client, err
2229
log.Printf("Connect lost: %v", err)
2330
}
2431

25-
func New(url string, prefix string) (*MosquittoConnection, error) {
32+
func New(config *MqttConfig) (*MosquittoConnection, error) {
2633
opts := mqtt.NewClientOptions()
27-
opts.AddBroker(url)
34+
opts.AddBroker(config.Url)
2835
opts.SetClientID("sofar")
2936
opts.OnConnect = connectHandler
3037
opts.OnConnectionLost = connectLostHandler
3138

39+
if config.User != "" {
40+
opts.SetUsername(config.User)
41+
}
42+
43+
if config.Password != "" {
44+
opts.SetPassword(config.Password)
45+
}
46+
3247
conn := &MosquittoConnection{}
3348
conn.client = mqtt.NewClient(opts)
34-
conn.prefix = prefix
49+
conn.prefix = config.Prefix
3550
if token := conn.client.Connect(); token.Wait() && token.Error() != nil {
3651
return nil, token.Error()
3752
}

adapters/devices/sofar/device.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package sofar
22

3-
import "git.xelasys.ro/sigxcpu/sofar/ports"
3+
import "github.com/kubaceg/sofar_g3_lsw3_logger_reader/ports"
44

55
type SofarLogger struct {
66
serialNumber string

adapters/devices/sofar/lsw.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"fmt"
66
"strconv"
77

8-
"git.xelasys.ro/sigxcpu/sofar/ports"
8+
"github.com/kubaceg/sofar_g3_lsw3_logger_reader/ports"
99
"github.com/sigurn/crc16"
1010
)
1111

config-example.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
inverter:
2+
port: 1.2.3.4:23 # required port name (e.g. /dev/ttyUSB0 for serial or 1.2.3.4:23 for TCP/IP
3+
loggerSerial: 123456 # required logger serial number
4+
readInterval: 60 # update interval in seconds, default 60
5+
mqtt:
6+
url: 1.2.3.4:5678 #MQTT broker URL (e.g. 1.2.3.4:5678)
7+
user: #MQTT username (leave empty when not needed)
8+
password: #MQTT password (leave empty when not needed)
9+
prefix: /sensors/energy/inverter #topic on which data will be sended

go.mod

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
module git.xelasys.ro/sigxcpu/sofar
1+
module github.com/kubaceg/sofar_g3_lsw3_logger_reader
22

3-
go 1.18
3+
go 1.19
44

55
require (
66
github.com/eclipse/paho.mqtt.golang v1.3.1
@@ -14,4 +14,5 @@ require (
1414
github.com/gorilla/websocket v1.4.2 // indirect
1515
golang.org/x/net v0.0.0-20200425230154-ff2c4b7c35a0 // indirect
1616
golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf // indirect
17+
gopkg.in/yaml.v2 v2.4.0 // indirect
1718
)

go.sum

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,7 @@ golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7w
2121
golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf h1:2ucpDCmfkl8Bd/FsLtiD653Wf96cW37s+iGx93zsu4k=
2222
golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
2323
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
24+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
25+
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
26+
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
2427
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=

0 commit comments

Comments
 (0)