1
0
mirror of https://github.com/EliasKotlyar/Xiaomi-Dafang-Hacks.git synced 2025-09-03 13:12:44 +02:00

Merge branch 'beta'

This commit is contained in:
Julian Tatsch
2020-12-08 19:10:57 +01:00
13 changed files with 32 additions and 339 deletions

View File

@@ -1,8 +1,8 @@
ENABLE_OSD=true
OSD="%H:%M:%S %d.%m.%Y"
DISPLAY_AXIS=false
COLOR=3
SIZE=18
COLOR=0
SIZE=12
SPACE=
POSY=
FIXEDW=false

View File

@@ -1,123 +0,0 @@
#!/bin/sh
PIDFILE="/run/rtsp-h264.pid"
export LD_LIBRARY_PATH='/system/sdcard/lib/:/thirdlib:/system/lib'
if [ ! -f /system/sdcard/config/rtspserver.conf ]; then
cp /system/sdcard/config/rtspserver.conf.dist /system/sdcard/config/rtspserver.conf
fi
if [ -f /system/sdcard/config/rtspserver.conf ]; then
. /system/sdcard/config/rtspserver.conf
fi
if [ "$LOG" != true ] ; then
LOGPATH="/dev/null"
fi
if [ -f /system/sdcard/config/osd.conf ]; then
. /system/sdcard/config/osd.conf 2>/dev/null
fi
status()
{
pid="$(cat "$PIDFILE" 2>/dev/null)"
if [ "$pid" ]; then
# return current pid if pidfile exists and contained pid is alive
# return 1 if pidfile existed but the contained pid is dead
kill -0 "$pid" >/dev/null && echo "PID: $pid" || return 1
else
# return 2 if pidfile did not exist
return 2
fi
}
start()
{
if [ "$(status)" != "" ]; then
echo "A v4l2rtspserver is already running, please stop it or reboot"
else
echo "Starting v4l2rtspserver-master"
/system/sdcard/controlscripts/rtsp-mjpeg stop
## Configure OSD
if [ -f /system/sdcard/controlscripts/configureOsd ]; then
. /system/sdcard/controlscripts/configureOsd 2>/dev/null
fi
## Configure Motion
if [ -f /system/sdcard/controlscripts/configureMotion ]; then
. /system/sdcard/controlscripts/configureMotion 2>/dev/null
fi
## Bitrate
/system/sdcard/bin/setconf -k b -v ${BITRATE} 2>/dev/null
## Framerate
if [ "$FRAMERATE_DEN" != "" ] && [ "$FRAMERATE_NUM" != "" ]; then
/system/sdcard/bin/setconf -k d -v "$FRAMERATE_NUM,$FRAMERATE_DEN" 2>/dev/null
fi
## Audio
if [ "$AUDIOFORMAT" != "OFF" ] ; then
AUDIOPARAM="-E $AUDIOFORMAT:$AUDIOINBR:$AUDIOOUTBR"
/system/sdcard/bin/setconf -k h -v "$HWVOLUME" 2>/dev/null
/system/sdcard/bin/setconf -k i -v "$SWVOLUME" 2>/dev/null
/system/sdcard/bin/setconf -k q -v "$FILTER" 2>/dev/null
/system/sdcard/bin/setconf -k l -v "$HIGHPASSFILTER" 2>/dev/null
/system/sdcard/bin/setconf -k a -v "$AECFILTER" 2>/dev/null
else
AUDIOPARAM="-A"
fi
## Video format
if [ "$VIDEOFORMAT" != "" ]; then
VIDEOFORMAT="-r $VIDEOFORMAT -F $FRAMERATE_NUM"
fi
## UserName and password
if [ "$USERNAME" != "" ]; then
CREDENTIAL="-U $USERNAME:$USERPASSWORD"
fi
## Port
if [ "$PORT" != "" ]; then
PORT="-P $PORT"
fi
## Multicast
if [ "$MULTICASTDEST" != "" ]; then
MULTICASTDEST="-M $MULTICASTDEST"
fi
## FLIP
if [ "$FLIP" == "ON" ]; then
/system/sdcard/bin/setconf -k f -v 1
elif [ "$FLIP" == "OFF" ]; then
/system/sdcard/bin/setconf -k f -v 0
fi
echo "================== START ===============" >> "$LOGPATH"
echo "/system/sdcard/bin/v4l2rtspserver-master $RTSPOPTS $AUDIOPARAM $VIDEOFORMAT $CREDENTIAL $PORT $MULTICASTDEST" >> "$LOGPATH"
cd /system/sdcard/hls
/system/sdcard/bin/v4l2rtspserver-master $RTSPOPTS $AUDIOPARAM $VIDEOFORMAT $CREDENTIAL $PORT $MULTICASTDEST 2>> "$LOGPATH" >> "$LOGPATH" &
echo "$!" > "$PIDFILE"
fi
}
stop()
{
pid="$(cat "$PIDFILE" 2>/dev/null)"
if [ "$pid" ]; then
kill "$pid"
rm "$PIDFILE" 1> /dev/null 2>&1
fi
}
if [ $# -eq 0 ]; then
start
else
case $1 in start|stop|status)
$1
;;
esac
fi

