Skip to content

Commit 8b4a58f

Browse files
authored
Merge pull request #872 from thomasjacquin/saveImages.sh
Save images.sh
2 parents 722ea1f + 4e74521 commit 8b4a58f

16 files changed

+1081
-836
lines changed

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ scripts/startrails_manual.sh
1919
scripts/startrails_only.sh
2020
scripts/stretch.sh
2121
scripts/endOfNight_additionalSteps.sh
22+
scripts/saveImageDay.sh
23+
scripts/saveImageNight.sh
2224
settings_RPiHQ.json
2325
settings_ZWO.json
2426

@@ -35,4 +37,4 @@ capture
3537
capture_RPiHQ
3638
keogram
3739
startrails
38-
sunwait
40+
sunwait

README.md

+21-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
# Allsky Camera ![Release 0.8.1](https://img.shields.io/badge/Release-0.8.1-green.svg) [![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=MEBU2KN75G2NG&source=url)
2-
1+
# Allsky Camera ![Release 0.8.3](https://img.shields.io/badge/Release-0.8.3-green.svg) [![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=MEBU2KN75G2NG&source=url)
32

43
This is the source code for the Allsky Camera project described [on Instructables](http://www.instructables.com/id/Wireless-All-Sky-Camera/).
54

5+
## Required Action Needed
6+
When upgrading from a release _prior to_ 0.8.3 you **MUST** follow the steps [here](https://github.com/thomasjacquin/allsky/wiki/Upgrade-from-0.8.2-or-prior-versions).
7+
8+
69

710
![](http://www.thomasjacquin.com/allsky-portal/screenshots/camera-header-photo.jpg)
811

12+
913
## Requirements
1014

1115
In order to get the camera working properly you will need the following hardware:
@@ -196,7 +200,7 @@ Set to "false" to keep all nights (requires manual management of SD card free sp
196200
197201
## Logging issues
198202
199-
When using the allsky service, issues are written to a log file. In case the program stopped, crashed, or behaved in an abnormal way, take a look at this log file:
203+
When using the allsky service, issues are written to a log file. In case the program stopped, crashed, or behaved in an abnormal way, take a look at:
200204
```
201205
tail /var/log/allsky.log
202206
```
@@ -232,8 +236,7 @@ Once you've installed the website, either on your Pi or another machine, look at
232236
Experienced users may want to add some additional processing steps at the end of nighttime.
233237
To do so, copy `scripts/endOfNight_additionalSteps.repo` to
234238
`scripts/endOfNight_additionalSteps.sh` and then add your additional processing steps which
235-
will be run after the usual end-of-night processing, but before the deletion of any
236-
old image files.
239+
will be run after the usual end-of-night processing, but before the deletion of any old image files.
237240

238241
Edit this file via the "Editor" link on the left side of the WebUI page.
239242

@@ -301,7 +304,19 @@ If you've built an allsky camera, please send me a message and I'll add you to t
301304
* The WebUI will now show the Pi's throttle and low-voltage states, which is useful for debugging.
302305
* Darks work better.
303306
* Many bug fixes, error checks, and warnings added.
304-
307+
* version **0.8.3**: Works on Bullseye operating system.
308+
* RPiHQ version:
309+
* Has an improved auto-exposure algorithm. To use it, set `CAPTURE_EXTRA_PARAMETERS="-mean-value 0.3 -autoexposure 1"` in config.sh (a future version will allow this to be set via the WebUI).
310+
* Has many new settings including support for most of the text overlay features that are supported by the ZWO version. The "extra text" feature will be supported in a future version).
311+
* New and changed config.sh variables, see the [Software Settings](https://github.com/thomasjacquin/allsky/wiki/allsky-Settings) Wiki page for more information:
312+
* `IMG_UPLOAD_FREQUENCY`: how often the image should be uploaded to a website. Useful with slow uplinks or metered Internet connections.
313+
* `IMG_CREATE_THUMBNAILS`: specifies whether or not thumbnails should be created for each image.
314+
* `REMOVE_BAD_IMAGES` now defaults to "true" since bad-image detection is now done after a picture is saved rather than once for all pictures at the end of the night. This helps decrease problems when creating startrails, keograms, and timelapse videos.
315+
* `IMG_PREFIX`: no longer used - the name of the image used by the websites is now whatever you specify in the WebUI (default: image.jpg).
316+
* **NOTE**: When upgrading to 0.8.3 you MUST follow the steps listed [here](https://github.com/thomasjacquin/allsky/wiki/Upgrade-from-0.8.2-or-prior-versions).
317+
* Replaced `saveImageDay.sh` and `saveImageNight.sh` with `saveImage.sh` that has improved functionality, including passing the sensor temperature to the dark subtraction commands, thereby eliminating the need for the "temperature.txt" file.
318+
* The image used by the websites (default: image.jpg) as well as all temporary files are now written to `allsky/tmp`. **NOTE**: if you are using the Allsky Website you will need to change the "imageName" variable in `/var/www/html/allsky/config.js` to `"/current/tmp/"`.
319+
* You can **significanly** reduce wear on your SD card by making `allsky/tmp` a [memory-based filesystem](https://github.com/thomasjacquin/allsky/wiki/Miscellaneous-Tips) for instructions).
305320
## Donation
306321

307322
If you found this project useful, here's a link to send me a cup of coffee :)

allsky.sh

+34-19
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@ fi
2525
# If not found, force the user to upgrade config.sh
2626
if [ -f "${ALLSKY_CONFIG}/config.sh" ]; then
2727
source "${ALLSKY_CONFIG}/config.sh"
28-
RET=$?
29-
if [ -z "${ALLSKY_DEBUG_LEVEL}" ]; then
28+
if [ -z "${CAPTURE_SAVE_DIR}" ]; then
3029
echo "${RED}*** ERROR: old version of config.sh detected.${NC}"
31-
RET=1
30+
echo "See https://github.com/thomasjacquin/allsky/wiki/Upgrade-from-0.8.2-or-prior-versions"
31+
32+
"${ALLSKY_SCRIPTS}/copy_notification_image.sh" "Error" 2>&1
33+
sudo systemctl stop allsky
34+
exit 1
3235
fi
3336
else
34-
echo "${RED}*** ERROR: cannot find config.sh.${NC}"
35-
RET=1
36-
fi
37-
if [ ${RET} -ne 0 ]; then
37+
echo "${RED}*** ERROR: config.sh not in ${ALLSKY_CONFIG}.${NC}"
3838
echo "Please make a backup of your config.sh, ftp-settings.sh, and settings_*.json files,"
3939
echo "then do a full re-install of AllSky."
4040
echo "After the re-install, copy your settings from the backup files to the new files."
@@ -45,24 +45,22 @@ if [ ${RET} -ne 0 ]; then
4545
exit 1
4646
fi
4747

48-
mkdir -p "${ALLSKY_TMP}" # Re-create in case it's on a memory filesystem that gets wiped out at reboot
49-
5048
# Make sure allsky.sh is not already running.
5149
ps -ef | grep allsky.sh | grep -v $$ | xargs "sudo kill -9" 2>/dev/null
5250

5351
# old/regular manual camera selection mode => exit if no requested camera was found
5452
# Buster and Bullseye have different output so only check the part they have in common.
5553
# TODO: this check only needs to be done if CAMERA = RPiHQ
56-
# vcgencmd get_camera | grep --silent "supported=1"
57-
# bullseye has problems to dedect cameras - workaround
58-
which libcamera-still
54+
# Bullseye has problems detecting RPiHQ cameras - workaround
55+
which libcamera-still > /dev/null
5956
if [ $? -eq 0 ]; then
60-
LIBCAMERA_LOG_LEVELS="ERROR,FATAL" libcamera-still -t 1 --nopreview
57+
LIBCAMERA_LOG_LEVELS="ERROR,FATAL" libcamera-still -t 1 --nopreview
58+
RET=$?
6159
else
62-
vcgencmd get_camera | grep --silent "supported=1"
60+
vcgencmd get_camera | grep --silent "supported=1"
61+
RET=$?
6362
fi
64-
65-
if [ $? -eq 0 ]; then
63+
if [ $RET -eq 0 ]; then
6664
RPiHQIsPresent=1
6765
else
6866
RPiHQIsPresent=0
@@ -147,15 +145,21 @@ echo "export CAMERA=${CAMERA}" > "${ALLSKY_CONFIG}/autocam.sh"
147145
# This must be called after CAMERA AUTOSELECT above to refresh the file name.
148146
source "${ALLSKY_SCRIPTS}/filename.sh"
149147

148+
if [ -d "${ALLSKY_TMP}" ]; then
149+
# remove any lingering old image files.
150+
rm -f "${ALLSKY_TMP}/${FILENAME}"-202*.${EXTENSION} # "202" for 2021 and later
151+
else
152+
# Re-create in case it's on a memory filesystem that gets wiped out at reboot
153+
mkdir -p "${ALLSKY_TMP}"
154+
fi
155+
150156
# Optionally display a notification image. This must come after the creation of "autocam.sh" above.
151157
USE_NOTIFICATION_IMAGES=$(jq -r '.notificationimages' "$CAMERA_SETTINGS")
152158
if [ "$USE_NOTIFICATION_IMAGES" = "1" ] ; then
153159
# Can do this in the background to speed up startup
154160
"${ALLSKY_SCRIPTS}/copy_notification_image.sh" "StartingUp" 2>&1 &
155161
fi
156162

157-
echo "Starting allsky camera..."
158-
159163
# Building the arguments to pass to the capture binary.
160164
# Want to allow spaces in arguments so need to put quotes around them,
161165
# but in order for it to work need to make ARGUMENTS an array.
@@ -181,7 +185,6 @@ ARGUMENTS+=(-debuglevel ${ALLSKY_DEBUG_LEVEL})
181185
# This argument should come next so the capture program knows if it should use colors.
182186
ARGUMENTS+=(-tty ${ON_TTY})
183187

184-
185188
KEYS=( $(jq -r 'keys[]' $CAMERA_SETTINGS) )
186189
for KEY in ${KEYS[@]}
187190
do
@@ -195,6 +198,18 @@ if [[ $1 == "preview" ]] ; then
195198
ARGUMENTS+=(-preview 1)
196199
fi
197200

201+
ARGUMENTS+=(-save_dir "${CAPTURE_SAVE_DIR}")
202+
203+
FREQUENCY_FILE="${ALLSKY_TMP}/IMG_UPLOAD_FREQUENCY.txt"
204+
# If the user wants images uploaded only every n times, save that number to a file.
205+
if [ "${IMG_UPLOAD_FREQUENCY}" != "1" ]; then
206+
# Save "1" so we upload the first image.
207+
# saveImage.sh will write ${IMG_UPLOAD_FREQUENCY} to the file as needed.
208+
echo "1" > "${FREQUENCY_FILE}"
209+
else
210+
rm -f "${FREQUENCY_FILE}"
211+
fi
212+
198213
# "capture" expects 0 or 1; newer versions of config.sh use "true" and "false".
199214
# DAYTIME is the old name for DAYTIME_CAPTURE.
200215
# TODO: These checks will go away in the future.

config_repo/config.sh.repo

+24-16
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,18 @@ CAMERA=""
1515
IMG_UPLOAD="false"
1616

1717
# If UPLOAD_IMG is "true", upload images every IMG_UPLOAD_FREQUENCY frames, e.g., every 5 frames.
18-
# 0 uploades every frame.
19-
IMG_UPLOAD_FREQUENCY=0
18+
# 1 uploades every frame.
19+
IMG_UPLOAD_FREQUENCY=1
2020

2121
# The websites look in IMG_DIR for the current image.
22-
# When using the Allsky website from the "allsky-website" packge, "allsky" is an
23-
# alias for "/var/www/html/allsky/" and "current" is an alias for "/home/pi/allsky".
24-
# If you use "current" and have the Allsky website, prepend "/current/" to
25-
# the "imageName" in /var/www/html/allsky/config.js, for example: imageName: "/current/image.jpg",
26-
# Using "current" avoids copying the image to the website.
27-
IMG_DIR="current"
28-
29-
# Set an optional prefix on the image file name, before "$FILENAME.$EXTENSION".
30-
# This must match what the local web site thinks the name is (see /var/www/html/allsky/config.js).
31-
IMG_PREFIX="liveview-"
22+
# When using the Allsky website from the "allsky-website" packge,
23+
# "current" is an alias for "/home/pi/allsky".
24+
# If you use the default IMG_DIR and have the Allsky website, set "imageName" in
25+
# /var/www/html/allsky/config.js to:
26+
# imageName: "/current/tmp/image.jpg",
27+
# This avoids copying the image to the website.
28+
# Only change IMG_DIR if you know what you are doing.
29+
IMG_DIR="current/tmp"
3230

3331
# Resize images before cropping, stretching, and saving.
3432
# Adjust IMG_WIDTH and IMG_HEIGHT according to your camera's sensor ratio.
@@ -54,10 +52,12 @@ AUTO_STRETCH_MID_POINT="10%"
5452
RESIZE_UPLOADS="false"
5553
RESIZE_UPLOADS_SIZE="962x720"
5654

57-
# Remove corrupt images before generating keograms and startrails.
58-
# This can take tens of minutes to run and isn't necessary unless your system produces
59-
# corrupt images which then generate funny colors in the summary images...
60-
REMOVE_BAD_IMAGES="false"
55+
# Create thumbnails of images. If you are not running the WebUI consider changing this to "false".
56+
IMG_CREATE_THUMBNAILS="true"
57+
58+
# Remove corrupt images before generating keograms, startrails, and timelapse videos.
59+
# This only adds a few seconds per image as it's being processed.
60+
REMOVE_BAD_IMAGES="true"
6161

6262
# If REMOVE_BAD_IMAGES is "true", images whose mean brightness is
6363
# less than THRESHOLD_LOW or greater than THRESHOLD_HIGH percent (max: 100) will be removed.
@@ -142,6 +142,7 @@ AUTO_DELETE="true"
142142
NIGHTS_TO_KEEP=14
143143

144144
# Set to "true" to upload data to your server at the end of each night.
145+
# This is needed if you are running the Allsky Website.
145146
POST_END_OF_NIGHT_DATA="false"
146147

147148
# Set to "true" if you want to enable dark frame subtraction on your night-time images.
@@ -175,6 +176,13 @@ elif [ "${CAMERA}" = "auto" ]; then
175176
exit 1
176177
fi
177178

179+
# This is needed in case the user changed the default location the current image is saved to.
180+
if [ "${IMG_DIR}" = "current/tmp" ]; then
181+
CAPTURE_SAVE_DIR="${ALLSKY_TMP}"
182+
else
183+
CAPTURE_SAVE_DIR="${IMG_DIR}"
184+
fi
185+
178186
# !!! The next few lines are for backwards compatibility and will be removed in the future - do not change !!!
179187
UPLOAD_IMG="${IMG_UPLOAD}" # UPLOAD_IMG is th eold name for IMG_UPLOAD
180188
if [ "${DAYTIME_CAPTURE}" = "true" ]; then

scripts/copy_notification_image.sh

+9-7
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ if [ ! -e "${NOTIFICATIONFILE}" ] ; then
1919
exit 2
2020
fi
2121

22-
IMAGE_TO_USE="${ALLSKY_TMP}/notification-${FULL_FILENAME}"
22+
IMAGE_TO_USE="${CAPTURE_SAVE_DIR}/notification-${FULL_FILENAME}"
2323
# Don't overwrite notification image so create a temporary copy and use that.
2424
cp "${NOTIFICATIONFILE}" "${IMAGE_TO_USE}"
2525

@@ -32,32 +32,34 @@ if [ "${IMG_RESIZE}" = "true" ]; then
3232
fi
3333
fi
3434

35-
# If daytime saving is desired, save the image in today's thumbnail directory
35+
# If daytime saving is desired, save the image in today's thumbnail directory if desired
3636
# so the user can see when things changed.
3737
# Don't save in main image directory because we don't want the notification image in timelapses.
3838
# If at nighttime, save them in (possibly) yesterday's directory.
3939
# If during day, save in today's directory.
40-
if [ "${DAYTIME_SAVE}" = "true" -o "${CAPTURE_24HR}" = "true" ] ; then # CAPTURE_24HR is OLD name
40+
if [ "${DAYTIME_SAVE}" = "true" -a "${IMG_CREATE_THUMBNAILS}" = "true" ] ; then
4141
DATE_DIR="${ALLSKY_IMAGES}/$(date +'%Y%m%d')"
4242
# Use today's folder if it exists, otherwise yesterday's
4343
[ ! -d "${DATE_DIR}" ] && DATE_DIR="${ALLSKY_IMAGES}/$(date -d '12 hours ago' +'%Y%m%d')"
44-
THUMB="${DATE_DIR}/thumbnails/${FILENAME}-$(date +'%Y%m%d%H%M%S').${EXTENSION}"
44+
THUMBNAILS_DIR="${DATE_DIR}/thumbnails"
45+
mkdir -p ${THUMBNAILS_DIR}
46+
THUMB="${THUMBNAILS_DIR}/${FILENAME}-$(date +'%Y%m%d%H%M%S').${EXTENSION}"
4547

4648
convert "${IMAGE_TO_USE}" -resize "${THUMBNAIL_SIZE_X}x${THUMBNAIL_SIZE_Y}" "${THUMB}"
4749
if [ $? -ne 0 ] ; then
4850
echo "${YELLOW}*** ${ME}: WARNING: THUMBNAIL resize failed; continuing.${NC}"
49-
fi
51+
fi
5052
fi
5153

5254
FULL_FILENAME="${IMG_PREFIX}${FULL_FILENAME}"
53-
FINAL_IMAGE="${ALLSKY_HOME}/${FULL_FILENAME}" # final resting place - no more changes to it. TODO: put in ALLSKY_TMP
55+
FINAL_IMAGE="${CAPTURE_SAVE_DIR}/${FULL_FILENAME}" # final resting place - no more changes to it.
5456
mv -f "${IMAGE_TO_USE}" "${FINAL_IMAGE}" # so web severs can see it.
5557

5658
# If upload is true, optionally create a smaller version of the image, either way, upload it.
5759
if [ "${UPLOAD_IMG}" = "true" ] ; then
5860
if [ "${RESIZE_UPLOADS}" = "true" ]; then
5961
# Don't overwrite FINAL_IMAGE since the web server(s) may be looking at it.
60-
TEMP_FILE="${ALLSKY_TMP}/resize-${FULL_FILENAME}"
62+
TEMP_FILE="${CAPTURE_SAVE_DIR}/resize-${FULL_FILENAME}"
6163
cp "${FINAL_IMAGE}" "${TEMP_FILE}" # create temporary copy to resize
6264
convert "${TEMP_FILE}" -resize "${RESIZE_UPLOADS_SIZE}" -gravity East -chop 2x0 "${TEMP_FILE}"
6365
if [ $? -ne 0 ] ; then

scripts/darkCapture.sh

+19-15
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,43 @@
22

33
# This file is "source"d into another.
44
# "${CURRENT_IMAGE}" is the name of the current image we're working on and is passed to us.
5+
ME2="$(basename "${BASH_SOURCE[0]}")"
56

6-
# ${TEMPERATURE} is passed to us by saveImage.sh, but may be null.
7-
# If ${TEMPERATURE} is set, use it as the temperature, otherwise read the ${TEMPERATURE_FILE}.
7+
# Make sure the input file exists; if not, something major is wrong so exit.
8+
if [ "${CURRENT_IMAGE}" = "" ]; then
9+
echo "*** ${ME2}: ERROR: 'CURRENT_IMAGE' not set; aborting."
10+
exit 1
11+
fi
12+
if [ ! -f "${CURRENT_IMAGE}" ]; then
13+
echo "*** ${ME2}: ERROR: '${CURRENT_IMAGE}' does not exist; aborting."
14+
exit 2
15+
fi
16+
17+
# ${THIS_TEMPERATURE} is passed to us by saveImage.sh, but may be null.
18+
# If ${THIS_TEMPERATURE} is set, use it as the temperature, otherwise read the ${TEMPERATURE_FILE}.
819
# If the ${TEMPERATURE_FILE} file doesn't exist, set the temperature to "n/a".
9-
if [ "${TEMPERATURE}" = "" ]; then
10-
TEMPERATURE_FILE="${ALLSKY_HOME}/temperature.txt"
20+
if [ "${THIS_TEMPERATURE}" = "" ]; then
21+
TEMPERATURE_FILE="${ALLSKY_TMP}/temperature.txt"
1122
if [ -s "${TEMPERATURE_FILE}" ]; then # -s so we don't use an empty file
12-
TEMPERATURE=$(printf "%02.0f" "$(< ${TEMPERATURE_FILE})")
23+
THIS_TEMPERATURE=$( < ${TEMPERATURE_FILE})
1324
else
14-
TEMPERATURE="n/a"
25+
THIS_TEMPERATURE="n/a"
1526
fi
1627
fi
1728

1829
DARK_MODE=$(jq -r '.darkframe' "${CAMERA_SETTINGS}")
1930
if [ "${DARK_MODE}" = "1" ] ; then
20-
# XXXXX in future release $CURRENT_IMAGE will be set by saveImage.sh
21-
# and passed to us. Doing this conditional set works either way.
22-
CURRENT_IMAGE=${CURRENT_IMAGE:-"dark.${EXTENSION}"}
23-
2431
# The extension on $CURRENT_IMAGE may not be $EXTENSION.
2532
DARK_EXTENSION="${CURRENT_IMAGE##*.}"
2633

2734
DARKS_DIR="${ALLSKY_DARKS}"
2835
mkdir -p "${DARKS_DIR}"
2936
# If the camera doesn't support temperature, we will keep overwriting the file until
3037
# the user creates a temperature.txt file.
31-
if [ "${TEMPERATURE}" = "n/a" ]; then
38+
if [ "${THIS_TEMPERATURE}" = "n/a" ]; then
3239
cp "${CURRENT_IMAGE}" "${DARKS_DIR}"
3340
else
34-
cp "${CURRENT_IMAGE}" "${DARKS_DIR}/${TEMPERATURE}.${DARK_EXTENSION}"
41+
cp "${CURRENT_IMAGE}" "${DARKS_DIR}/${THIS_TEMPERATURE}.${DARK_EXTENSION}"
3542
fi
3643

3744
# If the user has notification images on, the current image says we're taking dark frames,
@@ -45,7 +52,4 @@ if [ "${DARK_MODE}" = "1" ] ; then
4552
fi
4653

4754
exit 0 # exit so the calling script exits and doesn't try to process the file.
48-
else
49-
# XXXXX Need this until saveImage.sh passes $CURRENT_IMAGE to us.
50-
CURRENT_IMAGE="${CURRENT_IMAGE:-${FULL_FILENAME}}" # Not capturing darks so use standard file name
5155
fi

0 commit comments

Comments
 (0)