1
0
mirror of https://github.com/EliasKotlyar/Xiaomi-Dafang-Hacks.git synced 2025-09-09 07:30:57 +02:00

Motionvideo2mqtt (#1298)

* Add 768x432 video resolution

* Update system_video.cgi

sort

* Add options to send motion video to MQTT

* Missing pieces

Co-authored-by: jmtatsch <jmtatsch@users.noreply.github.com>
Co-authored-by: Marc Fundenberger <38658442+MarcFundenberger@users.noreply.github.com>
This commit is contained in:
Knurlnheim
2020-03-01 20:49:40 +01:00
committed by GitHub
parent 8858ca43e1
commit d9336ab637
7 changed files with 70 additions and 12 deletions

View File

@@ -19,6 +19,7 @@ motion_tracking=off
motion_trigger_led=true
publish_mqtt_message=false
publish_mqtt_snapshot=false
publish_mqtt_video=false
send_email=false
send_telegram=false
telegram_alert_type=image

View File

@@ -530,7 +530,7 @@ motion_tracking(){
esac
}
# Control the motion detection publish MQTT-message function
# Control the motion detection publish MQTT-message function
motion_mqtt_publish(){
case "$1" in
on)
@@ -574,6 +574,28 @@ motion_mqtt_snapshot(){
esac
}
# Control the motion detection publish video in MQTT-message function
motion_mqtt_video(){
case "$1" in
on)
rewrite_config /system/sdcard/config/motion.conf publish_mqtt_video "true"
;;
off)
rewrite_config /system/sdcard/config/motion.conf publish_mqtt_video "false"
;;
status)
status=$(grep '^[^#;]' /system/sdcard/config/motion.conf|grep 'publish_mqtt_video'|cut -f2 -d \=)
case $status in
true)
echo "ON"
;;
false)
echo "OFF"
;;
esac
esac
}
# Control the night mode
night_mode(){
case "$1" in

View File

@@ -25,12 +25,12 @@ record_video () {
if [ "$video_use_rtsp" = true ]; then
output_buffer_size="$((($BITRATE*100)+150000))"
if [ -z "$USERNAME" ]; then
if [ -z "$USERNAME" ]; then
/system/sdcard/bin/openRTSP -4 -w "$video_rtsp_w" -h "$video_rtsp_h" -f "$video_rtsp_f" -d "$video_duration" -b "$output_buffer_size" rtsp://127.0.0.1:$PORT/unicast > "$video_tempfile"
else
/system/sdcard/bin/openRTSP -4 -w "$video_rtsp_w" -h "$video_rtsp_h" -f "$video_rtsp_f" -d "$video_duration" -b "$output_buffer_size" rtsp://$USERNAME:$USERPASSWORD@127.0.0.1:$PORT/unicast > "$video_tempfile"
fi
else
# Use avconv to stitch multiple JPEGs into 1fps video.
# I couldn't get it working another way.
@@ -68,7 +68,7 @@ filename=$(date "$filename_pattern")
debug_msg "Got snapshot_tempfile=$snapshot_tempfile"
# Then, record video (if necessary)
if [ "$save_video" = true -o "$smb_video" = true -o "$telegram_alert_type" = "video" ] ; then
if [ "$save_video" = true -o "$smb_video" = true -o "$telegram_alert_type" = "video" -o "$publish_mqtt_video" = true ] ; then
record_video
fi
@@ -196,7 +196,7 @@ if [ "$smb_snapshot" = true -o "$smb_video" = true ]; then
fi
# Publish a mqtt message
if [ "$publish_mqtt_message" = true -o "$publish_mqtt_snapshot" = true ] ; then
if [ "$publish_mqtt_message" = true -o "$publish_mqtt_snapshot" = true -o "$publish_mqtt_video" = true ] ; then
(
. /system/sdcard/config/mqtt.conf
@@ -205,6 +205,11 @@ if [ "$publish_mqtt_message" = true -o "$publish_mqtt_snapshot" = true ] ; then
/system/sdcard/bin/mosquitto_pub.bin -h "$HOST" -p "$PORT" -u "$USER" -P "$PASS" -t "$TOPIC"/motion $MOSQUITTOOPTS $MOSQUITTOPUBOPTS -m "ON"
fi
if [ "$publish_mqtt_video" = true ] ; then
debug_msg "Send MQTT video"
/system/sdcard/bin/mosquitto_pub.bin -h "$HOST" -p "$PORT" -u "$USER" -P "$PASS" -t "$TOPIC"/motion/video $MOSQUITTOOPTS $MOSQUITTOPUBOPTS -f "$video_tempfile"
fi
if [ "$publish_mqtt_snapshot" = true ] ; then
debug_msg "Send MQTT snapshot"
/system/sdcard/bin/jpegtran -scale 1/2 "$snapshot_tempfile" > "$snapshot_tempfile-s"

View File

@@ -325,7 +325,7 @@ if [ -n "$F_cmd" ]; then
auto_night_mode_stop)
/system/sdcard/controlscripts/auto-night-detection stop
;;
auto_night_mode_status)
auto_night_mode status
return
@@ -692,6 +692,21 @@ if [ -n "$F_cmd" ]; then
return
;;
motion_detection_mqtt_video_off)
motion_mqtt_video off
return
;;
motion_detection_mqtt_video_on)
motion_mqtt_video on
return
;;
motion_detection_mqtt_video_status)
motion_mqtt_video status
return
;;
show_HWmodel)
detect_model
return