View File

@@ -1,115 +0,0 @@
#!/bin/sh
PIDFILE="/run/rtsp-mpjeg.pid"
LOGDIR="/tmp"
LOGPATH="$LOGDIR/v4l2rtspserver-master.log"
export LD_LIBRARY_PATH='/system/sdcard/lib:/thirdlib:/system/lib'
if [ ! -f /system/sdcard/config/rtspserver.conf ]; then
cp /system/sdcard/config/rtspserver.conf.dist /system/sdcard/config/rtspserver.conf
fi
if [ -f /system/sdcard/config/rtspserver.conf ]; then
. /system/sdcard/config/rtspserver.conf
fi
if [ -f /system/sdcard/config/osd.conf ]; then
. /system/sdcard/config/osd.conf 2>/dev/null
fi
status()
{
pid="$(cat "$PIDFILE" 2>/dev/null)"
if [ "$pid" ]; then
# Prints PID: $pid if exists and returns 0(no error) else returns 1(error condition)
kill -0 "$pid" >/dev/null && echo "PID: $pid" || return 1
fi
}
start()
{
if [ "$(status)" != "" ]; then
echo "A v4l2rtspserver is already running, please stop it or reboot"
else
echo "Starting v4l2rtspserver-master with parameter -fMJPG"
/system/sdcard/controlscripts/rtsp-h264 stop
## Configure OSD
if [ -f /system/sdcard/controlscripts/configureOsd ]; then
. /system/sdcard/controlscripts/configureOsd 2>/dev/null
fi
## Configure Motion
if [ -f /system/sdcard/controlscripts/configureMotion ]; then
. /system/sdcard/controlscripts/configureMotion 2>/dev/null
fi
## Bitrate
/system/sdcard/bin/setconf -k b -v ${BITRATE} 2>/dev/null
## Framerate
if [ "$FRAMERATE_DEN" != "" ] && [ "$FRAMERATE_NUM" != "" ]; then
/system/sdcard/bin/setconf -k d -v "$FRAMERATE_NUM,$FRAMERATE_DEN" 2>/dev/null
fi
## Audio
if [ "$AUDIOFORMAT" != "OFF" ] ; then
AUDIOPARAM="-E $AUDIOFORMAT:$AUDIOINBR:$AUDIOOUTBR"
/system/sdcard/bin/setconf -k h -v "$HWVOLUME" 2>/dev/null
/system/sdcard/bin/setconf -k i -v "$SWVOLUME" 2>/dev/null
/system/sdcard/bin/setconf -k q -v "$FILTER" 2>/dev/null
/system/sdcard/bin/setconf -k l -v "$HIGHPASSFILTER" 2>/dev/null
/system/sdcard/bin/setconf -k a -v "$AECFILTER" 2>/dev/null
else
AUDIOPARAM="-A"
fi
## Video format
if [ "$VIDEOFORMAT" != "" ]; then
VIDEOFORMAT="-r $VIDEOFORMAT -F $FRAMERATE_NUM"
fi
## UserName and password
if [ "$USERNAME" != "" ]; then
CREDENTIAL="-U $USERNAME:$USERPASSWORD"
fi
## Port
if [ "$PORT" != "" ]; then
PORT="-P $PORT"
fi
## Multicast
if [ "$MULTICASTDEST" != "" ]; then
MULTICASTDEST="-M $MULTICASTDEST"
fi
## FLIP
if [ "$FLIP" == "ON" ]; then
/system/sdcard/bin/setconf -k f -v 1
elif [ "$FLIP" == "OFF" ]; then
/system/sdcard/bin/setconf -k f -v 0
fi
echo "================== START ===============" >> "$LOGPATH"
echo "/system/sdcard/bin/v4l2rtspserver-master -fMJPG $RTSPOPTS $AUDIOPARAM $VIDEOFORMAT $CREDENTIAL $PORT $MULTICASTDEST" >> "$LOGPATH"
/system/sdcard/bin/v4l2rtspserver-master -fMJPG $RTSPOPTS $AUDIOPARAM $VIDEOFORMAT $CREDENTIAL $PORT $MULTICASTDEST 2>> "$LOGPATH" >> "$LOGPATH" &
echo "$!" > "$PIDFILE"
fi
}
stop()
{
pid="$(cat "$PIDFILE" 2>/dev/null)"
if [ "$pid" ]; then
kill "$pid"
rm "$PIDFILE" 1> /dev/null 2>&1
fi
}
if [ $# -eq 0 ]; then
start
else
case $1 in start|stop|status)
$1
;;
esac
fi

