Skip to content

Commit

Permalink
fix mqtt autoconfig start, add motion tracking switch
Browse files Browse the repository at this point in the history
  • Loading branch information
jmtatsch committed Apr 14, 2018
1 parent ffe4eba commit a591ee8
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 22 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,4 @@ firmware_mod/config/wpa_supplicant.conf
firmware_mod/System Volume Information/IndexerVolumeGuid
firmware_mod/System Volume Information/WPSettings.dat
firmware_mod/config/motion.conf
firmware_mod/config/mqtt.conf
1 change: 1 addition & 0 deletions firmware_mod/controlscripts/mqtt-control
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ start()
elif [ ! -f /system/sdcard/config/mqtt.conf ]; then
echo "You have to configure mqtt first. Please see /system/sdcard/config/mqtt.dist for further instructions"
else
. /system/sdcard/config/mqtt.conf
if [ -z ${AUTODISCOVERY_PREFIX+x} ];
then echo "MQTT autodiscovery is not enabled";
else
Expand Down
22 changes: 22 additions & 0 deletions firmware_mod/scripts/common_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,28 @@ motion_detection(){
esac
}

# Control the motion tracking function
motion_tracking(){
case "$1" in
on)
/system/sdcard/bin/setconf -k t -v on
;;
off)
/system/sdcard/bin/setconf -k t -v off
;;
status)
status=$(/system/sdcard/bin/setconf -g t 2>/dev/null)
case $status in
true)
echo "ON"
;;
*)
echo "OFF"
;;
esac
esac
}

