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/configurations.nix | 1 + nixos/machine/spt-mox.nix | 112 ++++++++++++++++++++++++++++++++++++++++++++++ nixos/modules/develop.nix | 2 + 3 files changed, 115 insertions(+) (limited to 'nixos') diff --git a/nixos/configurations.nix b/nixos/configurations.nix index 8977c7c..9754d28 100644 --- a/nixos/configurations.nix +++ b/nixos/configurations.nix @@ -7,6 +7,7 @@ let self.nixosModules."machine-${hostname}" shellrc.nixosModules.default usbkey.nixosModules.default + nixbigclown.nixosModules.default (personal-secret.lib.personalSecrets hostname) { networking.hostName = hostname; 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"; + }; + }; } diff --git a/nixos/modules/develop.nix b/nixos/modules/develop.nix index 5012fb8..c1c15b2 100644 --- a/nixos/modules/develop.nix +++ b/nixos/modules/develop.nix @@ -69,6 +69,8 @@ in { pylxd selenium + paho-mqtt + ])) geckodriver chromedriver -- cgit v1.2.3