View File

@@ -274,37 +274,18 @@ http_password(){
echo "$user:$realm:$hash" > /system/sdcard/config/lighttpd.user
}
# Control the RTSP h264 server
rtsp_h264_server(){
case "$1" in
on)
/system/sdcard/controlscripts/rtsp-h264 start
;;
off)
/system/sdcard/controlscripts/rtsp-h264 stop
;;
status)
if /system/sdcard/controlscripts/rtsp-h264 status | grep -q "PID"
then
echo "ON"
else
echo "OFF"
fi
;;
esac
}
# Control the RTSP mjpeg server
rtsp_mjpeg_server(){
# Control the RTSP server
rtsp_server(){
case "$1" in
on)
/system/sdcard/controlscripts/rtsp-mjpeg start
/system/sdcard/controlscripts/rtsp start
;;
off)
/system/sdcard/controlscripts/rtsp-mjpeg stop
/system/sdcard/controlscripts/rtsp stop
;;
status)
if /system/sdcard/controlscripts/rtsp-mjpeg status | grep -q "PID"
if /system/sdcard/controlscripts/rtsp status | grep -q "PID"
then
echo "ON"
else
@@ -836,4 +817,4 @@ getFonts() {
if [ "$fontName" == "$i" ] ; then echo selected; fi
echo -n ">`/system/sdcard/bin/busybox basename $i` </option>"
done
}
}

View File

