feat(octoprint): motion and notifs

This commit is contained in:
arcnmx 2024-07-14 18:44:05 -07:00
parent 6bf729ffe9
commit 7fe6d48ff0
11 changed files with 263 additions and 47 deletions

34
nixos/cameras/kitchen.nix Normal file
View file

@ -0,0 +1,34 @@
{
config,
gensokyo-zone,
lib,
...
}: let
inherit (gensokyo-zone.lib) mapDefaults;
inherit (config.services) motion;
in {
services.motion.cameras.kitchencam.settings = mapDefaults {
videodevice = "/dev/kitchencam";
v4l2_palette = 8;
width = 640;
height = 480;
framerate = 5;
camera_id = 1;
text_left = "kitchen";
};
services.udev.extraRules = let
inherit (lib.strings) concatStringsSep;
rules = [
''SUBSYSTEM=="video4linux"''
''ACTION=="add"''
''ATTR{index}=="0"''
''ATTRS{idProduct}=="2a25"''
''ATTRS{idVendor}=="1224"''
''SYMLINK+="kitchencam"''
''OWNER="${motion.user}"''
''TAG+="systemd"''
''ENV{SYSTEMD_WANTS}="motion.service"''
];
rulesLine = concatStringsSep ", " rules;
in rulesLine;
}

View file

@ -0,0 +1,12 @@
{
gensokyo-zone,
...
}: let
inherit (gensokyo-zone.lib) mapDefaults;
in {
services.motion.cameras.webcam.settings = mapDefaults {
videodevice = "/dev/video0";
camera_id = 3;
text_left = "logistics";
};
}

34
nixos/cameras/printer.nix Normal file
View file

@ -0,0 +1,34 @@
{
config,
gensokyo-zone,
lib,
...
}: let
inherit (gensokyo-zone.lib) mapDefaults;
inherit (config.services) motion;
in {
services.motion.cameras.printercam.settings = mapDefaults {
videodevice = "/dev/printercam";
width = 640;
height = 480;
framerate = 5;
camera_id = 2;
text_left = "";
#text_right = "";
};
services.udev.extraRules = let
inherit (lib.strings) concatStringsSep;
rules = [
''SUBSYSTEM=="video4linux"''
''ACTION=="add"''
''ATTR{index}=="0"''
''ATTRS{idProduct}=="6366"''
''ATTRS{idVendor}=="0c45"''
''SYMLINK+="printercam"''
''OWNER="${motion.user}"''
''TAG+="systemd"''
''ENV{SYSTEMD_WANTS}="motion.service"''
];
rulesLine = concatStringsSep ", " rules;
in rulesLine;
}

View file

@ -33,32 +33,7 @@ in {
webcontrol_port = webPort;
stream_port = streamPort;
};
cameras.kitchencam.settings = mapDefaults {
videodevice = "/dev/kitchencam";
v4l2_palette = 8;
width = 640;
height = 480;
framerate = 5;
camera_id = 1;
text_left = "kitchen";
};
};
services.udev.extraRules = let
inherit (lib.strings) concatStringsSep;
rules = [
''SUBSYSTEM=="video4linux"''
''ACTION=="add"''
''ATTR{index}=="0"''
''ATTRS{idProduct}=="2a25"''
''ATTRS{idVendor}=="1224"''
''SYMLINK+="kitchencam"''
''OWNER="${cfg.user}"''
''TAG+="systemd"''
''ENV{SYSTEMD_WANTS}="motion.service"''
];
rulesLine = concatStringsSep ", " rules;
in
mkIf cfg.enable rulesLine;
networking.firewall.interfaces.local = mkIf cfg.enable {
allowedTCPPorts = [cfg.settings.stream_port cfg.settings.webcontrol_port];
};

View file

@ -1,14 +1,16 @@
{
pkgs,
config,
access,
gensokyo-zone,
lib,
...
}: let
inherit (gensokyo-zone.lib) domain;
inherit (lib.modules) mkIf mkMerge mkDefault;
inherit (config.services) motion;
cfg = config.services.octoprint;
behindVouch = false;
vouchHeader = null;
#vouchHeader = "X-Vouch-User";
in {
services.octoprint = {
enable = mkDefault true;
@ -16,6 +18,7 @@ in {
plugins = python3Packages: with python3Packages; [
prometheus-exporter
octorant
queue
abl-expert
bedlevelvisualizer
#displayprogress / displaylayerprogress?
@ -66,27 +69,113 @@ in {
serial = {
port = "/dev/ttyUSB0";
baudrate = 115200;
#autoconnect = true;
autoconnect = true;
};
}
{
plugins.octorant = let
media = {
none = "none";
webcam = "snapshot";
#timelapse = ?;
};
in {
_config_version = 2;
events = {
printer_state_error.media = media.none;
printer_state_operational = {
enabled = false;
media = media.none;
};
printer_state_unknown.media = media.none;
printing_started = {
message = "New print started: **{name}**";
};
printing_cancelled = {
message = "Print cancelled after {time_formatted}";
};
printing_paused = {
message = "Print paused";
media = media.none;
};
printing_failed.message = "Print failed! :<";
printing_progress.message = "Printed **{progress}%** with {remaining_formatted} remaining";
printing_resumed = {
message = "Print resumed";
media = media.none;
};
shutdown = {
#enabled = false;
media = media.none;
};
startup = {
#enabled = false;
media = media.none;
};
timelapse_done = {
enabled = true;
# TODO: movie_basename needs uri encoding if it contains spaces .-.
message = "Timelapse for {gcode}: https://print.${domain}/downloads/timelapse/{movie_basename}";
media = media.none;
};
timelapse_failed.media = media.none;
transfer_done.media = media.none;
transfer_failed.media = media.none;
transfer_progress.media = media.none;
progress = {
#percentage_enabled = false;
percentage_step = "14";
throttle_enabled = true;
time_enabled = true;
throttle_step = "540";
time_step = "600";
};
};
# TODO: url = "https://discord.com/api/webhooks/etc";
};
}
(mkIf motion.enable {
webcam = {
# TODO
bitrate = "6000k";
ffmpegThreads = 2;
timelapse = {
fps = 25;
options.interval = 3;
postRoll = 0;
type = "timed";
};
};
plugins = {
classicwebcam = let
inherit (motion.cameras) printercam;
inherit (printercam.settings) camera_id;
in {
_config_version = 1;
snapshot = "https://kitchen.local.${domain}/${toString camera_id}/current";
stream = "https://kitchen.local.${domain}/${toString camera_id}/stream";
streamRatio = "4:3";
};
};
})
(mkIf (!behindVouch) {
(mkIf (vouchHeader == null) {
accessControl = {
autologinLocal = true;
autologinHeadsupAcknowledged = true;
#autologinAs = "guest";
autologinAs = "admin";
localNetworks = access.cidrForNetwork.allLocal.all;
localNetworks = access.cidrForNetwork.allLocal.all
++ [
# vouch protects it from the outside world so...
"0.0.0.0/0"
"::/0"
];
};
})
(mkIf behindVouch {
(mkIf (vouchHeader != null) {
accessControl = {
trustRemoteUser = true;
addRemoteUsers = true;
remoteUserHeader = "X-Vouch-User";
remoteUserHeader = vouchHeader;
};
})
];