Commit 60456c7c authored by Samuel Laurén's avatar Samuel Laurén
Browse files

Timer service for image uploads

parent c5f96e9b
......@@ -76,6 +76,7 @@
user = "coffeecam";
targetAddress = "rtp://130.232.103.36:2222";
device = "/dev/v4l/by-id/usb-Generic_USB2.0_PC_CAMERA-video-index0";
uploadAddress = "http://baka-ett.utu.fi/kahviimg.php";
};
system.stateVersion = "17.09";
......
......@@ -31,12 +31,25 @@ in {
description = "Username";
type = types.str;
};
uploadAddress = mkOption {
description = "Upload address";
type = types.str;
example = "http://example.com/upload";
};
timer = mkOption {
description = "Image uploader timer";
type = types.str;
default = "*:0/2";
};
};
};
# Are these options in any way sensible
config = mkIf cfg.enable {
environment.systemPackages = [ pkgs.ffmpeg pkgs.dejavu_fonts ];
environment.systemPackages = [ pkgs.ffmpeg pkgs.curl ];
systemd.services.coffeecam = {
description = "CoffeeCam transmission";
wantedBy = [ "multi-user.target" ];
......@@ -55,7 +68,7 @@ in {
-vcodec mpeg4
-r 15
-f rtp_mpegts
-vf 'hflip,drawtext=fontsize=15:fontfile=/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans-Bold.ttf:rate=1/2:text=%{localtime}:fontsize=11:fontcolor='white':boxcolor=0x00000099:box=1:x=320-text_w/2:y=480-text_h'
-vf 'hflip,drawtext=rate=1/2:text=%{localtime}:fontsize=11:fontcolor='white':boxcolor=0x00000099:box=1:x=320-text_w/2:y=480-text_h'
-threads 2
-r 15 ${cfg.targetAddress}
-r 15
......@@ -69,5 +82,31 @@ in {
Restart = "on-failure";
};
};
systemd.services."coffeecam-uploader" = {
description = "CoffeeCam image uploader";
wants = [ "coffeecam.service" ];
serviceConfig = {
Type = "oneshot";
User = "${cfg.user}";
ExecStart = lib.replaceStrings ["\n"] [" "] ''
${pkgs.curl}/bin/curl
--connect-timeout 8
--max-time 15
--retry 1
--retry-max-time 4
'${cfg.uploadAddress}'
--data-binary
@${cfg.imagePath}'';
};
};
systemd.timers."coffeecam-uploader" = {
description = "CoffeeCam image uploader timer";
wantedBy = [ "timers.target" ];
timerConfig = {
OnCalendar = "${cfg.timer}";
};
};
};
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment