Loading README.md +8 −1 Original line number Diff line number Diff line Loading @@ -2,9 +2,16 @@ Wi-Fi password: 12345678 ## Access Live stream: rtsp://192.168.42.1/live # Shoot Photo download: http://192.168.42.1:50422/20190417/IMG_20190417_164229.JPG Control (JSON): TCP 192.168.42.1:7878 ## Shoot ./shoot.sh Loading shoot.sh +140 −1 Original line number Diff line number Diff line { for f in commands/*; do cat "$f"; sleep 4; done } | nc 192.168.42.1 7878 #!/bin/bash #HOSTNAME="192.168.42.1" HOSTNAME="localhost" PORT="7878" set -e # fail on error #set -x # print executed commanads set -u # fail on invalid variable set -o pipefail # fail if any command in pipeline fails # create FIFOs if missing [ -p data_to_camera ] || mkfifo data_to_camera #{ for f in commands/*; do cat "$f"; sleep 4; done } | nc 192.168.42.1 7878 #{ # for i in $(seq 1 110); do # echo -n '{"rval":0,"msg_id":257,"param":2}{"rval":0,"msg_id":261,"param":"b6291d832eb3cbd92c724f32437e95c3","update":0}' | cut -c $i # sleep 0.05; # done # #} | { get_JSON() { while read -n1 char; do #echo -n $char >&2 RESPONSE="$RESPONSE$char" # find the end of the response (assuming non-balanced brackets do not appear e.g. inside strings) ... (proper JSON parsing would be needed) if [ "$char" == '{' ]; then OPEN_BRACKETS=$(expr $OPEN_BRACKETS + 1 || true) elif [ "$char" == '}' ]; then OPEN_BRACKETS=$(expr $OPEN_BRACKETS - 1 || true) if [ $OPEN_BRACKETS -eq 0 ]; then echo "Received JSON: $RESPONSE" >&2 # TODO: assert contains '"rval":0' echo "$RESPONSE" RESPONSE='' break fi fi done } commander() { RESPONSE='' OPEN_BRACKETS=0 # 01 Request a token/session id echo '{"msg_id":257,"token":0}' TOKEN="$(get_JSON | sed 's/.*"param":\([0-9][0-9]*\).*/\1/')" # TODO: assert is numeric # 02 something ??? echo '{"msg_id":4097,"token":'$TOKEN'}' DUMMY="$(get_JSON)" # 03 Get config echo '{"msg_id":1539,"token":'$TOKEN'}' DUMMY="$(get_JSON)" # 04 maybe start streaming ??? echo '{"param":"192.168.42.3","type":"TCP","msg_id":261,"token":'$TOKEN'}' DUMMY="$(get_JSON)" # 05 Get camera settings echo '{"msg_id":4365,"token":'$TOKEN'}' DUMMY="$(get_JSON)" # 06 set time and shoot echo '{"param":"2019-04-17-16-42-19-3","msg_id":6147,"token":'$TOKEN'}' DUMMY="$(get_JSON)" # 07 get sd status echo '{"msg_id":4358,"token":'$TOKEN'}' DUMMY="$(get_JSON)" # 08 get info echo '{"msg_id":4364,"token":'$TOKEN'}' DUMMY="$(get_JSON)" # 09 set path echo '{"param":"/tmp/SD0/DCIM/","msg_id":1283,"token":'$TOKEN'}' DUMMY="$(get_JSON)" # 10 get files echo '{"param":"/tmp/SD0/DCIM/","msg_id":1283,"token":'$TOKEN'}' DUMMY="$(get_JSON)" # 11 set path 2 echo '{"param":"/tmp/SD0/DCIM/20150101/","msg_id":1283,"token":'$TOKEN'}' DUMMY="$(get_JSON)" # 12 get files echo '{"msg_id":1282,"token":'$TOKEN'}' DUMMY="$(get_JSON)" # 13 set path echo '{"param":"/tmp/SD0/DCIM/20190417/","msg_id":1283,"token":'$TOKEN'}' DUMMY="$(get_JSON)" # 14 get files echo '{"msg_id":1282,"token":'$TOKEN'}' DUMMY="$(get_JSON)" # 15 get status echo '{"msg_id":4864,"token":'$TOKEN'}' DUMMY="$(get_JSON)" # 16 give me and maybe shoot echo '{"param":"/tmp/SD0/DCIM/20190417/IMG_20190417_164229.JPG","msg_id":1026,"token":'$TOKEN'}' DUMMY="$(get_JSON)" # 17 give me or generate thumbnail echo '{"param":"/tmp/SD0/DCIM/20190417/IMG_20190417_164229.JPG","type":"thumb","msg_id":1025,"token":'$TOKEN'}' DUMMY="$(get_JSON)" # 18 ??? echo '{"msg_id":6154,"token":'$TOKEN'}' DUMMY="$(get_JSON)" # 19 ??? echo '{"msg_id":6154,"token":'$TOKEN'}' DUMMY="$(get_JSON)" } # Do it... nc -v "$HOSTNAME" "$PORT" 0<data_to_camera | commander 1>data_to_camera || ( # TODO: handle known errors? (e.g. connection refused) echo Error $?; false ) echo "Yee!" Loading
README.md +8 −1 Original line number Diff line number Diff line Loading @@ -2,9 +2,16 @@ Wi-Fi password: 12345678 ## Access Live stream: rtsp://192.168.42.1/live # Shoot Photo download: http://192.168.42.1:50422/20190417/IMG_20190417_164229.JPG Control (JSON): TCP 192.168.42.1:7878 ## Shoot ./shoot.sh Loading
shoot.sh +140 −1 Original line number Diff line number Diff line { for f in commands/*; do cat "$f"; sleep 4; done } | nc 192.168.42.1 7878 #!/bin/bash #HOSTNAME="192.168.42.1" HOSTNAME="localhost" PORT="7878" set -e # fail on error #set -x # print executed commanads set -u # fail on invalid variable set -o pipefail # fail if any command in pipeline fails # create FIFOs if missing [ -p data_to_camera ] || mkfifo data_to_camera #{ for f in commands/*; do cat "$f"; sleep 4; done } | nc 192.168.42.1 7878 #{ # for i in $(seq 1 110); do # echo -n '{"rval":0,"msg_id":257,"param":2}{"rval":0,"msg_id":261,"param":"b6291d832eb3cbd92c724f32437e95c3","update":0}' | cut -c $i # sleep 0.05; # done # #} | { get_JSON() { while read -n1 char; do #echo -n $char >&2 RESPONSE="$RESPONSE$char" # find the end of the response (assuming non-balanced brackets do not appear e.g. inside strings) ... (proper JSON parsing would be needed) if [ "$char" == '{' ]; then OPEN_BRACKETS=$(expr $OPEN_BRACKETS + 1 || true) elif [ "$char" == '}' ]; then OPEN_BRACKETS=$(expr $OPEN_BRACKETS - 1 || true) if [ $OPEN_BRACKETS -eq 0 ]; then echo "Received JSON: $RESPONSE" >&2 # TODO: assert contains '"rval":0' echo "$RESPONSE" RESPONSE='' break fi fi done } commander() { RESPONSE='' OPEN_BRACKETS=0 # 01 Request a token/session id echo '{"msg_id":257,"token":0}' TOKEN="$(get_JSON | sed 's/.*"param":\([0-9][0-9]*\).*/\1/')" # TODO: assert is numeric # 02 something ??? echo '{"msg_id":4097,"token":'$TOKEN'}' DUMMY="$(get_JSON)" # 03 Get config echo '{"msg_id":1539,"token":'$TOKEN'}' DUMMY="$(get_JSON)" # 04 maybe start streaming ??? echo '{"param":"192.168.42.3","type":"TCP","msg_id":261,"token":'$TOKEN'}' DUMMY="$(get_JSON)" # 05 Get camera settings echo '{"msg_id":4365,"token":'$TOKEN'}' DUMMY="$(get_JSON)" # 06 set time and shoot echo '{"param":"2019-04-17-16-42-19-3","msg_id":6147,"token":'$TOKEN'}' DUMMY="$(get_JSON)" # 07 get sd status echo '{"msg_id":4358,"token":'$TOKEN'}' DUMMY="$(get_JSON)" # 08 get info echo '{"msg_id":4364,"token":'$TOKEN'}' DUMMY="$(get_JSON)" # 09 set path echo '{"param":"/tmp/SD0/DCIM/","msg_id":1283,"token":'$TOKEN'}' DUMMY="$(get_JSON)" # 10 get files echo '{"param":"/tmp/SD0/DCIM/","msg_id":1283,"token":'$TOKEN'}' DUMMY="$(get_JSON)" # 11 set path 2 echo '{"param":"/tmp/SD0/DCIM/20150101/","msg_id":1283,"token":'$TOKEN'}' DUMMY="$(get_JSON)" # 12 get files echo '{"msg_id":1282,"token":'$TOKEN'}' DUMMY="$(get_JSON)" # 13 set path echo '{"param":"/tmp/SD0/DCIM/20190417/","msg_id":1283,"token":'$TOKEN'}' DUMMY="$(get_JSON)" # 14 get files echo '{"msg_id":1282,"token":'$TOKEN'}' DUMMY="$(get_JSON)" # 15 get status echo '{"msg_id":4864,"token":'$TOKEN'}' DUMMY="$(get_JSON)" # 16 give me and maybe shoot echo '{"param":"/tmp/SD0/DCIM/20190417/IMG_20190417_164229.JPG","msg_id":1026,"token":'$TOKEN'}' DUMMY="$(get_JSON)" # 17 give me or generate thumbnail echo '{"param":"/tmp/SD0/DCIM/20190417/IMG_20190417_164229.JPG","type":"thumb","msg_id":1025,"token":'$TOKEN'}' DUMMY="$(get_JSON)" # 18 ??? echo '{"msg_id":6154,"token":'$TOKEN'}' DUMMY="$(get_JSON)" # 19 ??? echo '{"msg_id":6154,"token":'$TOKEN'}' DUMMY="$(get_JSON)" } # Do it... nc -v "$HOSTNAME" "$PORT" 0<data_to_camera | commander 1>data_to_camera || ( # TODO: handle known errors? (e.g. connection refused) echo Error $?; false ) echo "Yee!"