From c4c0b2a9bfb98250e620c92ac6e173a5946464f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Mon, 12 Dec 2022 10:47:51 +0100 Subject: Add BigClown --- nixos/machine/spt-mox.nix | 112 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) (limited to 'nixos/machine') 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"; + }; + }; } -- cgit v1.2.3