Skip to content

Instantly share code, notes, and snippets.

@mherwig
Last active December 11, 2015 09:49
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mherwig/4582545 to your computer and use it in GitHub Desktop.
Save mherwig/4582545 to your computer and use it in GitHub Desktop.
HttpImage is set of tools for sending photos to devices like tablets or phone via HTTP. There is an android app for receiving and displaying photos and there is an optional shell script that is able to send photos to these android devices right after you take a photo with a camera connected to your PC or your Raspberry Pi
#!/bin/bash
#
# USB fix for Raspberry PI, it wrapps gphoto2
# tested on Raspbian
dev=`gphoto2 --auto-detect | grep usb | cut -b 36-42 | sed 's/,/\//'`
if [ -z ${dev} ]
then
echo "Error: Camera not found"
exit
fi
./resetusb /dev/bus/usb/${dev}
gphoto2 $@
./resetusb /dev/bus/usb/${dev}
HttpImage Listener (Android):
You can send images via cURL to an android device running HttpImage Listener:
e.g.: curl -F imagefile@myimage.jpg http://192.168.0.2
The follwoing options are available:
nohandler=true just save image, don't display
customapp=true let's you choose the app for handling the image
e.g: curl -d nohandler=true -F imagefile@myimage.jpg http://192.168.0.2
HttpImage-gphoto2Client (shell script):
This shell script is meant to be a client for my Android App "HttpImage Listener", which is an app running a webserver that handles image files sent via HTTP POST request.HttpImage-gphoto2Client sends photos you take with a connected camera to a list of webservers via http POST request as soons as they have been taken.
This script uses a fix named gphoto-mod which wrapps gphoto2. This is needed to fix problems with USB on the Raspberry Pi.
nice use-case: run the script on a wireless Raspberry Pi that is connected to a DSLR camera, take photos and receive them immediately ony your tablet and sharem them via facebook
You will need the file "listener.conf" file which has the server URLs in it (starting with http:// or https://) seperated by newlines.
e.g.:
http://192.168.0.2:8080
http://192.168.0.3:8080
#!/bin/bash
#
# HttpImage-gphoto2Client
#
# Author: Mike Herwig
#
# Dependencies: libgphoto2, curl
#
# Description:
# Sends photos you take with a connected camera to
# a list of webserver via http POST request as soons as
# they have been taken
SAVE_DIR="$HOME/HttpImage"
LISTENER_CONFIG_FILE="listener.conf"
OPTIONS=""
#OPTIONS="-d nohandler=true"
#OPTIONS="-d customapp=true"
# don't change anything below unless you know what you're doing ;)
! [ -d $SAVE_DIR ] && mkdir "$SAVE_DIR"
if [ -e $LISTENER_CONFIG_FILE ]; then
IFS=$'\n'
LISTENER_ARGS=`cat $LISTENER_CONFIG_FILE`
else
echo "no config file $LISTENER_CONFIG_FILE was found."
exit 1
fi
unset IFS
LISTENER_LIST=($(echo "$LISTENER_ARGS" | grep --only-matching --perl-regexp "http(s?):\/\/.+"))
if [ "$1" = run ]; then
if [ ${#LISTENER_LIST[@]} -gt 0 ]; then
./gphoto-mod --wait-event-and-download --force-overwrite --hook-script $0
else
echo "no valid listener urls were found."
exit 1
fi
fi
if [[ $ACTION ]]; then
if [ $ACTION = download ]; then
INDEX=0
for i in ${LISTENER_LIST[@]}; do
REQUEST=$(curl -i "$OPTION" -F "imagefile=@$ARGUMENT" "${LISTENER_LIST[$INDEX]}")
time $REQUEST $
INDEX=$((INDEX + 1))
done
fi
if [ $ACTION = stop ]; then
mv *.jpg $SAVE_DIR
fi
fi
# sup, bro?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment