From 0acdc403f3049b580432202e947de25e08e8f591 Mon Sep 17 00:00:00 2001
From: Qiyang Sun <qs2g22@soton.ac.uk>
Date: Thu, 22 Aug 2024 21:34:39 +0100
Subject: [PATCH] Add network: AP, DNS, nginx (rtmp, fastcgi)

Can capture camera
---
 README                                        |   1 +
 recipes-bsp/bootfiles/rpi-cmdline.bbappend    |   2 +-
 .../hostapd/hostapd/hostapd.conf              |   5 +
 .../hostapd/hostapd_2.10.bbappend             |   7 +
 recipes-core/fastinit/files/fastinit.sh       |  49 ++++
 recipes-core/images/mar-image-minimal.bb      |   4 +
 recipes-httpd/nginx/nginx/cgi-bin/camcap.cgi  |  28 ++
 recipes-httpd/nginx/nginx/conf/nginx.conf     |  76 ++++++
 recipes-httpd/nginx/nginx/html/.dir-locals.el |   4 +
 recipes-httpd/nginx/nginx/html/.gitignore     |   2 +
 recipes-httpd/nginx/nginx/html/camctrl.html   | 242 ++++++++++++++++++
 recipes-httpd/nginx/nginx/html/camctrl.org    |  26 ++
 recipes-httpd/nginx/nginx/html/landing.html   |  34 +++
 recipes-httpd/nginx/nginx/html/orgsetup       |   4 +
 recipes-httpd/nginx/nginx/sbin/rtmp-nginx.sh  |   9 +
 recipes-httpd/nginx/nginx_%.bbappend          |  60 +++++
 recipes-support/dnsmasq/dnsmasq/dnsmasq.conf  |   7 +
 recipes-support/dnsmasq/dnsmasq_%.bbappend    |  14 +
 18 files changed, 573 insertions(+), 1 deletion(-)
 create mode 100644 recipes-connectivity/hostapd/hostapd/hostapd.conf
 create mode 100644 recipes-connectivity/hostapd/hostapd_2.10.bbappend
 create mode 100755 recipes-httpd/nginx/nginx/cgi-bin/camcap.cgi
 create mode 100644 recipes-httpd/nginx/nginx/conf/nginx.conf
 create mode 100644 recipes-httpd/nginx/nginx/html/.dir-locals.el
 create mode 100644 recipes-httpd/nginx/nginx/html/.gitignore
 create mode 100644 recipes-httpd/nginx/nginx/html/camctrl.html
 create mode 100644 recipes-httpd/nginx/nginx/html/camctrl.org
 create mode 100644 recipes-httpd/nginx/nginx/html/landing.html
 create mode 100644 recipes-httpd/nginx/nginx/html/orgsetup
 create mode 100755 recipes-httpd/nginx/nginx/sbin/rtmp-nginx.sh
 create mode 100644 recipes-httpd/nginx/nginx_%.bbappend
 create mode 100644 recipes-support/dnsmasq/dnsmasq/dnsmasq.conf
 create mode 100644 recipes-support/dnsmasq/dnsmasq_%.bbappend

diff --git a/README b/README
index 73d166f..51448c8 100644
--- a/README
+++ b/README
@@ -84,6 +84,7 @@ III. Quick start guide
       bitbake-layers add-layer ../meta-openembedded/meta-python
       bitbake-layers add-layer ../meta-openembedded/meta-networking
       bitbake-layers add-layer ../meta-openembedded/meta-multimedia
+      bitbake-layers add-layer ../meta-openembedded/meta-webserver
 
       Assign a higher priority for layer meta-marfb than
       meta-raspberrypi and meta-openembedded.
diff --git a/recipes-bsp/bootfiles/rpi-cmdline.bbappend b/recipes-bsp/bootfiles/rpi-cmdline.bbappend
index eb4f84f..4e81ce6 100644
--- a/recipes-bsp/bootfiles/rpi-cmdline.bbappend
+++ b/recipes-bsp/bootfiles/rpi-cmdline.bbappend
@@ -5,4 +5,4 @@ CMDLINE:append = " modules.load=dwc2,g_serial"
 CMDLINE:append = " earlycon=uart8250,mmio32,0x20215040"
 #CMDLINE:append = " earlycon=pl011,mmio32,0x20201000"
 