# Control the night mode
night_mode(){
case "$1" in
Expand Down
19 changes: 11 additions & 8 deletions firmware_mod/scripts/mqtt-autodiscovery.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
#!/bin/sh

source /system/sdcard/config/mqtt.conf
source /system/sdcard/scripts/common_functions.sh
. /system/sdcard/config/mqtt.conf
. /system/sdcard/scripts/common_functions.sh

# Motion sensor
/system/sdcard/bin/mosquitto_pub.bin -h "$HOST" -u "$USER" -P "$PASS" -t "$AUTODISCOVERY_PREFIX/binary_sensor/$DEVICE_NAME/motion/config" ${MOSQUITTOPUBOPTS} ${MOSQUITTOOPTS} -m "{\"name\": \"$DEVICE_NAME motion sensor\", \"icon\": \"mdi:run\", \"state_topic\": \"$TOPIC/motion\", \"device_class\": \"motion\"}"

# Motion detection
# Motion detection on/off switch
/system/sdcard/bin/mosquitto_pub.bin -h "$HOST" -u "$USER" -P "$PASS" -t "$AUTODISCOVERY_PREFIX/switch/$DEVICE_NAME/motion_detection/config" ${MOSQUITTOPUBOPTS} ${MOSQUITTOOPTS} -m "{\"name\": \"$DEVICE_NAME motion detection\", \"icon\": \"mdi:run\", \"state_topic\": \"$TOPIC/motion/detection\", \"command_topic\": \"$TOPIC/motion/detection/set\"}"

# Motion detection snapshots
/system/sdcard/bin/mosquitto_pub.bin -h "$HOST" -u "$USER" -P "$PASS" -t "$AUTODISCOVERY_PREFIX/camera/$DEVICE_NAME/motion_snapshots/config" ${MOSQUITTOPUBOPTS} ${MOSQUITTOOPTS} -m "{\"name\": \"$DEVICE_NAME motion snapshots\", \"topic\": \"$TOPIC/motion_snapshots\"}"

# Motion tracking on/off switch
/system/sdcard/bin/mosquitto_pub.bin -h "$HOST" -u "$USER" -P "$PASS" -t "$AUTODISCOVERY_PREFIX/switch/$DEVICE_NAME/motion_tracking/config" ${MOSQUITTOPUBOPTS} ${MOSQUITTOOPTS} -m "{\"name\": \"$DEVICE_NAME motion tracking\", \"icon\": \"mdi:run\", \"state_topic\": \"$TOPIC/motion/tracking\", \"command_topic\": \"$TOPIC/motion/tracking/set\"}"

# LEDs
/system/sdcard/bin/mosquitto_pub.bin -h "$HOST" -u "$USER" -P "$PASS" -t "$AUTODISCOVERY_PREFIX/switch/$DEVICE_NAME/blue_led/config" ${MOSQUITTOPUBOPTS} ${MOSQUITTOOPTS} -m "{\"name\": \"$DEVICE_NAME blue led\", \"icon\": \"mdi:led-on\", \"state_topic\": \"$TOPIC/leds/blue\", \"command_topic\": \"$TOPIC/leds/blue/set\"}"
/system/sdcard/bin/mosquitto_pub.bin -h "$HOST" -u "$USER" -P "$PASS" -t "$AUTODISCOVERY_PREFIX/switch/$DEVICE_NAME/yellow_led/config" ${MOSQUITTOPUBOPTS} ${MOSQUITTOOPTS} -m "{\"name\": \"$DEVICE_NAME yellow led\", \"icon\": \"mdi:led-on\", \"state_topic\": \"$TOPIC/leds/yellow\", \"command_topic\": \"$TOPIC/leds/yellow/set\"}"
Expand All @@ -23,11 +29,8 @@ source /system/sdcard/scripts/common_functions.sh
# Night mode
/system/sdcard/bin/mosquitto_pub.bin -h "$HOST" -u "$USER" -P "$PASS" -t "$AUTODISCOVERY_PREFIX/switch/$DEVICE_NAME/night_mode/config" ${MOSQUITTOPUBOPTS} ${MOSQUITTOOPTS} -m "{\"name\": \"$DEVICE_NAME night mode\", \"icon\": \"mdi:weather-night\", \"state_topic\": \"$TOPIC/night_mode\", \"command_topic\": \"$TOPIC/night_mode/set\"}"

# Auto Night mode
/system/sdcard/bin/mosquitto_pub.bin -h "$HOST" -u "$USER" -P "$PASS" -t "$AUTODISCOVERY_PREFIX/switch/$DEVICE_NAME/auto_night_mode/config" ${MOSQUITTOPUBOPTS} ${MOSQUITTOOPTS} -m "{\"name\": \"$DEVICE_NAME auto night mode\", \"icon\": \"mdi:weather-night\", \"state_topic\": \"$TOPIC/auto_night_mode\", \"command_topic\": \"$TOPIC/auto_night_mode/set\"}"
# Night mode automatic
/system/sdcard/bin/mosquitto_pub.bin -h "$HOST" -u "$USER" -P "$PASS" -t "$AUTODISCOVERY_PREFIX/switch/$DEVICE_NAME/auto_night_mode/config" ${MOSQUITTOPUBOPTS} ${MOSQUITTOOPTS} -m "{\"name\": \"$DEVICE_NAME night mode auto\", \"icon\": \"mdi:weather-night\", \"state_topic\": \"$TOPIC/night_mode/auto\", \"command_topic\": \"$TOPIC/night_mode/auto/set\"}"

# RTSP Server
/system/sdcard/bin/mosquitto_pub.bin -h "$HOST" -u "$USER" -P "$PASS" -t "$AUTODISCOVERY_PREFIX/switch/$DEVICE_NAME/rtsp_server/config" ${MOSQUITTOPUBOPTS} ${MOSQUITTOOPTS} -m "{\"name\": \"$DEVICE_NAME rtsp server\", \"icon\": \"mdi:cctv\", \"state_topic\": \"$TOPIC/rtsp_server\", \"command_topic\": \"$TOPIC/rtsp_server/set\"}"

# Motion Snapshots (soon supported with auto autodiscovery)
/system/sdcard/bin/mosquitto_pub.bin -h "$HOST" -u "$USER" -P "$PASS" -t "$AUTODISCOVERY_PREFIX/camera/$DEVICE_NAME/motion_snapshots/config" ${MOSQUITTOPUBOPTS} ${MOSQUITTOOPTS} -m "{\"name\": \"$DEVICE_NAME motion snapshots\", \"topic\": \"$TOPIC/motion_snapshots\"}"
30 changes: 22 additions & 8 deletions firmware_mod/scripts/mqtt-control.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh

source /system/sdcard/config/mqtt.conf
source /system/sdcard/scripts/common_functions.sh
. /system/sdcard/config/mqtt.conf
. /system/sdcard/scripts/common_functions.sh

killall mosquitto_sub 2> /dev/null
killall mosquitto_sub.bin 2> /dev/null
Expand Down Expand Up @@ -104,18 +104,18 @@ killall mosquitto_sub.bin 2> /dev/null
/system/sdcard/bin/mosquitto_pub.bin -h "$HOST" -u "$USER" -P "$PASS" -t "${TOPIC}"/night_mode ${MOSQUITTOPUBOPTS} ${MOSQUITTOOPTS} -m "$(night_mode status)"
;;

"${TOPIC}/auto_night_mode")
/system/sdcard/bin/mosquitto_pub.bin -h "$HOST" -u "$USER" -P "$PASS" -t "${TOPIC}"/auto_night_mode ${MOSQUITTOPUBOPTS} ${MOSQUITTOOPTS} -m "$(auto_night_mode status)"
"${TOPIC}/night_mode/auto")
/system/sdcard/bin/mosquitto_pub.bin -h "$HOST" -u "$USER" -P "$PASS" -t "${TOPIC}"/night_mode/auto ${MOSQUITTOPUBOPTS} ${MOSQUITTOOPTS} -m "$(auto_night_mode status)"
;;