@@ -65,9 +65,7 @@
$MQTT_COMMAND "$AUTODISCOVERY_PREFIX/switch/$DEVICE_NAME/auto_night_mode/config" ${MOSQUITTOPUBOPTS} ${MOSQUITTOOPTS} -r -m "{\"name\": \"$DEVICE_NAME night mode auto\", \"unique_id\": \"$MAC_SIMPLE-night-mode-auto\", $DEVICE_INFO, \"icon\": \"mdi:weather-night\", \"state_topic\": \"$TOPIC/night_mode/auto\", \"command_topic\": \"$TOPIC/night_mode/auto/set\"}"
# RTSP Server
$MQTT_COMMAND "$AUTODISCOVERY_PREFIX/switch/$DEVICE_NAME/rtsp_h264_server/config" ${MOSQUITTOPUBOPTS} ${MOSQUITTOOPTS} -r -m "{\"name\": \"$DEVICE_NAME h264 rtsp server\", \"unique_id\": \"$MAC_SIMPLE-h264-rtsp-server\", $DEVICE_INFO, \"icon\": \"mdi:cctv\", \"state_topic\": \"$TOPIC/rtsp_h264_server\", \"command_topic\": \"$TOPIC/rtsp_h264_server/set\"}"
$MQTT_COMMAND "$AUTODISCOVERY_PREFIX/switch/$DEVICE_NAME/rtsp_mjpeg_server/config" ${MOSQUITTOPUBOPTS} ${MOSQUITTOOPTS} -r -m "{\"name\": \"$DEVICE_NAME mjpeg rtsp server\", \"unique_id\": \"$MAC_SIMPLE-mjpeg-rtsp-server\", $DEVICE_INFO, \"icon\": \"mdi:cctv\", \"state_topic\": \"$TOPIC/rtsp_mjpeg_server\", \"command_topic\": \"$TOPIC/rtsp_mjpeg_server/set\"}"
$MQTT_COMMAND "$AUTODISCOVERY_PREFIX/switch/$DEVICE_NAME/rtsp_server/config" ${MOSQUITTOPUBOPTS} ${MOSQUITTOOPTS} -r -m "{\"name\": \"$DEVICE_NAME rtsp server\", \"unique_id\": \"$MAC_SIMPLE-rtsp-server\", $DEVICE_INFO, \"icon\": \"mdi:cctv\", \"state_topic\": \"$TOPIC/rtsp_server\", \"command_topic\": \"$TOPIC/rtsp_server/set\"}"
# Motor up/down/left/right
$MQTT_COMMAND "$AUTODISCOVERY_PREFIX/cover/$DEVICE_NAME/motor_up_down/config" ${MOSQUITTOPUBOPTS} ${MOSQUITTOOPTS} -r -m "{\"name\": \"$DEVICE_NAME move up/down\", \"unique_id\": \"$MAC_SIMPLE-move-up-down\", $DEVICE_INFO, \"set_position_topic\": \"$TOPIC/motors/vertical/set\", \"position_topic\": \"$TOPIC/motors/vertical\", \"command_topic\": \"$TOPIC/motors/vertical/set\", \"payload_close\": \"down\", \"payload_open\": \"up\", \"optimistic\": \"false\", \"value_template\": \"{{ ((value|int)/($MAX_Y/$STEP))|round }}\", \"set_position_template\": \"{{ ((position|int)*($MAX_Y/$STEP))|round }}\"}"

View File

