diff --git a/.stfolder b/.stfolder new file mode 100644 index 0000000..e69de29 diff --git a/broadcast.py b/broadcast.py new file mode 100755 index 0000000..a47f781 --- /dev/null +++ b/broadcast.py @@ -0,0 +1,16 @@ +#!/usr/bin/python3 + +import json +import socket + +UDP_IP = "255.255.255.255" +UDP_PORT = 32145 +MESSAGE = {"subject": "Fotobox Broadcast", "port": 80} + +sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) +sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) +sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) + +data = json.dumps(MESSAGE, indent=4, sort_keys=True) +data = data.encode("UTF-8") +sock.sendto(data, (UDP_IP, UDP_PORT)) diff --git a/graphics/1.png b/graphics/1.png new file mode 100644 index 0000000..9484241 Binary files /dev/null and b/graphics/1.png differ diff --git a/graphics/1.xcf b/graphics/1.xcf new file mode 100644 index 0000000..4105720 Binary files /dev/null and b/graphics/1.xcf differ diff --git a/graphics/2.png b/graphics/2.png new file mode 100644 index 0000000..5d4c554 Binary files /dev/null and b/graphics/2.png differ diff --git a/graphics/2.xcf b/graphics/2.xcf new file mode 100644 index 0000000..df54791 Binary files /dev/null and b/graphics/2.xcf differ diff --git a/graphics/3.png b/graphics/3.png new file mode 100644 index 0000000..157bddb Binary files /dev/null and b/graphics/3.png differ diff --git a/graphics/3.xcf b/graphics/3.xcf new file mode 100644 index 0000000..61122fc Binary files /dev/null and b/graphics/3.xcf differ diff --git a/graphics/begin.png b/graphics/begin.png new file mode 100644 index 0000000..3305eeb Binary files /dev/null and b/graphics/begin.png differ diff --git a/graphics/begin.xcf b/graphics/begin.xcf new file mode 100644 index 0000000..37be23d Binary files /dev/null and b/graphics/begin.xcf differ diff --git a/graphics/canceled.png b/graphics/canceled.png new file mode 100644 index 0000000..166cc6a Binary files /dev/null and b/graphics/canceled.png differ diff --git a/graphics/canceled.xcf b/graphics/canceled.xcf new file mode 100644 index 0000000..71c5641 Binary files /dev/null and b/graphics/canceled.xcf differ diff --git a/graphics/end_no.png b/graphics/end_no.png new file mode 100644 index 0000000..d9889c5 Binary files /dev/null and b/graphics/end_no.png differ diff --git a/graphics/end_no.xcf b/graphics/end_no.xcf new file mode 100644 index 0000000..e60aba0 Binary files /dev/null and b/graphics/end_no.xcf differ diff --git a/graphics/end_yes.png b/graphics/end_yes.png new file mode 100644 index 0000000..c236376 Binary files /dev/null and b/graphics/end_yes.png differ diff --git a/graphics/end_yes.xcf b/graphics/end_yes.xcf new file mode 100644 index 0000000..bdaed22 Binary files /dev/null and b/graphics/end_yes.xcf differ diff --git a/graphics/info.png b/graphics/info.png new file mode 100644 index 0000000..2890a69 Binary files /dev/null and b/graphics/info.png differ diff --git a/graphics/info.xcf b/graphics/info.xcf new file mode 100644 index 0000000..3d2ba06 Binary files /dev/null and b/graphics/info.xcf differ diff --git a/graphics/info2.xcf b/graphics/info2.xcf new file mode 100644 index 0000000..d7859a1 Binary files /dev/null and b/graphics/info2.xcf differ diff --git a/graphics/keypad.png b/graphics/keypad.png new file mode 100644 index 0000000..5af9e79 Binary files /dev/null and b/graphics/keypad.png differ diff --git a/graphics/loading.png b/graphics/loading.png new file mode 100644 index 0000000..cbef6d9 Binary files /dev/null and b/graphics/loading.png differ diff --git a/graphics/loading.xcf b/graphics/loading.xcf new file mode 100644 index 0000000..665d0a4 Binary files /dev/null and b/graphics/loading.xcf differ diff --git a/graphics/no.png b/graphics/no.png new file mode 100644 index 0000000..fc77600 Binary files /dev/null and b/graphics/no.png differ diff --git a/graphics/saved.png b/graphics/saved.png new file mode 100644 index 0000000..8bd8e45 Binary files /dev/null and b/graphics/saved.png differ diff --git a/graphics/saved.xcf b/graphics/saved.xcf new file mode 100644 index 0000000..cfe2ea8 Binary files /dev/null and b/graphics/saved.xcf differ diff --git a/graphics/yes.png b/graphics/yes.png new file mode 100644 index 0000000..81a69b5 Binary files /dev/null and b/graphics/yes.png differ diff --git a/onlineconfig.py b/onlineconfig.py new file mode 100755 index 0000000..d2ad3be --- /dev/null +++ b/onlineconfig.py @@ -0,0 +1,41 @@ +#!/usr/bin/python3 + +import netifaces +import urllib.request +import json +import os + + + +API_URL = "http://fotobox.online:8888/api" +BASE_PATH = "/var/lib/photobox" +MAC_INTERFACE = "eth0" +FOTOBOX_KEY = "eDAOMohrcJY3" + + +CONFIG_PATH = "%s/config.json" % (BASE_PATH, ) + + + +def getHwAddr(ifname): + return netifaces.ifaddresses(ifname)[netifaces.AF_LINK][0]["addr"] + + + + +mac_address = getHwAddr(MAC_INTERFACE) + +url = "%s/fotobox/config/%s/%s/" % (API_URL, mac_address, FOTOBOX_KEY) +print(url) +reply = urllib.request.urlopen(url).read() +reply = reply.decode("UTF-8") +reply = json.loads(reply) +reply = json.dumps(reply, sort_keys=True, indent=4) +print(reply) + +try: + os.makedirs(BASE_PATH) +except OSError: + pass + +open(CONFIG_PATH, "w+").write(reply) diff --git a/photobox.py b/photobox.py index 4cdaf3b..eeb0a97 100755 --- a/photobox.py +++ b/photobox.py @@ -8,11 +8,12 @@ from shutil import copyfile from math import floor import RPi.GPIO as GPIO +import traceback import picamera import pygame import random import time - +import json @@ -41,10 +42,6 @@ def monotonic_time(): - -os.chdir(os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))) - - # CONFIGURATION WIDTH = 800 HEIGHT = 480 @@ -56,13 +53,18 @@ OVERLAY_ALPHA = 64 COLOR_BACK = pygame.Color(0, 0, 0) COLOR_FLASH = pygame.Color(255, 255, 255) GRAPHICS_DIR = "./graphics" -IMAGE_DIR = "/var/www/html/current_images" +BASE_PATH = "/var/lib/photobox" COUNTDOWN = 3 SHOT_COUNT = 3 BORDER = 10 THUMB_WIDTH = int((800 - BORDER) / SHOT_COUNT - BORDER) THUMB_HEIGHT = int(THUMB_WIDTH / 1.333) +CONFIG_LOCATION = "%s/config.json" % (BASE_PATH, ) + + + +os.chdir(os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))) @@ -71,29 +73,6 @@ session_start = monotonic_time() -# CREATE DIRECTORIES -try: - os.makedirs(GRAPHICS_DIR) -except OSError: - pass - -try: - os.makedirs(IMAGE_DIR) -except OSError: - pass - -try: - os.makedirs(IMAGE_DIR + "/original") -except OSError: - pass - -try: - os.makedirs(IMAGE_DIR + "/todo") -except OSError: - pass - - - # INIT GPIO GPIO.setmode(GPIO.BOARD) GPIO.setwarnings(False) @@ -116,6 +95,7 @@ GPIO.output(7, GPIO.LOW) # INIT PYGAME pygame.init() +pygame.mixer.quit() pygame.mouse.set_visible(False) screen = pygame.display.set_mode((WIDTH,HEIGHT)) @@ -384,9 +364,22 @@ def saveImages(choices): for i in range(0, SHOT_COUNT): if choices[i] > 0: print(" saving image #%s" % i) + + EVENT_PATH = "%s/events/%s" % (BASE_PATH, EVENT_ID) + + try: + os.makedirs(EVENT_PATH + "/original") + except OSError: + pass + + try: + os.makedirs(EVENT_PATH + "/todo") + except OSError: + pass + filename = "%s-%s-session_age=%05d.jpg" % (local.strftime("%Y%m%dT%H:%M:%S.%f%z"), i, session_age) - os.rename("tmp%s.jpg" % i, IMAGE_DIR + "/original/" + filename) - copyfile(IMAGE_DIR + "/original/" + filename, IMAGE_DIR + "/todo/" + filename) + os.rename("tmp%s.jpg" % i, EVENT_PATH + "/original/" + filename) + copyfile(EVENT_PATH + "/original/" + filename, EVENT_PATH + "/todo/" + filename) # show message screen.fill(COLOR_BACK) @@ -396,11 +389,31 @@ def saveImages(choices): +def loadConfig(): + global EVENT_ID + + try: + if os.path.isfile(CONFIG_LOCATION): + config = open(CONFIG_LOCATION, "r").read() + config = json.loads(config) + + EVENT_ID = int(config["id"]) + + except: + traceback.print_exc() + + EVENT_ID = -1 + + + +EVENT_ID = -1 + while 1: waitForBegin() makePhotos() (choices, save) = chooseImages() + loadConfig() if save: saveImages(choices); else: diff --git a/tmp0.jpg b/tmp0.jpg new file mode 100644 index 0000000..2796ecc Binary files /dev/null and b/tmp0.jpg differ diff --git a/tmp2.jpg b/tmp2.jpg new file mode 100644 index 0000000..8c43b71 Binary files /dev/null and b/tmp2.jpg differ diff --git a/upload-daemon.sh b/upload-daemon.sh index 3382353..5980f00 100755 --- a/upload-daemon.sh +++ b/upload-daemon.sh @@ -2,7 +2,7 @@ INTERVAL="10" FAILURE_PAUSE="10" -LOCAL_FILES="/var/www/html/current_images" +BASE_PATH="/var/lib/photobox" BASE_URL="https://fotobox.online/upload" #BASE_URL="http://fotobox.online:8888/upload" @@ -11,47 +11,57 @@ BASE_URL="https://fotobox.online/upload" FOTOBOX_ID="1" FOTOBOX_KEY="eDAOMohrcJY3" -EVENT_ID="20" - -mkdir -p "$LOCAL_FILES/todo" 2> /dev/null -mkdir -p "$LOCAL_FILES/upload" 2> /dev/null -mkdir -p "$LOCAL_FILES/lowres" 2> /dev/null +cd "$BASE_PATH/events" while true; do date=$(date +'%Y-%m-%d %H:%M:%S') - cd "$LOCAL_FILES/todo" - todos="$(ls ./)" + todos="$(ls ./*/todo/* 2> /dev/null)" if [ "$todos" != "" ]; then - echo "$date: uploading files:" + echo -e "= CONVERTING ==================================\n" for todo in $todos; do - echo "converting..." - convert "$todo" -resize 1000x -quality 0.7 "../lowres/$todo" && cp "../lowres/$todo" "../upload/$todo" && rm -f "$todo" + echo "CONVERTING: $todo" + + event_id=$(echo "$todo" | cut -d'/' -f2) + filename=$(echo "$todo" | cut -d'/' -f4) + + mkdir -p "./$event_id/lowres" 2> /dev/null + mkdir -p "./$event_id/upload" 2> /dev/null + + lowres="./$event_id/lowres/$filename" + upload="./$event_id/upload/$filename" + + ( convert "$todo" -resize 1000x -quality 0.7 "$lowres" && cp "$lowres" "$upload" && rm -f "$todo" && echo "OK" ) || echo "FAIL!" + + echo "" done - echo "" fi - cd "$LOCAL_FILES/upload" - uploads="$(ls ./)" + uploads="$(ls ./*/upload/* 2> /dev/null)" if [ "$uploads" != "" ]; then - echo "$date: uploading files:" + echo -e "= UPLOADING ===================================\n" for upload in $uploads; do - echo "uploading..." + echo "UPLOADING: $upload" + + event_id=$(echo "$upload" | cut -d'/' -f2) + filename=$(echo "$upload" | cut -d'/' -f4) + timestamp_fotobox=$(date +'%Y-%m-%dT%H:%M:%S.%N%z') timestamp_shot=$(basename "$upload" | sed 's|.jpg||g') - url="$BASE_URL/$FOTOBOX_ID/$FOTOBOX_KEY/$EVENT_ID/$timestamp_fotobox/$timestamp_shot/" - echo "$url" + url="$BASE_URL/$FOTOBOX_ID/$FOTOBOX_KEY/$event_id/$timestamp_fotobox/$timestamp_shot/" + #~ echo "$url" + result=$(curl -s --form "image=@$upload" "$url" 2>&1) - echo "$result" if [ "$result" == "OK" ]; then - rm -f "$upload" + ( rm -f "$upload" && echo "OK" ) || echo "FAIL!" else + echo "$result" sleep $FAILURE_PAUSE fi + echo "" done - echo "" fi # SLEEP