"${TOPIC}/auto_night_mode/set ON")
"${TOPIC}/night_mode/auto/set ON")
auto_night_mode on
/system/sdcard/bin/mosquitto_pub.bin -h "$HOST" -u "$USER" -P "$PASS" -t "${TOPIC}"/auto_night_mode ${MOSQUITTOPUBOPTS} ${MOSQUITTOOPTS} -m "$(auto_night_mode status)"
/system/sdcard/bin/mosquitto_pub.bin -h "$HOST" -u "$USER" -P "$PASS" -t "${TOPIC}"/night_mode/auto ${MOSQUITTOPUBOPTS} ${MOSQUITTOOPTS} -m "$(auto_night_mode status)"
;;

"${TOPIC}/auto_night_mode/set OFF")
"${TOPIC}/night_mode/auto/set OFF")
auto_night_mode off
/system/sdcard/bin/mosquitto_pub.bin -h "$HOST" -u "$USER" -P "$PASS" -t "${TOPIC}"/auto_night_mode ${MOSQUITTOPUBOPTS} ${MOSQUITTOOPTS} -m "$(auto_night_mode status)"
/system/sdcard/bin/mosquitto_pub.bin -h "$HOST" -u "$USER" -P "$PASS" -t "${TOPIC}"/night_mode/auto ${MOSQUITTOPUBOPTS} ${MOSQUITTOOPTS} -m "$(auto_night_mode status)"
;;

"${TOPIC}/motion/detection")
Expand All @@ -132,6 +132,20 @@ killall mosquitto_sub.bin 2> /dev/null
/system/sdcard/bin/mosquitto_pub.bin -h "$HOST" -u "$USER" -P "$PASS" -t "${TOPIC}"/motion/detection ${MOSQUITTOPUBOPTS} ${MOSQUITTOOPTS} -m "$(motion_detection status)"
;;

"${TOPIC}/motion/tracking")
/system/sdcard/bin/mosquitto_pub.bin -h "$HOST" -u "$USER" -P "$PASS" -t "${TOPIC}"/motion/tracking ${MOSQUITTOPUBOPTS} ${MOSQUITTOOPTS} -m "$(motion_tracking status)"
;;

"${TOPIC}/motion/tracking/set ON")
motion_tracking on
/system/sdcard/bin/mosquitto_pub.bin -h "$HOST" -u "$USER" -P "$PASS" -t "${TOPIC}"/motion/tracking ${MOSQUITTOPUBOPTS} ${MOSQUITTOOPTS} -m "$(motion_tracking status)"
;;

"${TOPIC}/motion/tracking/set OFF")
motion_tracking off
/system/sdcard/bin/mosquitto_pub.bin -h "$HOST" -u "$USER" -P "$PASS" -t "${TOPIC}"/motion/tracking ${MOSQUITTOPUBOPTS} ${MOSQUITTOOPTS} -m "$(motion_tracking status)"
;;

"${TOPIC}/set "*)
COMMAND=$(echo "$line" | awk '{print $2}')
#echo "$COMMAND"
Expand Down
7 changes: 4 additions & 3 deletions firmware_mod/scripts/mqtt-status-interval.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh
source /system/sdcard/config/mqtt.conf
source /system/sdcard/scripts/common_functions.sh
. /system/sdcard/config/mqtt.conf
. /system/sdcard/scripts/common_functions.sh