@@ -111,32 +111,18 @@ done
fi
;;
"${TOPIC}/rtsp_h264_server")
/system/sdcard/bin/mosquitto_pub.bin -h "$HOST" -p "$PORT" -u "$USER" -P "$PASS" -t "${TOPIC}"/rtsp_h264_server ${MOSQUITTOPUBOPTS} ${MOSQUITTOOPTS} -m "$(rtsp_h264_server status)"
"${TOPIC}/rtsp_server")
/system/sdcard/bin/mosquitto_pub.bin -h "$HOST" -p "$PORT" -u "$USER" -P "$PASS" -t "${TOPIC}"/rtsp_server ${MOSQUITTOPUBOPTS} ${MOSQUITTOOPTS} -m "$(rtsp_server status)"
;;
"${TOPIC}/rtsp_h264_server/set ON")
rtsp_h264_server on
/system/sdcard/bin/mosquitto_pub.bin -h "$HOST" -p "$PORT" -u "$USER" -P "$PASS" -t "${TOPIC}"/rtsp_h264_server ${MOSQUITTOPUBOPTS} ${MOSQUITTOOPTS} -m "$(rtsp_h264_server status)"
"${TOPIC}/rtsp_server/set ON")
rtsp_server on
/system/sdcard/bin/mosquitto_pub.bin -h "$HOST" -p "$PORT" -u "$USER" -P "$PASS" -t "${TOPIC}"/rtsp_server ${MOSQUITTOPUBOPTS} ${MOSQUITTOOPTS} -m "$(rtsp_server status)"
;;
"${TOPIC}/rtsp_h264_server/set OFF")
rtsp_h264_server off
/system/sdcard/bin/mosquitto_pub.bin -h "$HOST" -p "$PORT" -u "$USER" -P "$PASS" -t "${TOPIC}"/rtsp_h264_server ${MOSQUITTOPUBOPTS} ${MOSQUITTOOPTS} -m "$(rtsp_h264_server status)"
;;
"${TOPIC}/rtsp_mjpeg_server")
/system/sdcard/bin/mosquitto_pub.bin -h "$HOST" -p "$PORT" -u "$USER" -P "$PASS" -t "${TOPIC}"/rtsp_mjpeg_server ${MOSQUITTOPUBOPTS} ${MOSQUITTOOPTS} -m "$(rtsp_mjpeg_server status)"
;;
"${TOPIC}/rtsp_mjpeg_server/set ON")
rtsp_mjpeg_server on
/system/sdcard/bin/mosquitto_pub.bin -h "$HOST" -p "$PORT" -u "$USER" -P "$PASS" -t "${TOPIC}"/rtsp_mjpeg_server ${MOSQUITTOPUBOPTS} ${MOSQUITTOOPTS} -m "$(rtsp_mjpeg_server status)"
;;
"${TOPIC}/rtsp_mjpeg_server/set OFF")
rtsp_mjpeg_server off
/system/sdcard/bin/mosquitto_pub.bin -h "$HOST" -p "$PORT" -u "$USER" -P "$PASS" -t "${TOPIC}"/rtsp_mjpeg_server ${MOSQUITTOPUBOPTS} ${MOSQUITTOOPTS} -m "$(rtsp_mjpeg_server status)"
"${TOPIC}/rtsp_server/set OFF")
rtsp_server off
/system/sdcard/bin/mosquitto_pub.bin -h "$HOST" -p "$PORT" -u "$USER" -P "$PASS" -t "${TOPIC}"/rtsp_server ${MOSQUITTOPUBOPTS} ${MOSQUITTOOPTS} -m "$(rtsp_server status)"
;;
"${TOPIC}/night_mode")

View File

@@ -21,8 +21,7 @@ do
/system/sdcard/bin/mosquitto_pub.bin -h "$HOST" -p "$PORT" -u "$USER" -P "$PASS" -t "${TOPIC}"/brightness ${MOSQUITTOPUBOPTS} ${MOSQUITTOOPTS} -r -m "$(exposure status)"
fi
/system/sdcard/bin/mosquitto_pub.bin -h "$HOST" -p "$PORT" -u "$USER" -P "$PASS" -t "${TOPIC}"/rtsp_h264_server ${MOSQUITTOPUBOPTS} ${MOSQUITTOOPTS} -r -m "$(rtsp_h264_server status)"
/system/sdcard/bin/mosquitto_pub.bin -h "$HOST" -p "$PORT" -u "$USER" -P "$PASS" -t "${TOPIC}"/rtsp_mjpeg_server ${MOSQUITTOPUBOPTS} ${MOSQUITTOOPTS} -r -m "$(rtsp_mjpeg_server status)"
/system/sdcard/bin/mosquitto_pub.bin -h "$HOST" -p "$PORT" -u "$USER" -P "$PASS" -t "${TOPIC}"/rtsp_server ${MOSQUITTOPUBOPTS} ${MOSQUITTOOPTS} -r -m "$(rtsp_server status)"
/system/sdcard/bin/mosquitto_pub.bin -h "$HOST" -p "$PORT" -u "$USER" -P "$PASS" -t "${TOPIC}"/night_mode ${MOSQUITTOPUBOPTS} ${MOSQUITTOOPTS} -r -m "$(night_mode status)"
/system/sdcard/bin/mosquitto_pub.bin -h "$HOST" -p "$PORT" -u "$USER" -P "$PASS" -t "${TOPIC}"/night_mode/auto ${MOSQUITTOPUBOPTS} ${MOSQUITTOOPTS} -r -m "$(auto_night_mode status)"
/system/sdcard/bin/mosquitto_pub.bin -h "$HOST" -p "$PORT" -u "$USER" -P "$PASS" -t "${TOPIC}"/motion/detection ${MOSQUITTOPUBOPTS} ${MOSQUITTOOPTS} -r -m "$(motion_detection status)"

