diff options
author | Karel Kočí <cynerd@email.cz> | 2022-12-12 10:47:51 +0100 |
---|---|---|
committer | Karel Kočí <cynerd@email.cz> | 2022-12-12 10:47:51 +0100 |
commit | c4c0b2a9bfb98250e620c92ac6e173a5946464f7 (patch) | |
tree | 0d7fc7e44cd4b65beaeaa636f14c632a83c35485 /nixos/machine | |
parent | 32faf3d514ca67ffadd712ef10ddf257020c83e1 (diff) | |
download | nixos-personal-c4c0b2a9bfb98250e620c92ac6e173a5946464f7.tar.gz nixos-personal-c4c0b2a9bfb98250e620c92ac6e173a5946464f7.tar.bz2 nixos-personal-c4c0b2a9bfb98250e620c92ac6e173a5946464f7.zip |
Add BigClown
Diffstat (limited to 'nixos/machine')
-rw-r--r-- | nixos/machine/spt-mox.nix | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/nixos/machine/spt-mox.nix b/nixos/machine/spt-mox.nix index 037b10e..b01c48a 100644 --- a/nixos/machine/spt-mox.nix +++ b/nixos/machine/spt-mox.nix @@ -7,6 +7,10 @@ with lib; config = { + environment.systemPackages = with pkgs; [ + mosquitto + ]; + networking.wirelessAP = { enable = true; environmentFile = "/run/secrets/hostapd.env"; @@ -58,6 +62,114 @@ with lib; dhcpcd.allowInterfaces = [ "brlan" ]; }; + services.mosquitto = { + enable = true; + listeners = [ + { + users = { + cynerd = { + acl = ["readwrite #"]; + passwordFile = "/run/secrets/mosquitto.cynerd.pass"; + }; + bigclown = { + acl = ["readwrite bigclown/#"]; + passwordFile = "/run/secrets/mosquitto.bigclown.pass"; + }; + }; + } + ]; + }; + networking.firewall.allowedTCPPorts = [1883]; + + services.bigclown = { + gateway = { + enable = true; + device = "/dev/ttyUSB0"; + environmentFile = "/run/secrets/bigclown.env"; + baseTopicPrefix = "bigclown/"; + mqtt = { + username = "bigclown"; + password = "@PASS_MQTT@"; + }; + }; + mqtt2influxdb = { + enable = true; + environmentFile = "/run/secrets/bigclown.env"; + mqtt = { + username = "bigclown"; + password = "@PASS_MQTT@"; + }; + influxdb = { + host = "cynerd.cz"; + database = "bigclown"; + username = "bigclown"; + password = "@PASS_INFLUXDB@"; + ssl = true; + verify_ssl = false; + }; + points = [ + { + measurement = "temperature"; + topic = "bigclown/node/+/thermometer/+/temperature"; + fields.value = "$.payload"; + tags = { + id = "$.topic[2]"; + channel = "$.topic[4]"; + }; + } + { + measurement = "relative-humidity"; + topic = "bigclown/node/+/hygrometer/+/relative-humidity"; + fields.value = "$.payload"; + tags = { + id = "$.topic[2]"; + channel = "$.topic[4]"; + }; + } + { + measurement = "illuminance"; + topic = "bigclown/node/+/lux-meter/0:0/illuminance"; + fields.value = "$.payload"; + tags = { + id = "$.topic[2]"; + }; + } + { + measurement = "pressure"; + topic = "bigclown/node/+/barometer/0:0/pressure"; + fields.value = "$.payload"; + tags = { + id = "$.topic[2]"; + }; + } + { + measurement = "voltage"; + topic = "bigclown/node/+/battery/+/voltage"; + fields.value = "$.payload"; + tags = { + id = "$.topic[2]"; + }; + } + { + measurement = "button"; + topic = "bigclown/node/+/push-button/+/event-count"; + fields.value = "$.payload"; + tags = { + id = "$.topic[2]"; + channel = "$.topic[4]"; + }; + } + ]; + }; + }; + + systemd.services.bigclown-leds = { + description = "Bigclown LEDs control"; + wantedBy = ["multi-user.target"]; + after = ["mosquitto.service"]; + serviceConfig.ExecStart = "${pkgs.bigclown-leds}/bin/bigclown-leds /run/secrets/bigclown-leds.ini"; + }; + }; } |