View File

@@ -137,6 +137,15 @@ if [ -n "$F_cmd" ]; then
fi
;;
motion_mqtt_video)
. /system/sdcard/config/motion.conf 2> /dev/null
if [ "$publish_mqtt_video" == "true" ]; then
echo "ON"
else
echo "OFF"
fi
;;
hostname)
echo $(hostname);
;;

View File

@@ -211,7 +211,7 @@
<a id="network" class="navbar-item onpage" href="javascript: void(0)" data-target="cgi-bin/network.cgi">Network</a>
<a id="logs" class="navbar-item onpage" href="javascript: void(0)" data-target="logs.html">Logs</a>
</div>
</div>
</div>
</div>
<!-- right menu -->
@@ -319,6 +319,12 @@
data-unchecked="cgi-bin/action.cgi?cmd=motion_detection_mqtt_snapshot_off">
<label for="motion_mqtt_snapshot">Motion - MQTT Snapshot</label>
</span>
<!-- Motion: MQTT Message -->
<span class="navbar-item">
<input id="motion_mqtt_video" type="checkbox" name="motion_mqtt_video" class="switch" data-checked="cgi-bin/action.cgi?cmd=motion_detection_mqtt_video_on"
data-unchecked="cgi-bin/action.cgi?cmd=motion_detection_mqtt_video_off">
<label for="motion_mqtt_video">Motion - MQTT Video</label>
</span>
</div>
</div>
</div>

View File

@@ -3,7 +3,7 @@ var SWITCHES = [
"rtsp_h264", "rtsp_mjpeg", "auto_night_detection",
"mqtt_status", "mqtt_control",
"sound_on_startup", "motion_detection", "motion_mail", "motion_telegram",
"motion_led","motion_snapshot","motion_mqtt", "motion_mqtt_snapshot"];
"motion_led","motion_snapshot","motion_mqtt", "motion_mqtt_snapshot", "motion_mqtt_video"];
var timeoutJobs = {};
@@ -53,14 +53,14 @@ function showResult(txt) {
$(document).ready(function () {
setTheme(getThemeChoice());
// Set title page and menu with hostname
$.get("cgi-bin/state.cgi", {cmd: "hostname"}, function(title){document.title = title;document.getElementById("title").innerHTML = title;});
// Set git version to bottim page
$.get("cgi-bin/state.cgi", {cmd: "version"}, function(version){document.getElementById("version").innerHTML = version;});
// Load link into #content
$('.onpage').click(function () {
var e = $(this);