-CMDLINE:append = " init=/usr/sbin/fastinit.sh 2"
+CMDLINE:append = " init=/usr/sbin/fastinit.sh 3"
diff --git a/recipes-connectivity/hostapd/hostapd/hostapd.conf b/recipes-connectivity/hostapd/hostapd/hostapd.conf
new file mode 100644
index 0000000..7750a48
--- /dev/null
+++ b/recipes-connectivity/hostapd/hostapd/hostapd.conf
@@ -0,0 +1,5 @@
+interface=wlan0
+driver=nl80211
+ssid=MAR Vision (Soton ECS)
+channel=1
+country_code=GB
diff --git a/recipes-connectivity/hostapd/hostapd_2.10.bbappend b/recipes-connectivity/hostapd/hostapd_2.10.bbappend
new file mode 100644
index 0000000..26c43c0
--- /dev/null
+++ b/recipes-connectivity/hostapd/hostapd_2.10.bbappend
@@ -0,0 +1,7 @@
+FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"
+SRC_URI:append = "file://hostapd.conf"
+
+do_install:append() {
+    install -m 0644 ${WORKDIR}/hostapd.conf ${D}${sysconfdir}
+}
+
diff --git a/recipes-core/fastinit/files/fastinit.sh b/recipes-core/fastinit/files/fastinit.sh
index 5c89cc2..04be9b3 100755
--- a/recipes-core/fastinit/files/fastinit.sh
+++ b/recipes-core/fastinit/files/fastinit.sh
@@ -24,6 +24,8 @@ mountfs() {
 	mount -t proc proc /proc
 	mount -t sysfs sysfs /sys
 	mount -o ro /dev/mmcblk0p1 /boot
+	mount -t tmpfs -o size=100M tmpfs /var/volatile/log
+	mount -t tmpfs -o size=100M tmpfs /var/log
 }
 
 rwrootfs() {
@@ -66,6 +68,48 @@ level_two() {
 	/sbin/getty -L 115200 ttyS0 vt100
 }
 
+level_three() {
+	mountfs
+	rwrootfs
+	log_to_kernel "adding modules to linux kernel"
+	log_to_kernel "to be added: bcm2835-codec, bcm2835-isp, bcm2835-v4l2, bcm2835-unicam, ov5647, i2c-mux-pinctrl, i2c-bcm2835, uio, fixed, brcmfmac" 
+	modprobe bcm2835-codec # minors 0-4
+	modprobe bcm2835-isp # minors 5-12
+	modprobe bcm2835-v4l2
+	modprobe bcm2835-unicam # cause red led flash
+	modprobe ov5647
+	modprobe i2c-mux-pinctrl
+	modprobe i2c-bcm2835
+	modprobe uio
+	modprobe fixed
+	modprobe brcmfmac
+	udevd --daemon
+	udevadm trigger
+	log_to_kernel "setting up lo (127.0.0.1/8)"
+	ip addr add 127.0.0.1/8 dev lo
+	ip link set lo up
+	log_to_kernel "setting up wlan0 (192.168.1.1)"
+	ifconfig wlan0 down
+	ifconfig wlan0 192.168.1.1
+	ifconfig wlan0 up
+	log_to_kernel "starting hostapd"
+	hostapd /etc/hostapd.conf -B 1>&2
+	log_to_kernel "starting dnsmasq"
+	dnsmasq 1>&2
+	log_to_kernel "starting fcgiwrap"
+	fcgiwrap -s unix:/var/run/fcgiwrap.socket &
+	log_to_kernel "starting nginx"
+	mkdir -p /var/volatile/log
+	mkdir -p /var/log/nginx
+	mkdir -p /usr/logs
+	mkdir -p /run/nginx
+	nginx 1>&2
+	gp23hi
+	crit_to_kernel "host is up and ready"
+	log_to_kernel "getting teletypes on ttyS0"
+	/sbin/getty -L 115200 ttyS0 vt100
+}
+
 level_five() {
 	exec /sbin/init 5
 }
@@ -99,6 +143,11 @@ else
 			log_to_kernel "runlevel 2: tty, serial, gpio, camera"
 			level_two
 			;;
+		3)
+			log_to_kernel "entering runlevel 3 (network)"
+			log_to_kernel "runlevel 3: tty, serial, gpio, camera, network, hostap"
+			level_three
+			;;
 		5)
 			log_to_kernel "entering runlevel 5 (sysvinit)"
 			level_five
diff --git a/recipes-core/images/mar-image-minimal.bb b/recipes-core/images/mar-image-minimal.bb
index 2efe346..2591df0 100644
--- a/recipes-core/images/mar-image-minimal.bb
+++ b/recipes-core/images/mar-image-minimal.bb
@@ -38,6 +38,10 @@ IMAGE_INSTALL = "packagegroup-core-boot \
     gstreamer1.0-plugins-ugly \
     gstreamer1.0-plugins-good-rpicamsrc \
     visionhellocc \
+    hostapd \
+    dnsmasq \
+    nginx \
+    fcgiwrap \
     ${CORE_IMAGE_EXTRA_INSTALL}"
 
 COMPATIBLE_MACHINE = "^rpi$"