View File

@@ -148,7 +148,7 @@ case "$F_cmd" in
ir_cut off
;;
ir_cut_status)
ir_cut_status)
ir_cut status
return
;;
@@ -187,35 +187,12 @@ ir_cut_status)
return
;;
h264_start)
/system/sdcard/controlscripts/rtsp-h264 start
;;
h264_noseg_start)
/system/sdcard/controlscripts/rtsp-h264 start
;;
mjpeg_start)
/system/sdcard/controlscripts/rtsp-mjpeg start
;;
h264_nosegmentation_start)
/system/sdcard/controlscripts/rtsp-h264 start
rtsp_start)
/system/sdcard/controlscripts/rtsp start
;;
rtsp_stop)
/system/sdcard/controlscripts/rtsp-mjpeg stop
/system/sdcard/controlscripts/rtsp-h264 stop
;;
h264_status)
rtsp_h264_server status
return
;;
mjpeg_status)
rtsp_mjpeg_server status
return
/system/sdcard/controlscripts/rtsp stop
;;
settz)

View File

@@ -81,12 +81,8 @@ if [ -n "$F_cmd" ]; then
echo $(night_mode status)
;;
rtsp_h264)
echo $(rtsp_h264_server status)
;;
rtsp_mjpeg)
echo $(rtsp_mjpeg_server status)
rtsp)
echo $(rtsp_server status)
;;
auto_night_detection)

View File

@@ -238,7 +238,7 @@ if [ -n "$F_cmd" ]; then
fi
if [ -n "${F_osdY+x}" ]; then
echo "POSY=${F_osdY}" >> /system/sdcard/config/osd.conf
system/sdcard/bin/setconf -k x -v "${F_osdY}"
/system/sdcard/bin/setconf -k x -v "${F_osdY}"
echo "Set OSD Y position to ${F_osdY}<br />"
fi
if [ -n "${F_osdFixW+x}" ]; then

View File

@@ -225,15 +225,10 @@ if [ -n "$F_cmd" ]; then
rewrite_config /system/sdcard/config/motion.conf region_of_interest $F_regions
echo "Regions set to $F_regions<br/>"
fi
if [ "$(rtsp_h264_server status)" = "ON" ]; then
echo "Restart H264 rtsp server"
rtsp_h264_server off
rtsp_h264_server on
fi
if [ "$(rtsp_mjpeg_server status)" = "ON" ]; then
echo "Restart MJPEG rtsp server"
rtsp_mjpeg_server off
rtsp_mjpeg_server on
if [ "$(rtsp_server status)" = "ON" ]; then
echo "Restarting rtsp server"
rtsp_server off
rtsp__server on
fi
;;
*)

View File

@@ -27,7 +27,7 @@
//Check if theme configured
var css = localStorage.getItem('theme')
if ( css == null )
css = "w3-theme-teal";
css = "w3-theme-night-blue";
$('head').append("<link rel='stylesheet' href='css/themes/"+css+".css'>");
$.get("cgi-bin/state.cgi", {cmd: "hostname"}, function(hostname){document.title = hostname;});
</script>

View File

@@ -2,7 +2,7 @@
### On the Home Assistant side
First let's set up your camera stream. Make sure the _rtsp-h264_ service in the _Services control panel_ is running and you can connect to it via a media player (like [VLC](https://www.videolan.org/)) using the address `rtsp://dafang:8554/unicast`.
First let's set up your camera stream. Make sure the _rtsp_ service in the _Services control panel_ is running and you can connect to it via a media player (like [VLC](https://www.videolan.org/)) using the address `rtsp://dafang:8554/unicast`.
![rtsp-h264](rtsp_h264.png)
@@ -85,8 +85,7 @@ To put all the sensors & actors conveniently into one group you can use the foll
```yaml
Dafang3:
- camera.dafang3
- switch.dafang3_h264_rtsp_server
- switch.dafang3_mjpeg_rtsp_server
- switch.dafang3_rtsp_server
- sensor.dafang3
- device_tracker.dafang3
- sensor.dafang3_light_sensor