From 0b57d7f1aa54211d1d2459da6aad34df0f16194a Mon Sep 17 00:00:00 2001 From: Lan Tian Date: Tue, 7 Jan 2025 01:41:04 -0800 Subject: [PATCH] hosts(lt-rpi4): setup lora multiplexer --- flake.lock | 6 ++-- hosts/lt-rpi4/lora/default.nix | 60 +++++++++++++++++++++++++--------- 2 files changed, 47 insertions(+), 19 deletions(-) diff --git a/flake.lock b/flake.lock index ccaa96d3..f9465662 100644 --- a/flake.lock +++ b/flake.lock @@ -943,11 +943,11 @@ "treefmt-nix": "treefmt-nix_3" }, "locked": { - "lastModified": 1735987314, - "narHash": "sha256-zjOdlIxIMNmtQOk6pXqZfj33SbJQj4eh5byQQRBT5rE=", + "lastModified": 1736240807, + "narHash": "sha256-BT517AKtTJX6VVun6sS7hdWAUAnYfONYkW/6Y7YjZLo=", "owner": "xddxdd", "repo": "nur-packages", - "rev": "2005fcccf32b7b702db941744aac39075fc8e6b6", + "rev": "31d037a5792423669a9345f7e3c32c850f81a878", "type": "github" }, "original": { diff --git a/hosts/lt-rpi4/lora/default.nix b/hosts/lt-rpi4/lora/default.nix index e6db7541..33c35d92 100644 --- a/hosts/lt-rpi4/lora/default.nix +++ b/hosts/lt-rpi4/lora/default.nix @@ -6,6 +6,15 @@ ... }: let + gwmp-mux = pkgs.nur-xddxdd.gwmp-mux.overrideAttrs (old: { + postPatch = + (old.postPatch or "") + + '' + substituteInPlace src/gwmp_mux.rs \ + --replace-fail "[0, 0, 0, 0]" "[127, 0, 0, 1]" + ''; + }); + sx1302Hal = pkgs.nur-xddxdd.sx1302-hal.overrideAttrs (old: { postPatch = (old.postPatch or "") @@ -14,24 +23,24 @@ let ''; }); + sx1302ServerConfig = { + "gateway_ID" = { + _secret = config.age.secrets.lora-euid.path; + }; + "server_address" = "127.0.0.1"; + "serv_port_up" = 1681; + "serv_port_down" = 1681; + }; + sx1302HalConfig = { - "gateway_conf" = { - "gateway_ID" = { - _secret = config.age.secrets.lora-euid.path; - }; - "server_address" = "nam1.cloud.thethings.network"; - "serv_port_up" = 1700; - "serv_port_down" = 1700; + "gateway_conf" = sx1302ServerConfig // { "servers" = [ - { - "gateway_ID" = { - _secret = config.age.secrets.lora-euid.path; - }; - "server_address" = "nam1.cloud.thethings.network"; - "serv_port_up" = 1700; - "serv_port_down" = 1700; - "serv_enabled" = true; - } + ( + sx1302ServerConfig + // { + "serv_enabled" = true; + } + ) ]; "gps_i2c_path" = "/dev/i2c-1"; @@ -54,6 +63,25 @@ in { age.secrets.lora-euid.file = inputs.secrets + "/lora-euid.age"; + systemd.services.lora-gwmp-mux = { + description = "LoRa GWMP Mux"; + wantedBy = [ "multi-user.target" ]; + + script = '' + TTN_IP=$(${pkgs.dnsutils}/bin/dig +short nam1.cloud.thethings.network | head -n1) + + sleep infinity | ${gwmp-mux}/bin/gwmp-mux \ + --host 1681 \ + --client $TTN_IP:1700 + ''; + + serviceConfig = { + Type = "simple"; + Restart = "always"; + RestartSec = "3"; + }; + }; + systemd.services.lora-sx1302-hal = { description = "LoRa SX1302 HAL"; wantedBy = [ "multi-user.target" ];