diff --git a/recipes-httpd/nginx/nginx/cgi-bin/camcap.cgi b/recipes-httpd/nginx/nginx/cgi-bin/camcap.cgi
new file mode 100755
index 0000000..f45b05f
--- /dev/null
+++ b/recipes-httpd/nginx/nginx/cgi-bin/camcap.cgi
@@ -0,0 +1,28 @@
+#!/usr/bin/env bash
+echo "Content-type: text/html"
+echo
+echo "<html><head><title>CAMCTRL-CGI</title>"
+echo "<style>a { padding: 0px 1em; border: 3px outset buttonborder; border-radius: 3px; color: buttontext; background-color: buttonface; text-decoration: none; }</style>"
+echo "</head><body>"
+echo "<hr />"
+echo "<strong>** DEBUG INFO **</strong><br />"
+printf "<i>Who am i?</i> $(whoami)<br />"
+printf "<i>Uname?</i> $(uname -a)<br />"
+printf "<i>Date?</i> $(date)<br />"
+printf "<i>Uptime?</i> $(uptime)<br />"
+echo "<hr /><br />"
+echo "<strong>** CAMERA CONTROL CGI **</strong><br /><br />"
+chmod 0777 /usr/local/nginx/html/camctrl
+printf "<pre>Cleaning up..."
+rm -f /usr/local/nginx/camctrl/cap.jpg
+printf " done.</pre><br />"
+printf "<pre>Capturing in background..."
+nohup libcamera-jpeg -o /usr/local/nginx/html/camctrl/cap.jpg 1>/dev/null 2>/dev/null &
+PID=$!
+disown $PID
+printf " process (PID=$PID) started, detached and disowned.</pre><br />"
+echo "<strong>Please Navigate Back!</strong><br /><br /><br />"
+echo "<a href=\"javascript:history.back()\">Go Back</a> if your browser supports javascript:history.back()<br /><br />" 
+echo "<a href=\"http://192.168.1.1/camctrl\">Go to Camera Capture Ctl</a> if your browser does not support javascript"
+echo "</body></html>"
+exit 0
diff --git a/recipes-httpd/nginx/nginx/conf/nginx.conf b/recipes-httpd/nginx/nginx/conf/nginx.conf
new file mode 100644
index 0000000..9bcec29
--- /dev/null
+++ b/recipes-httpd/nginx/nginx/conf/nginx.conf
@@ -0,0 +1,76 @@
+worker_processes  1;
+user root;
+error_log  logs/error.log  info;
+events {
+	worker_connections  1024;
+}
+rtmp {
+	server {
+		listen 1935;
+		chunk_size 128;
+		application rtmp {
+			live on;
+			hls on;
+			hls_path /var/www/localhost/html/rtmp;
+			hls_continuous on;
+			hls_nested on;
+		}
+	}
+}
+http {
+	include             mime.types;
+	default_type        application/octet-stream;
+	#access_log         logs/access.log  main;
+	#tcp_nopush         on;
+	keepalive_timeout   65;
+	#gzip  on;
+	server {
+		listen          80;
+		server_name     localhost;
+		#access_log     logs/host.access.log  main;
+		location / {
+			root        /var/www/localhost/html;
+			index       index.html index.htm;
+			try_files   $uri $uri/index.html /index.html;
+			add_header Cache-Control no-cache;
+		}
+		error_page   500 502 503 504  /50x.html;
+		location = /50x.html {
+			root html;
+		}
+		location ~ /\.ht {
+			deny all;
+		}
+		location /stat {
+			rtmp_stat all;
+			rtmp_stat_stylesheet stat.xsl;
+		}
+		location /stat.xsl {
+			root /usr/local/nginx/nginx-rtmp-module;
+		}
+		location /control {
+			rtmp_control all;
+		}
+		location /rtmp {
+			types {
+				application/vnd.apple.mpegurl m3u8;
+				video/mp2t ts;
+				text/html;
+			}
+			default_type text_html;
+			alias /var/www/localhost/html/rtmp;
+			expires -1;
+			add_header Cache-Control no-cache;
+			index index.html;
+		}
+		location /exec {
+			command on;
+		}
+		location /cgi-bin/ {
+			gzip off;
+			fastcgi_pass unix:/var/run/fcgiwrap.socket;
+			include /etc/nginx/fastcgi_params;
+			fastcgi_param SCRIPT_FILENAME /var/www/localhost/html$fastcgi_script_name;
+		}
+	}
+}
diff --git a/recipes-httpd/nginx/nginx/html/.dir-locals.el b/recipes-httpd/nginx/nginx/html/.dir-locals.el
new file mode 100644
index 0000000..edeea12
--- /dev/null
+++ b/recipes-httpd/nginx/nginx/html/.dir-locals.el
@@ -0,0 +1,4 @@
+((org-mode
+  (org-html-postamble . "<br /><hr /><p><strong>Copyleft 2024 Qiyang Sun and the MAR24 Project Maintainers</strong>. Unless otherwise noted or where University of Southampton copyright regulations apply, this work (excluding code and program) is licensed under CC BY-SA 4.0 | Linux Foundation&reg; and Yocto Project&reg; are registered trademarks of the Linux Foundation. Linux&reg; is a registered trademark of Linus Torvalds. This project is not affiliated with Debian. Debian is a registered trademark owned by Software in the Public Interest, Inc. Raspberry Pi is a trademark of Raspberry Pi Ltd.<br /><p><strong>Author</strong>: %a <%e> | <strong>Last modified</strong>: %C | <strong>Static page built with</strong> %c </p>")))
+
+
diff --git a/recipes-httpd/nginx/nginx/html/.gitignore b/recipes-httpd/nginx/nginx/html/.gitignore
new file mode 100644
index 0000000..5236e1e
--- /dev/null
+++ b/recipes-httpd/nginx/nginx/html/.gitignore
@@ -0,0 +1,2 @@
+*~
+
diff --git a/recipes-httpd/nginx/nginx/html/camctrl.html b/recipes-httpd/nginx/nginx/html/camctrl.html
new file mode 100644
index 0000000..15a5a09
--- /dev/null
+++ b/recipes-httpd/nginx/nginx/html/camctrl.html
@@ -0,0 +1,242 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
+<head>
+<!-- 2024-08-22 Thu 17:42 -->
+<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
+<meta name="viewport" content="width=device-width, initial-scale=1" />
+<title>Camera Capture Control</title>
+<meta name="author" content="Qiyang Sun" />
+<meta name="generator" content="Org Mode" />
+<style>
+  #content { max-width: 60em; margin: auto; }
+  .title  { text-align: center;
+             margin-bottom: .2em; }
+  .subtitle { text-align: center;
+              font-size: medium;
+              font-weight: bold;
+              margin-top:0; }
+  .todo   { font-family: monospace; color: red; }
+  .done   { font-family: monospace; color: green; }
+  .priority { font-family: monospace; color: orange; }
+  .tag    { background-color: #eee; font-family: monospace;
+            padding: 2px; font-size: 80%; font-weight: normal; }
+  .timestamp { color: #bebebe; }
+  .timestamp-kwd { color: #5f9ea0; }
+  .org-right  { margin-left: auto; margin-right: 0px;  text-align: right; }
+  .org-left   { margin-left: 0px;  margin-right: auto; text-align: left; }
+  .org-center { margin-left: auto; margin-right: auto; text-align: center; }
+  .underline { text-decoration: underline; }
+  #postamble p, #preamble p { font-size: 90%; margin: .2em; }
+  p.verse { margin-left: 3%; }
+  pre {
+    border: 1px solid #e6e6e6;
+    border-radius: 3px;
+    background-color: #f2f2f2;
+    padding: 8pt;
+    font-family: monospace;
+    overflow: auto;
+    margin: 1.2em;
+  }
+  pre.src {
+    position: relative;
+    overflow: auto;
+  }
+  pre.src:before {
+    display: none;
+    position: absolute;
+    top: -8px;
+    right: 12px;
+    padding: 3px;
+    color: #555;
+    background-color: #f2f2f299;
+  }
+  pre.src:hover:before { display: inline; margin-top: 14px;}
+  /* Languages per Org manual */
+  pre.src-asymptote:before { content: 'Asymptote'; }
+  pre.src-awk:before { content: 'Awk'; }
+  pre.src-authinfo::before { content: 'Authinfo'; }
+  pre.src-C:before { content: 'C'; }
+  /* pre.src-C++ doesn't work in CSS */
+  pre.src-clojure:before { content: 'Clojure'; }
+  pre.src-css:before { content: 'CSS'; }
+  pre.src-D:before { content: 'D'; }
+  pre.src-ditaa:before { content: 'ditaa'; }
+  pre.src-dot:before { content: 'Graphviz'; }
+  pre.src-calc:before { content: 'Emacs Calc'; }
+  pre.src-emacs-lisp:before { content: 'Emacs Lisp'; }
+  pre.src-fortran:before { content: 'Fortran'; }
+  pre.src-gnuplot:before { content: 'gnuplot'; }
+  pre.src-haskell:before { content: 'Haskell'; }
+  pre.src-hledger:before { content: 'hledger'; }
+  pre.src-java:before { content: 'Java'; }
+  pre.src-js:before { content: 'Javascript'; }
+  pre.src-latex:before { content: 'LaTeX'; }
+  pre.src-ledger:before { content: 'Ledger'; }
+  pre.src-lisp:before { content: 'Lisp'; }
+  pre.src-lilypond:before { content: 'Lilypond'; }
+  pre.src-lua:before { content: 'Lua'; }
+  pre.src-matlab:before { content: 'MATLAB'; }
+  pre.src-mscgen:before { content: 'Mscgen'; }
+  pre.src-ocaml:before { content: 'Objective Caml'; }
+  pre.src-octave:before { content: 'Octave'; }
+  pre.src-org:before { content: 'Org mode'; }
+  pre.src-oz:before { content: 'OZ'; }
+  pre.src-plantuml:before { content: 'Plantuml'; }
+  pre.src-processing:before { content: 'Processing.js'; }
+  pre.src-python:before { content: 'Python'; }
+  pre.src-R:before { content: 'R'; }
+  pre.src-ruby:before { content: 'Ruby'; }
+  pre.src-sass:before { content: 'Sass'; }
+  pre.src-scheme:before { content: 'Scheme'; }
+  pre.src-screen:before { content: 'Gnu Screen'; }
+  pre.src-sed:before { content: 'Sed'; }
+  pre.src-sh:before { content: 'shell'; }
+  pre.src-sql:before { content: 'SQL'; }
+  pre.src-sqlite:before { content: 'SQLite'; }
+  /* additional languages in org.el's org-babel-load-languages alist */
+  pre.src-forth:before { content: 'Forth'; }
+  pre.src-io:before { content: 'IO'; }
+  pre.src-J:before { content: 'J'; }
+  pre.src-makefile:before { content: 'Makefile'; }
+  pre.src-maxima:before { content: 'Maxima'; }
+  pre.src-perl:before { content: 'Perl'; }
+  pre.src-picolisp:before { content: 'Pico Lisp'; }
+  pre.src-scala:before { content: 'Scala'; }
+  pre.src-shell:before { content: 'Shell Script'; }
+  pre.src-ebnf2ps:before { content: 'ebfn2ps'; }
+  /* additional language identifiers per "defun org-babel-execute"
+       in ob-*.el */
+  pre.src-cpp:before  { content: 'C++'; }
+  pre.src-abc:before  { content: 'ABC'; }
+  pre.src-coq:before  { content: 'Coq'; }
+  pre.src-groovy:before  { content: 'Groovy'; }
+  /* additional language identifiers from org-babel-shell-names in
+     ob-shell.el: ob-shell is the only babel language using a lambda to put
+     the execution function name together. */
+  pre.src-bash:before  { content: 'bash'; }
+  pre.src-csh:before  { content: 'csh'; }
+  pre.src-ash:before  { content: 'ash'; }
+  pre.src-dash:before  { content: 'dash'; }
+  pre.src-ksh:before  { content: 'ksh'; }
+  pre.src-mksh:before  { content: 'mksh'; }
+  pre.src-posh:before  { content: 'posh'; }
+  /* Additional Emacs modes also supported by the LaTeX listings package */
+  pre.src-ada:before { content: 'Ada'; }
+  pre.src-asm:before { content: 'Assembler'; }
+  pre.src-caml:before { content: 'Caml'; }
+  pre.src-delphi:before { content: 'Delphi'; }
+  pre.src-html:before { content: 'HTML'; }
+  pre.src-idl:before { content: 'IDL'; }
+  pre.src-mercury:before { content: 'Mercury'; }
+  pre.src-metapost:before { content: 'MetaPost'; }
+  pre.src-modula-2:before { content: 'Modula-2'; }
+  pre.src-pascal:before { content: 'Pascal'; }
+  pre.src-ps:before { content: 'PostScript'; }
+  pre.src-prolog:before { content: 'Prolog'; }
+  pre.src-simula:before { content: 'Simula'; }
+  pre.src-tcl:before { content: 'tcl'; }
+  pre.src-tex:before { content: 'TeX'; }
+  pre.src-plain-tex:before { content: 'Plain TeX'; }
+  pre.src-verilog:before { content: 'Verilog'; }
+  pre.src-vhdl:before { content: 'VHDL'; }
+  pre.src-xml:before { content: 'XML'; }
+  pre.src-nxml:before { content: 'XML'; }
+  /* add a generic configuration mode; LaTeX export needs an additional
+     (add-to-list 'org-latex-listings-langs '(conf " ")) in .emacs */
+  pre.src-conf:before { content: 'Configuration File'; }
+
+  table { border-collapse:collapse; }
+  caption.t-above { caption-side: top; }
+  caption.t-bottom { caption-side: bottom; }
+  td, th { vertical-align:top;  }
+  th.org-right  { text-align: center;  }
+  th.org-left   { text-align: center;   }
+  th.org-center { text-align: center; }
+  td.org-right  { text-align: right;  }
+  td.org-left   { text-align: left;   }
+  td.org-center { text-align: center; }
+  dt { font-weight: bold; }
+  .footpara { display: inline; }
+  .footdef  { margin-bottom: 1em; }
+  .figure { padding: 1em; }
+  .figure p { text-align: center; }
+  .equation-container {
+    display: table;
+    text-align: center;
+    width: 100%;
+  }
+  .equation {
+    vertical-align: middle;
+  }
+  .equation-label {
+    display: table-cell;
+    text-align: right;
+    vertical-align: middle;
+  }
+  .inlinetask {
+    padding: 10px;
+    border: 2px solid gray;
+    margin: 10px;
+    background: #ffffcc;
+  }
+  #org-div-home-and-up
+   { text-align: right; font-size: 70%; white-space: nowrap; }
+  textarea { overflow-x: auto; }
+  .linenr { font-size: smaller }
+  .code-highlighted { background-color: #ffff00; }
+  .org-info-js_info-navigation { border-style: none; }
+  #org-info-js_console-label
+    { font-size: 10px; font-weight: bold; white-space: nowrap; }
+  .org-info-js_search-highlight
+    { background-color: #ffff00; color: #000000; font-weight: bold; }
+  .org-svg { }
+</style>
+<style type="text/css"> html { color-scheme: light dark; } body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } a { padding: 0px 1em; border: 3px outset buttonborder; border-radius: 3px; color: buttontext; background-color: buttonface; text-decoration: none; } </style> <meta name="viewport" content="width=device-width, initial-scale=1.0">
+</head>
+<body>
+<div id="content" class="content">
+<h1 class="title">Camera Capture Control</h1>
+
+<div id="outline-container-org905a5a8" class="outline-2">
+<h2 id="org905a5a8">Manual</h2>
+<div class="outline-text-2" id="text-org905a5a8">
+<ol class="org-ol">
+<li>Click "Capture", will navigate to CGI</li>
+<li>Wait and navigate back when prompted</li>
+<li>When you are back to this page again, the view should be updated</li>
+<li>If not, force refresh this page</li>
+</ol>
+</div>
+</div>
+
+<div id="outline-container-org48efea3" class="outline-2">
+<h2 id="org48efea3">Control</h2>
+<div class="outline-text-2" id="text-org48efea3">
+<p>
+<a href="http://192.168.1.1/cgi-bin/camcap.cgi">Capture</a> or manually visit /cgi-bin/camcap.cgi
+</p>
+
+<p><a href="javascript:location.reload()">Reload</a> if your browser ignores no-cache header</p>
+
+<p><a href="http://192.168.1.1/camctrl/cap.jpg">Open Image</a> instead of viewing below</p>
+</div>
+</div>
+
+<div id="outline-container-org5d6c74b" class="outline-2">
+<h2 id="org5d6c74b">View</h2>
+<div class="outline-text-2" id="text-org5d6c74b">
+
+<div id="org5fa2fc5" class="figure">
+<p><img src="http://192.168.1.1/camctrl/cap.jpg" alt="cap.jpg" width="80%" />
+</p>
+</div>
+</div>
+</div>
+</div>
+<div id="postamble" class="status">
+<br /><hr /><p><strong>Copyleft 2024 Qiyang Sun and the MAR24 Project Maintainers</strong>. Unless otherwise noted or where University of Southampton copyright regulations apply, this work (excluding code and program) is licensed under CC BY-SA 4.0 | Linux Foundation&reg; and Yocto Project&reg; are registered trademarks of the Linux Foundation. Linux&reg; is a registered trademark of Linus Torvalds. This project is not affiliated with Debian. Debian is a registered trademark owned by Software in the Public Interest, Inc. Raspberry Pi is a trademark of Raspberry Pi Ltd.<br /><p><strong>Author</strong>: Qiyang Sun <<a href="mailto:qs2g22@soton.ac.uk">qs2g22@soton.ac.uk</a>> | <strong>Last modified</strong>: 2024-08-22 Thu 17:42 | <strong>Static page built with</strong> <a href="https://www.gnu.org/software/emacs/">Emacs</a> 28.2 (<a href="https://orgmode.org">Org</a> mode 9.5.5) </p>
+</div>
+</body>
+</html>
diff --git a/recipes-httpd/nginx/nginx/html/camctrl.org b/recipes-httpd/nginx/nginx/html/camctrl.org
new file mode 100644
index 0000000..83ae692
--- /dev/null
+++ b/recipes-httpd/nginx/nginx/html/camctrl.org
@@ -0,0 +1,26 @@
+#+TITLE: Camera Capture Control
+#+SETUPFILE: ./orgsetup
+
+* Manual
+
+1. Click "Capture", will navigate to CGI
+2. Wait and navigate back when prompted
+3. When you are back to this page again, the view should be updated
+4. If not, force refresh this page
+
+* Control
+
+[[http://192.168.1.1/cgi-bin/camcap.cgi][Capture]] or manually visit /cgi-bin/camcap.cgi
+
+#+BEGIN_EXPORT html
+<p><a href="javascript:location.reload()">Reload</a> if your browser ignores no-cache header</p>
+#+END_EXPORT
+
+#+BEGIN_EXPORT html
+<p><a href="http://192.168.1.1/camctrl/cap.jpg">Open Image</a> instead of viewing below</p>
+#+END_EXPORT
+
+* View
+
+#+ATTR_HTML: :width 80%
+[[http://192.168.1.1/camctrl/cap.jpg]]
diff --git a/recipes-httpd/nginx/nginx/html/landing.html b/recipes-httpd/nginx/nginx/html/landing.html
new file mode 100644
index 0000000..5a6fcd5
--- /dev/null
+++ b/recipes-httpd/nginx/nginx/html/landing.html
@@ -0,0 +1,34 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>Welcome to Mar Vision!</title>
+<meta name="viewport" content="width=device-width, initial-scale=1.0">
+<style>
+html { color-scheme: light dark; }
+body { width: 35em; margin: 0 auto;
+font-family: Tahoma, Verdana, Arial, sans-serif; }
+a { padding: 0px 1em; border: 3px outset buttonborder; 
+border-radius: 3px; color: buttontext; background-color: buttonface; 
+text-decoration: none; }
+</style>
+</head>
+<body>
+<h1>Welcome to Mar Vision!</h1>
+<p>If you see this page, the MAR web control systems are successfully
+installed andworking.</p>
+
+<p>For online documentation and support please refer to
+<a href="https://git.soton.ac.uk/qs2g22/meta-marfb">Git Repo</a>.<br/>
+Support from maintainer is available at
+<a href="mailto:qs2g22@soton.ac.uk">qs2g22 (email)</a>. You 
+do <strong>not</strong> have internet access when you are connected to
+this AP.</p>
+
+<p><em>Thank you for using MAR Fastboot Linux by ECS,
+University of Southampton.</em></p>
+<h1>Utilities</h1>
+<p>Follow the links to use the utilities.</p>
+<br />
+<p><a href="http://192.168.1.1/camctrl">Camera Control</a> Capture and 
+view the camera.</p><br />
+</body>
diff --git a/recipes-httpd/nginx/nginx/html/orgsetup b/recipes-httpd/nginx/nginx/html/orgsetup
new file mode 100644
index 0000000..1c935c8
--- /dev/null
+++ b/recipes-httpd/nginx/nginx/html/orgsetup
@@ -0,0 +1,4 @@
+#+HTML_HEAD: <style type="text/css"> html { color-scheme: light dark; } body { width: 35em; margin: 0 auto; font-family: Tahoma, Verdana, Arial, sans-serif; } a { padding: 0px 1em; border: 3px outset buttonborder; border-radius: 3px; color: buttontext; background-color: buttonface; text-decoration: none; } </style> <meta name="viewport" content="width=device-width, initial-scale=1.0">
+#+OPTIONS: ^:nil <:t num:nil toc:nil
+#+AUTHOR: Qiyang Sun
+#+EMAIL: qs2g22@soton.ac.uk 
diff --git a/recipes-httpd/nginx/nginx/sbin/rtmp-nginx.sh b/recipes-httpd/nginx/nginx/sbin/rtmp-nginx.sh
new file mode 100755
index 0000000..4c80e40
--- /dev/null
+++ b/recipes-httpd/nginx/nginx/sbin/rtmp-nginx.sh
@@ -0,0 +1,9 @@
+#!/bin/sh
+on_die () {  
+   # kill all children  
+   pkill -KILL -P $$  
+}  
+trap 'on_die' TERM  
+libcamera-vid --width=320 --height=240 -t 0 -o - | ffmpeg -i - -f flv -rtmp_buffer 1000 -filter:v "setpts=1.75*PTS" rtmp://localhost/rtmp &
+wait  
+
diff --git a/recipes-httpd/nginx/nginx_%.bbappend b/recipes-httpd/nginx/nginx_%.bbappend
new file mode 100644
index 0000000..1adce3c
--- /dev/null
+++ b/recipes-httpd/nginx/nginx_%.bbappend
@@ -0,0 +1,60 @@
+FILESEXTRAPATHS:prepend := "${THISDIR}/nginx:"
+
+SRC_URI += "file://conf/nginx.conf"
+SRC_URI += "file://sbin/rtmp-nginx.sh"
+
+SRC_URI += "git://github.com/arut/nginx-rtmp-module.git;protocol=https;name=nginx-rtmp-module;branch=master;tag=v1.2.2;subdir=nginx-rtmp-module"
+
+SRC_URI += "https://github.com/videojs/video.js/releases/download/v8.17.3/video-js-8.17.3.zip;name=videojs;subdir=video-js"
+SRC_URI[videojs.sha256sum] = "6aa29b8bd8b0d623d8ee92e752e3d6cdcf2cdff3d25285da12a1b00cdda3d7ea"
+
+SRC_URI += "git://github.com/limithit/NginxExecute.git;protocol=https;name=nginx-exec;branch=master;subdir=nginx-exec;rev=16ee0042ce5757a8111f920d51fe2048c8539aa2"
+SRCREV_FORMAT = "sha256"
+
+SRC_URI += "file://html/landing.html"
+SRC_URI += "file://html/camctrl.html"
+SRC_URI += "file://cgi-bin/camcap.cgi"
+
+EXTRA_OECONF:append = " --add-module=../nginx-rtmp-module --add-module=../nginx-exec"
+
+do_install:append() {
+
+    # install the modified nginx.conf
+    install -m 0644 ${WORKDIR}/conf/nginx.conf ${D}${sysconfdir}/nginx/nginx.conf
+
+    # install cgi-bin folder
+    install -m 0755 -d ${D}/var/www/localhost/html/cgi-bin
+
+    # create symlinks, prefix=/usr/local/nginx
+    install -m 0644 -d ${D}/usr/local/nginx
+    install -m 0644 -d ${D}/usr/local/nginx/conf
+    install -m 0644 -d ${D}/usr/local/nginx/sbin
+    install -m 0644 -d ${D}/usr/local/nginx/logs
+    ln -s /etc/nginx/nginx.conf ${D}/usr/local/nginx/conf/nginx.conf
+    ln -s /usr/sbin/nginx ${D}/usr/local/nginx/sbin/nginx
+    ln -s /var/www/localhost/html ${D}/usr/local/nginx/
+    ln -s /var/volatile/log/nginx/access.log ${D}/usr/local/nginx/logs/access.log
+    ln -s /var/volatile/log/nginx/error.log ${D}/usr/local/nginx/logs/error.log
+
+    # install nginx-rtmp-module
+    install -m 0666 -d ${D}/usr/local/nginx/nginx-rtmp-module
+    cp -r ../nginx-rtmp-module/* ${D}/usr/local/nginx/nginx-rtmp-module/
+    cp ${WORKDIR}/sbin/rtmp-nginx.sh ${D}/usr/local/nginx/sbin/
+    install -m 0777 -d ${D}/var/www/localhost/html/rtmp
+    chown root ${D}/var/www/localhost/html/rtmp
+    chown root ${D}/usr/local/nginx/nginx-rtmp-module/stat.xsl
+    chmod 0777 ${D}/usr/local/nginx/nginx-rtmp-module/stat.xsl
+
+    # install video.js
+    cp -r ${WORKDIR}/video-js/ ${D}/var/www/localhost/html/video-js/
+
+    # install landing page
+    cp ${WORKDIR}/html/landing.html ${D}/var/www/localhost/html/index.html
+    
+    # install camera control
+    install -m 0777 -d ${D}/var/www/localhost/html/camctrl
+    cp ${WORKDIR}/html/camctrl.html ${D}/var/www/localhost/html/camctrl/index.html
+    cp ${WORKDIR}/cgi-bin/camcap.cgi ${D}/var/www/localhost/html/cgi-bin/camcap.cgi
+}
+
+FILES:${PN} += "/usr/local/ /usr/local/nginx/ /usr/local/nginx/* /var/www/localhost/html/video-js/"
diff --git a/recipes-support/dnsmasq/dnsmasq/dnsmasq.conf b/recipes-support/dnsmasq/dnsmasq/dnsmasq.conf
new file mode 100644
index 0000000..5c9cee3
--- /dev/null
+++ b/recipes-support/dnsmasq/dnsmasq/dnsmasq.conf
@@ -0,0 +1,7 @@
+domain-needed
+no-resolv
+no-poll
+no-hosts
+interface=wlan0
+address=/#/192.168.1.1
+
diff --git a/recipes-support/dnsmasq/dnsmasq_%.bbappend b/recipes-support/dnsmasq/dnsmasq_%.bbappend
new file mode 100644
index 0000000..b6772d0
--- /dev/null
+++ b/recipes-support/dnsmasq/dnsmasq_%.bbappend
@@ -0,0 +1,14 @@
+do_install:append() {
+    cat <<EOF > ${D}${sysconfdir}/dnsmasq.conf
+domain-needed
+no-resolv
+no-poll
+no-hosts
+interface=wlan0
+address=/#/192.168.1.1
+dhcp-range=192.168.1.3,192.168.1.254,12h
+dhcp-option=option:router,192.168.1.1
+dhcp-option=option:dns-server,192.168.1.1
+EOF
+
+}
-- 
GitLab