Compare commits
3 Commits
5458c3ba86
...
28a555fa2b
Author | SHA1 | Date |
---|---|---|
Jarno Rankinen | 28a555fa2b | |
Jarno Rankinen | ea8ca1a6df | |
Jarno Rankinen | d9fbbfac1c |
|
@ -66,7 +66,7 @@ has been used.
|
|||
Username for HTTP Basic Authentication (default "pingvin")
|
||||
```
|
||||
On first run, the daemon generates `~/.config/enervent-ctrl/configuration.yaml` with default values.
|
||||
Configuration options are the same as with CLI flags. CLI flags take precedenence over the config file.
|
||||
Configuration options are the same as with CLI flags. CLI flags take precedence over the config file.
|
||||
- `serial_address:` Path to RS-485 serial device
|
||||
- `port:` TCP port for the REST API to listen on
|
||||
- `ssl_certificate:` Path to SSL certificate for HTTPS
|
||||
|
|
4
main.go
4
main.go
|
@ -25,7 +25,7 @@ import (
|
|||
var static embed.FS
|
||||
|
||||
var (
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
device pingvin.Pingvin
|
||||
config Conf
|
||||
usernamehash [32]byte
|
||||
|
@ -155,7 +155,7 @@ func initDefaultConfig(confpath string) {
|
|||
}
|
||||
}
|
||||
|
||||
// Read configuration. CLI flags take presedence over configuration file
|
||||
// Read configuration. CLI flags take precedence over configuration file
|
||||
func configure() {
|
||||
log.Println("Reading configuration")
|
||||
parseConfigFile()
|
||||
|
|
|
@ -32,6 +32,7 @@ type Pingvin struct {
|
|||
buslock *sync.Mutex
|
||||
handler *modbus.RTUClientHandler
|
||||
modbusclient modbus.Client
|
||||
firstReadDone bool
|
||||
Debug PingvinLogger
|
||||
}
|
||||
|
||||
|
@ -310,12 +311,18 @@ func (p *Pingvin) updateRegisters() {
|
|||
if len(results) > 0 {
|
||||
break
|
||||
} else if retries == 4 {
|
||||
log.Fatal("updateRegisters: client.ReadHoldingRegisters: ", err)
|
||||
log.Printf("ERROR: updateRegisters: max retries reached, giving up. client.ReadHoldingRegisters: %v", err)
|
||||
log.Printf("ERROR: error occurred when reading registers %d - %d", k, k+r-1)
|
||||
if !p.firstReadDone {
|
||||
panic("FATAL: Error on initial read")
|
||||
}
|
||||
return
|
||||
} else if err != nil {
|
||||
log.Printf("WARNING: updateRegisters: client.ReadHoldingRegisters attempt %d: %s", retries, err)
|
||||
}
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
time.Sleep(200 * time.Millisecond)
|
||||
}
|
||||
p.firstReadDone = true
|
||||
// The values represent 16 bit integers, but modbus works with bytes
|
||||
// Each even byte of the returned []byte is the 8 MSBs of a new 16-bit
|
||||
// value, so for each even byte in the reponse slice we bitshift the byte
|
||||
|
|
Loading…
Reference in New Issue