if [ "$STATUSINTERVAL" -lt 30 ]; then
STATUSINTERVAL=30
Expand All @@ -15,8 +15,9 @@ do
/system/sdcard/bin/mosquitto_pub.bin -h "$HOST" -u "$USER" -P "$PASS" -t "${TOPIC}"/brightness ${MOSQUITTOPUBOPTS} ${MOSQUITTOOPTS} -m "$(ldr status)"
/system/sdcard/bin/mosquitto_pub.bin -h "$HOST" -u "$USER" -P "$PASS" -t "${TOPIC}"/rtsp_server ${MOSQUITTOPUBOPTS} ${MOSQUITTOOPTS} -m "$(rtsp_server status)"
/system/sdcard/bin/mosquitto_pub.bin -h "$HOST" -u "$USER" -P "$PASS" -t "${TOPIC}"/night_mode ${MOSQUITTOPUBOPTS} ${MOSQUITTOOPTS} -m "$(night_mode status)"
/system/sdcard/bin/mosquitto_pub.bin -h "$HOST" -u "$USER" -P "$PASS" -t "${TOPIC}"/auto_night_mode ${MOSQUITTOPUBOPTS} ${MOSQUITTOOPTS} -m "$(auto_night_mode status)"
/system/sdcard/bin/mosquitto_pub.bin -h "$HOST" -u "$USER" -P "$PASS" -t "${TOPIC}"/night_mode/auto ${MOSQUITTOPUBOPTS} ${MOSQUITTOOPTS} -m "$(auto_night_mode status)"
/system/sdcard/bin/mosquitto_pub.bin -h "$HOST" -u "$USER" -P "$PASS" -t "${TOPIC}"/motion/detection ${MOSQUITTOPUBOPTS} ${MOSQUITTOOPTS} -m "$(motion_detection status)"
/system/sdcard/bin/mosquitto_pub.bin -h "$HOST" -u "$USER" -P "$PASS" -t "${TOPIC}"/motion/tracking ${MOSQUITTOPUBOPTS} ${MOSQUITTOOPTS} -m "$(motion_tracking status)"
/system/sdcard/bin/mosquitto_pub.bin -h "$HOST" -u "$USER" -P "$PASS" -t "${TOPIC}" ${MOSQUITTOOPTS} ${MOSQUITTOPUBOPTS} -m "$(/system/sdcard/scripts/mqtt-status.sh)"
sleep $STATUSINTERVAL
done
6 changes: 3 additions & 3 deletions firmware_mod/scripts/mqtt-status.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh
source /system/sdcard/config/mqtt.conf
source /system/sdcard/scripts/common_functions.sh
. /system/sdcard/config/mqtt.conf
. /system/sdcard/scripts/common_functions.sh

## Uptime
uptime=$(/system/sdcard/bin/busybox uptime)
Expand All @@ -13,4 +13,4 @@ noise_level=$(echo "$quality" | awk '{ print $6}' | sed -e 's/.*=//' | sed -e 's
link_quality=$(echo "$quality" | awk '{ print $2}' | sed -e 's/.*=//' | sed -e 's/\/100/\%/')
signal_level=$(echo "$quality" | awk '{ print $4}' | sed -e 's/.*=//' | sed -e 's/\/100/\%/')

echo "{\"uptime\":\"$uptime\", \"rtsp_server\":\"$(rtsp_server status)\", \"motion_detection\":\"$(motion_detection status)\", \"ssid\":\"$ssid\", \"bitrate\":\"$bitrate\", \"signal_level\":\"$signal_level\", \"link_quality\":\"$link_quality\", \"noise_level\":\"$noise_level\", \"blue_led\":\"$(blue_led status)\", \"yellow_led\":\"$(yellow_led status)\", \"ir_led\":\"$(ir_led status)\", \"ir_cut\":\"$(ir_cut status)\", \"ldr\":\"$(ldr status)\", \"night_mode\":\"$(night_mode status)\", \"auto_night_mode\":\"$(auto_night_mode status)\"}"
echo "{\"uptime\":\"$uptime\", \"ssid\":\"$ssid\", \"bitrate\":\"$bitrate\", \"signal_level\":\"$signal_level\", \"link_quality\":\"$link_quality\", \"noise_level\":\"$noise_level\" }"
5 changes: 5 additions & 0 deletions firmware_mod/www/cgi-bin/state.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ if [ -n "$F_cmd" ]; then
motion_detection)
echo $(motion_detection status)
;;

motion_tracking)
echo $(motion_tracking status)
;;

*)
echo "Unsupported command '$F_cmd'"
;;
Expand Down

0 comments on commit a591ee8

Please sign in to comment.