ctucx.git: solax2mqtt

Publish data from Solax solar inverters via MQTT

1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
import std/httpclient
import std/[tables, math, json]

proc round* [T: float32|float64](value: T, places: int = 0): float = 
  if places == 0:
    result = round(value)
  else:
    result = value * pow(10.0, T(places))
    result = floor(result)
    result = result / pow(10.0, T(places))

proc read8BitUnsigned* (n: int): int =
  return n mod 256

proc read16BitSigned* (n: int): int =
  if n < 32768: return n
  else:         return n - 65536

proc read32BitUnsigned* (a: int, b: int): int64 = 
  return 65536 * b + a;

proc read32BitSigned* (a: int, b: int): int64 = 
  if a < 32768: return a + 65536 * b
  else:         return a + 65536 * b - 4294967296