Skip to content

Instantly share code, notes, and snippets.

@jcconnell
Last active December 19, 2024 18:48
Show Gist options
  • Select an option

  • Save jcconnell/e4df5d71c68e67fd89b1d3573d762008 to your computer and use it in GitHub Desktop.

Select an option

Save jcconnell/e4df5d71c68e67fd89b1d3573d762008 to your computer and use it in GitHub Desktop.

Revisions

  1. jcconnell renamed this gist Sep 9, 2021. 1 changed file with 0 additions and 0 deletions.
  2. jcconnell revised this gist Sep 9, 2021. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions List of Interesting Commands
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    # Works Through telnet!
    # Disable IR Illumination (Cuts down IR illumination)
    /home/sendMq 0x10 1 0x1141 0`
    /home/sendMq 0x10 1 0x1141 0

    # Enable IR Illumination (Cut the IR illumination)
    /home/sendMq 0x10 1 0x1140 1
    @@ -9,7 +9,7 @@
    /home/sendMq 0x10 1 0x1147 0

    # Disable IR Filter (Cuts IR filter)
    `/home/sendMq 0x10 1 0x1146 1`
    /home/sendMq 0x10 1 0x1146 1

    # Flip the image
    vi /etc/ui.conf'
  3. jcconnell revised this gist Sep 9, 2021. 1 changed file with 24 additions and 11 deletions.
    35 changes: 24 additions & 11 deletions List of Interesting Commands
    Original file line number Diff line number Diff line change
    @@ -1,22 +1,35 @@
    Works Through telnet!
    Cuts down IR illumination
    `/home/sendMq 0x10 1 0x1141 0`
    # Works Through telnet!
    # Disable IR Illumination (Cuts down IR illumination)
    /home/sendMq 0x10 1 0x1141 0`

    Cut the IR illumination
    `/home/sendMq 0x10 1 0x1140 1`
    # Enable IR Illumination (Cut the IR illumination)
    /home/sendMq 0x10 1 0x1140 1

    IR cut filter
    `/home/sendMq 0x10 1 0x1147 0`
    # Enable IR Filter (IR cut filter)
    /home/sendMq 0x10 1 0x1147 0

    Cuts IR filter
    # Disable IR Filter (Cuts IR filter)
    `/home/sendMq 0x10 1 0x1146 1`

    Flip the image
    ```vi /etc/ui.conf'
    # Flip the image
    vi /etc/ui.conf'
    # Change ptz_hflip=0 to ptz_hflip=1
    sync
    reboot
    ```

    # Note: When making changes to /etc/ui.conf, these steps may be required:
    /home/killapp.sh
    sync
    vi /etc/ui.conf
    # make edit (see above)
    sync
    reboot

    # Night Vision IR Light is wrHdThreadKB in /etc/ui.conf.
    # 2=Off 1=On

    # LED Control
    /home/led_ctl -boff -yoff &

    Focusing the image:
    - http://4pda.ru/forum/index.php?showtopic=638230&view=findpost&p=40302353
  4. jcconnell revised this gist May 16, 2019. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions check_motion.sh
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,6 @@
    # Modified version of script from @airdrummingfool
    # Sends JSON payload to Home Assistant to emulate MQTT
    # Works with https://github.com/npetrovski/yi-hack-easy
    # crontab entry: @reboot /home/script/check_motion.sh > /dev/null 2>$1 &
    #
    # Description
    # Every 20 seconds, check for files modified since we last checked
    @@ -20,22 +19,23 @@ sleep 5 # since we /just/ created last_motion_check, the first check can return
    while true; do
    #echo "Checking for motion at `date`..."
    has_motion=$([ -z "`find . -type f -name "*.mp4*" -newer last_motion_check.txt`" ] && echo "false" || echo "true")
    echo `date +%s` > last_motion_check.txt
    echo `date '+%m-%d %I:%M%p'` > last_motion_check.txt

    # is mp4record running?
    armed=$(ps | grep mp4record | grep -v grep -q && echo "true" || echo "false")

    # Start of motion notification
    body=$(cat <<END
    {"payload":"{\"camera\":\"$(hostname)\",\"motion\":\"$has_motion\",\"last_motion_check\":\"$(cat last_motion_check.txt)\",\"date\":\"$(date +%F)\",\"time\":\"$(date +%I:%M%p)\"}","topic":"$topic","qos":"0"
    {"payload":"{\"camera\":\"$(hostname)\",\"motion\":\"$has_motion\",\"last_motion_check\":\"$(cat last_motion_check.txt)\",\"date\":\"$(date +%F)\",\"time\":\"$(date +%I:%M%p)\",\"armed\":\"$armed\"}","topic":"$topic","qos":"0","retain":"0"}
    END
    )

    # Build Curl command
    /home/curl --insecure -X POST -H "x-ha-access: $homeassistant_password" -H "Content-Type: application/json" --data "$body" "$homeassistant_url" --silent --show-error --stderr - -o /dev/null

    ip=$(ip addr | grep 'ra0' | grep 'inet' | awk '{print $2}' | cut -f1 -d'/')
    motion_file=$(find . -type f -name "*.mp4" -mmin -1 | tail -1)
    touch /home/hd1/record/motion.txt
    echo $motion_file | sed "s/.\//record\//" > /home/hd1/record/motion.txt
    touch /home/hd1/record/motion.html
    [ -z "$motion_file" ] || echo $motion_file | sed "s/.\//record\//" | echo '<a href='$motion_file'>'$motion_file'</a>' > /home/hd1/record/motion.html
    sleep 20
    done
  5. jcconnell revised this gist May 16, 2019. 1 changed file with 16 additions and 0 deletions.
    16 changes: 16 additions & 0 deletions run_check_motion.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    #!/bin/sh
    # Cron entry
    # * * * * * /home/script/run_check_motion.sh

    mkdir -p "/home/script/tmp"
    PIDFILE="/home/script/tmp/check_motion.pid"

    if [ -e "${PIDFILE}" ] && (ps |
    grep -P "^\s*$(cat ${PIDFILE})$" &> /dev/null); then
    exit 99
    fi

    /home/script/check_motion.sh &

    echo $! > "${PIDFILE}"
    chmod 644 "${PIDFILE}"
  6. jcconnell revised this gist May 16, 2019. No changes.
  7. jcconnell revised this gist May 16, 2019. 1 changed file with 6 additions and 1 deletion.
    7 changes: 6 additions & 1 deletion check_motion.sh
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,14 @@
    #!/bin/sh
    # Modified version of script from @airdrummingfool
    # Sends JSON payload to Home Assistant to emulate MQTT
    # Works with https://github.com/npetrovski/yi-hack-easy
    # crontab entry: @reboot /home/script/check_motion.sh > /dev/null 2>$1 &
    #
    # Description
    # Every 20 seconds, check for files modified since we last checked
    # if there is activity, it means motion was recently detected
    # Since file writes begin immediately on motion detected, and don't end until approx 1min after motion ends, we only need to look for files modified very recently
    # Relies on running mp4record process
    # Relies on running mp4record process if armed variable is important to you

    homeassistant_url="https://hass.example.com/api/services/mqtt/publish"
    homeassistant_password="Example-HA-Password"
  8. jcconnell revised this gist May 16, 2019. 1 changed file with 36 additions and 0 deletions.
    36 changes: 36 additions & 0 deletions check_motion.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    #!/bin/sh
    # Modified version of script from @airdrummingfool
    # Every 20 seconds, check for files modified since we last checked
    # if there is activity, it means motion was recently detected
    # Since file writes begin immediately on motion detected, and don't end until approx 1min after motion ends, we only need to look for files modified very recently
    # Relies on running mp4record process

    homeassistant_url="https://hass.example.com/api/services/mqtt/publish"
    homeassistant_password="Example-HA-Password"
    topic="homeassistant/example-ha-topic"

    cd /home/hd1/record/ || exit
    touch last_motion_check.txt
    sleep 5 # since we /just/ created last_motion_check, the first check can return a false negative unless we wait a beat
    while true; do
    #echo "Checking for motion at `date`..."
    has_motion=$([ -z "`find . -type f -name "*.mp4*" -newer last_motion_check.txt`" ] && echo "false" || echo "true")
    echo `date +%s` > last_motion_check.txt

    # is mp4record running?
    armed=$(ps | grep mp4record | grep -v grep -q && echo "true" || echo "false")

    # Start of motion notification
    body=$(cat <<END
    {"payload":"{\"camera\":\"$(hostname)\",\"motion\":\"$has_motion\",\"last_motion_check\":\"$(cat last_motion_check.txt)\",\"date\":\"$(date +%F)\",\"time\":\"$(date +%I:%M%p)\"}","topic":"$topic","qos":"0"
    END
    )

    # Build Curl command
    /home/curl --insecure -X POST -H "x-ha-access: $homeassistant_password" -H "Content-Type: application/json" --data "$body" "$homeassistant_url" --silent --show-error --stderr - -o /dev/null

    motion_file=$(find . -type f -name "*.mp4" -mmin -1 | tail -1)
    touch /home/hd1/record/motion.txt
    echo $motion_file | sed "s/.\//record\//" > /home/hd1/record/motion.txt
    sleep 20
    done
  9. jcconnell revised this gist May 15, 2019. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion List of Interesting Commands
    Original file line number Diff line number Diff line change
    @@ -16,4 +16,8 @@ Flip the image
    # Change ptz_hflip=0 to ptz_hflip=1
    sync
    reboot
    ```
    ```

    Focusing the image:
    - http://4pda.ru/forum/index.php?showtopic=638230&view=findpost&p=40302353
    - http://4pda.ru/forum/index.php?showtopic=638230&view=findpost&p=47551927
  10. jcconnell created this gist May 15, 2019.
    19 changes: 19 additions & 0 deletions List of Interesting Commands
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,19 @@
    Works Through telnet!
    Cuts down IR illumination
    `/home/sendMq 0x10 1 0x1141 0`

    Cut the IR illumination
    `/home/sendMq 0x10 1 0x1140 1`

    IR cut filter
    `/home/sendMq 0x10 1 0x1147 0`

    Cuts IR filter
    `/home/sendMq 0x10 1 0x1146 1`

    Flip the image
    ```vi /etc/ui.conf'
    # Change ptz_hflip=0 to ptz_hflip=1
    sync
    reboot
    ```