ctucx.git: smartied

[nimlang] smarthome server

commit 62cd7210edeaeb400cefdcb2214d4f202fa5cb1f
parent 62ff18726a229422f99e4a19d3a054e4ab7da15d
Author: Leah (ctucx) <leah@ctu.cx>
Date: Thu, 18 Feb 2021 19:52:13 +0100

improve influx
5 files changed, 18 insertions(+), 18 deletions(-)
diff --git a/config.json b/config.json
@@ -158,8 +158,8 @@
 		"influx": {
 			"host": "10.0.0.1",
 			"port": 8086,
-			"powermeterDatabase": "powermeter",
-			"lacrosseDatabase": "temperatureSensors"
+			"powermetersDatabase": "test_powermeters",
+			"sensorsDatabase": "test_sensors"
 		},
 		"powermeterUpdateIntervalSec": 20,
 		"accessToken": "penis123"
diff --git a/src/devices/lacrosseSensors.nim b/src/devices/lacrosseSensors.nim
@@ -33,7 +33,7 @@ proc lacrosseHandleLoop (sock: AsyncSocket) {.async.} =
         if server.config.serverConfig.influx.isSome:
           let config = server.config.serverConfig.influx.get
 
-          if config.lacrosseDatabase.isSome:
+          if config.sensorsDatabase.isSome:
             var tags, fields = initTable[string, string]()
 
             tags["device"] = key

@@ -43,7 +43,7 @@ proc lacrosseHandleLoop (sock: AsyncSocket) {.async.} =
 
             fields["temperature"] = $msg.temp.isaRound(2)
 
-            discard await config.insertDatabase(config.lacrosseDatabase.get, key, tags, fields, currentTimestamp * 1000000000)
+            discard await config.insertDatabase(config.sensorsDatabase.get, key, tags, fields, currentTimestamp * 1000000000)
 
 
         broadcastServerState()
diff --git a/src/devices/modbusPowermeter.nim b/src/devices/modbusPowermeter.nim
@@ -14,7 +14,7 @@ proc updatePowermeter (key: string, device: DeviceConfig) {.async.} =
   if server.config.serverConfig.influx.isSome:
     let config = server.config.serverConfig.influx.get
 
-    if config.powermeterDatabase.isSome:
+    if config.powermetersDatabase.isSome:
       if server.state[key].lastUpdated.isSome:
         if (currentTimestamp - server.state[key].lastUpdated.get) < 30:
           break

@@ -29,7 +29,7 @@ proc updatePowermeter (key: string, device: DeviceConfig) {.async.} =
       fields["cosphi"]    = $cosphi
       fields["power"]     = $power
 
-      discard await config.insertDatabase(config.powermeterDatabase.get, key, tags, fields, currentTimestamp * 1000000000)
+      discard await config.insertDatabase(config.powermetersDatabase.get, key, tags, fields, currentTimestamp * 1000000000)
 
   server.state[key].voltage     = voltage
   server.state[key].frequency   = frequency
diff --git a/src/influx.nim b/src/influx.nim
@@ -56,14 +56,14 @@ proc initInflux* () =
   let config = server.config.serverConfig.influx.get
 
   try:
-    if config.powermeterDatabase.isSome:
-      if not waitFor config.existsDatabase(config.powermeterDatabase.get):
-        echo "Specified Influxdatabase for Powermeter does not exist!"
+    if config.powermetersDatabase.isSome:
+      if not waitFor config.existsDatabase(config.powermetersDatabase.get):
+        echo "Specified Influxdatabase for powermeters does not exist!"
         quit()
 
-    if config.lacrosseDatabase.isSome:
-      if not waitFor config.existsDatabase(config.lacrosseDatabase.get):
-        echo "Specified Influxdatabase for Lacrosse does not exist!"
+    if config.sensorsDatabase.isSome:
+      if not waitFor config.existsDatabase(config.sensorsDatabase.get):
+        echo "Specified Influxdatabase for sensors does not exist!"
         quit()
 
   except:
diff --git a/src/types.nim b/src/types.nim
@@ -105,12 +105,12 @@ type LacrosseConfig* = object
   port*: uint16
 
 type InfluxConfig* = object
-  host*:               string
-  port*:               int
-  username*:           Option[string]
-  password*:           Option[string]
-  powermeterDatabase*: Option[string]
-  lacrosseDatabase*:   Option[string]
+  host*:                string
+  port*:                int
+  username*:            Option[string]
+  password*:            Option[string]
+  powermetersDatabase*: Option[string]
+  sensorsDatabase*:     Option[string]
 
 type SmartiedConfig* = object
   frontendPort*: uint16