pibooth / pibooth-qrcode

Pibooth plugin to generate a QR code to access to the final the picture
GNU General Public License v3.0
7 stars 7 forks source link

Local IP to download the picture #22

Open BramWerbrouck opened 5 months ago

BramWerbrouck commented 5 months ago

Can this plug-in be used local? I mean: if you dan't want to upload the pictures to google photos. The pictures are stored for instance in the folder /home/pi/Desktop/Pictures/pibooth If you are connected with your phone to the same network, is it possible that the QR-code contains 192.168.1.204/home/pi/Desktop/Pictures/pibooth/2024-04-08-19-08-33_pibooth.jpg to donwload this to your phone?

When I type this URL (192.168.1.204/home/pi/Desktop/Pictures/pibooth/2024-04-08-19-08-33_pibooth.jpg) on my phone, I got the "Page not found"-error so maybe you have to set something on the RPI to access this photo?

BramWerbrouck commented 4 months ago

Ok, I found something that works for me:

1) Installing a webservice sudo apt-get install apache2

2) Installing PHP-service sudo apt-get install php

3) Change the rights to the directory /var/www/html on the Raspberry Pi sudo chmod -R 777 /var/www/html

4) Rename the index.html file (or optionaly you can remove it too) sudo mv index.html default_index.html

5) Create a folder "pibooth-images" in /var/www/html and change the path were pibooth save the files

Path to save pictures (list of quoted paths eccepted)

from:
directory = ~/Pictures/pibooth

to:
directory = /var/www/html/pibooth-images/

6) Change the URL in de QR-code

URL which may be composed of variables: {picture}, {count}

from:
prefix_url = https://github.com/pibooth/pibooth

to:
prefix_url = https://192.168.0.1/index.php?image={picture}

where 192.168.0.1 is your ip address (*)

7) Create the index.php-file in directory /var/www/html with the following content:

<?php
$image = (isset($_GET['image']) && $_GET['image']) !='' ? $_GET['image'] : false;
if ($image){
  $path = 'pibooth-images/'.$image;
  if(!is_file($path)){
    http_response_code(404);
    echo $path.' does not exist!';
    exit();
  }
  try{
    header('Content-Type: application/octet-stream');
    header('Content-Length:'.filesize($path));
    header('Content-Disposition: attachement; filename="pibooth-'.$image.'"');
    echo file_get_contents($path);
  }catch(\Exception $e){
    http_response_code(500);
    echo 'Error downloading image ('.$image.')';
 }
else{
  http_response_code(400);
  echo 'No image defined';
}
exit();

TO DO:

BramWerbrouck commented 4 months ago

I added a new variabele {ip} which stands for yout local IP address by changing the code in pibooth_qrcode.py from:

def state_processing_exit(cfg, app): url_vars = {'picture': app.picture_filename, 'count': app.count, 'url': getattr(app, 'previous_picture_url', None) or ''} in: def state_processing_exit(cfg, app): url_vars = {'picture': app.picture_filename, 'count': app.count, 'url': getattr(app, 'previous_picture_url', None) or '', 'ip':get_ip()}

and adding: def get_ip(): testIP = "8.8.8.8" s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.connect((testIP, 0)) ipaddr = s.getsockname()[0] return "http://" + ipaddr

The IP address is automaticaly found and strored in de config.cfg file. Now you are able to download the resultpicture via the QR code to your phone IF you are on the same netwerk

Maybe the code itself can be written in a better way, feel free to help me out on this :-)

yoannpwln commented 3 months ago

Hello,

I have an issue with your solution...

I'm on RPI 4 and OS version : bookworm.

I try to change user and give access to start correctly but nothing ....

Can you help me to understand the problem and if you have a solution, i'll take it.

image

Thanks you for your help

BramWerbrouck commented 3 months ago

I did not tested this on Bookworm. But when I look at your error, you have a permission error for /var/html

sudo chmod -R 777 /var/html in the console should solve this problem. Can you try this and give some feedback?