#!/bin/bash syncTimeFromServer source "/etc/global.includes" cd ${processingDirectory} printf "\n$(date +"%d/%m/%y %I:%M%p")" printf "\n\nWorking with processing directory: ${processingDirectory}" printf "\n\nSending camera image to : ${cameraDSLR}" if [ ! -d $tempZipDirectory ]; then mkdir ${tempZipDirectory} fi echo $(date +"%s") > ${tempZipDirectory}/timestamp.txt # Global Variables imageText="DBC - Queens Wharf (63 George St)" imageDate=$(date +"%d/%m/%y %I:%M%p") archiveWithoutOriginal="true" currentTime=$(date +"%Y%m%d_%H%M%S") gPhotoString=" --set-config-index reviewtime=0 --set-config-index imageformat=1 --set-config-index aperture=8 --set-config-index iso=1 --set-config-index manualfocusdrive=6 --capture-image-and-download --filename ${processingDirectory}/${currentTime}.jpg " printf "\n\nCapturing Image... " captureCommand=$(gphoto ${gPhotoString} &> /tmp/gPhotoOutput.txt) captureResult=$(grep -i "Error" /tmp/gPhotoOutput.txt | wc -l) if [ $captureResult -gt 1 ]; then printf "Shit... camera error, starting power cycle routine in 10 seconds..." wgetResult=$(wget --timeout=30 -qO- "http://www.livetimelapse.com.au/monitoring/email.alerts.php?mode=powerCyclingCamera&location=${cameraDSLR}") printf "\n\n" cat /tmp/gPhotoOutput.txt printf "\n\n" powerCycleCamera & exit 0 else echo "Great! No errors detected" fi sdCardPresent=$(df -h | grep "${photoDirectory1}" | wc -l) if [ ! -f /tmp/uploading_flag ]; then printf "\nResampling WWW Image... \n\n" # Store the original filesize in a variable to be passed to the server originalImageSize=$(stat -c%s ${processingDirectory}/${currentTime}.jpg) # Live web view and time lapse sized image convert -resize 980x653 \ -fill "#00008B60" -draw "rectangle 0,653 980,633" \ -font "/usr/share/fonts/gotham-book.ttf" -pointsize 13 -stroke none \ -gravity SouthWest -fill '#000000' -draw "text 2,2 '${imageText} - ${imageDate}'" \ -gravity SouthWest -fill '#FFFFFF' -draw "text 3,3 '${imageText} - ${imageDate}'" \ -gravity SouthEast -fill '#000000' -draw "text 2,2 'Time Lapse Pty Ltd'" \ -gravity SouthEast -fill '#FFFFFF' -draw "text 3,3 'Time Lapse Pty Ltd'" \ ${processingDirectory}/${currentTime}.jpg -quality 85 ${tempZipDirectory}/980x655.jpg cp ${processingDirectory}/${currentTime}.jpg /tmp/latest.jpg # Configuration RELAY_URL="https://www.livetimelapse.com.au/ai/google-chat/php-tools/imageRelay.php" # Update this with your actual URL IMAGE_PATH="/tmp/latest.jpg" # Check if image exists if [ ! -f "$IMAGE_PATH" ]; then echo "Error: Image not found at $IMAGE_PATH" exit 1 fi # Build caption with available environment variables or defaults CAMERA="${cameraDSLR:-DSLR Camera}" LOCATION="${imageText:-Camera Location}" TIMESTAMP=$(date +"%Y-%m-%d %H:%M:%S") # Create caption #CAPTION="📸 $CAMERA | 📍 $LOCATION | 🕒 $TIMESTAMP" CAPTION="Latest camera image" # Send image to relay echo "Sending image to Google Chat..." # Get file size for logging FILE_SIZE=$(stat -c%s "$IMAGE_PATH" 2>/dev/null || stat -f%z "$IMAGE_PATH" 2>/dev/null || echo "unknown") echo "Image size: $FILE_SIZE bytes" # Check if GOOGLE_CHAT_SPACE_ID environment variable is set for multi-space support if [ ! -z "$GOOGLE_CHAT_SPACE_ID" ]; then echo "Multi-space mode: Sending to space $GOOGLE_CHAT_SPACE_ID" # Use curl to post the image with space_id parameter RESPONSE=$(curl -s -X POST "$RELAY_URL" \ -F "image=@$IMAGE_PATH" \ -F "caption=$CAPTION" \ -F "space_id=$GOOGLE_CHAT_SPACE_ID" \ --max-time 300 \ --connect-timeout 30 \ 2>&1) else echo "Default mode: Sending to configured space" # Use curl to post the image without space_id (backward compatibility) RESPONSE=$(curl -s -X POST "$RELAY_URL" \ -F "image=@$IMAGE_PATH" \ -F "caption=$CAPTION" \ --max-time 300 \ --connect-timeout 30 \ 2>&1) fi # Check response if echo "$RESPONSE" | grep -q '"success":true'; then echo "✅ Image successfully sent to Google Chat" # Note: exit 0 removed to allow script to continue with FTP upload else echo "❌ Failed to send image to Google Chat" echo "Response: $RESPONSE" # Note: exit 1 removed to allow script to continue with FTP upload fi printf "Creating ZIP file...\n" # ZIP files up cd ${tempZipDirectory} zip ${cameraDSLR}.zip *.* printf "Uploading ZIP file...\n\n" # Set the upload lock file touch /tmp/uploading_flag # Upload files ftp -inv tlcupload1.livetimelapse.com.au <