Compare commits

...

3 Commits

3 changed files with 19 additions and 12 deletions

View File

@ -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

View File

@ -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()

View File

@ -26,13 +26,14 @@ type pingvinCoil struct {
// unit modbus data
type Pingvin struct {
Coils []*pingvinCoil
Registers []*pingvinRegister
Status *pingvinStatus
buslock *sync.Mutex
handler *modbus.RTUClientHandler
modbusclient modbus.Client
Debug PingvinLogger
Coils []*pingvinCoil
Registers []*pingvinRegister
Status *pingvinStatus
buslock *sync.Mutex
handler *modbus.RTUClientHandler
modbusclient modbus.Client
firstReadDone bool
Debug PingvinLogger
}
// single register data
@ -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