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")
|
Username for HTTP Basic Authentication (default "pingvin")
|
||||||
```
|
```
|
||||||
On first run, the daemon generates `~/.config/enervent-ctrl/configuration.yaml` with default values.
|
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
|
- `serial_address:` Path to RS-485 serial device
|
||||||
- `port:` TCP port for the REST API to listen on
|
- `port:` TCP port for the REST API to listen on
|
||||||
- `ssl_certificate:` Path to SSL certificate for HTTPS
|
- `ssl_certificate:` Path to SSL certificate for HTTPS
|
||||||
|
|
4
main.go
4
main.go
|
@ -25,7 +25,7 @@ import (
|
||||||
var static embed.FS
|
var static embed.FS
|
||||||
|
|
||||||
var (
|
var (
|
||||||
version = "0.1.0"
|
version = "0.1.1"
|
||||||
device pingvin.Pingvin
|
device pingvin.Pingvin
|
||||||
config Conf
|
config Conf
|
||||||
usernamehash [32]byte
|
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() {
|
func configure() {
|
||||||
log.Println("Reading configuration")
|
log.Println("Reading configuration")
|
||||||
parseConfigFile()
|
parseConfigFile()
|
||||||
|
|
|
@ -32,6 +32,7 @@ type Pingvin struct {
|
||||||
buslock *sync.Mutex
|
buslock *sync.Mutex
|
||||||
handler *modbus.RTUClientHandler
|
handler *modbus.RTUClientHandler
|
||||||
modbusclient modbus.Client
|
modbusclient modbus.Client
|
||||||
|
firstReadDone bool
|
||||||
Debug PingvinLogger
|
Debug PingvinLogger
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -310,12 +311,18 @@ func (p *Pingvin) updateRegisters() {
|
||||||
if len(results) > 0 {
|
if len(results) > 0 {
|
||||||
break
|
break
|
||||||
} else if retries == 4 {
|
} 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 {
|
} else if err != nil {
|
||||||
log.Printf("WARNING: updateRegisters: client.ReadHoldingRegisters attempt %d: %s", retries, err)
|
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
|
// 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
|
// 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
|
// value, so for each even byte in the reponse slice we bitshift the byte
|
||||||
|
|
Loading…
Reference in New Issue