Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Local IP to download the picture #22

Open
BramWerbrouck opened this issue Apr 9, 2024 · 4 comments
Open

Local IP to download the picture #22

BramWerbrouck opened this issue Apr 9, 2024 · 4 comments

Comments

@BramWerbrouck
Copy link

BramWerbrouck commented Apr 9, 2024

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
Copy link
Author

BramWerbrouck commented Apr 28, 2024

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/
  1. 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 (*)

  1. 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:

  • Making the ip address variable (maybe with a script: when pibooth starts: it detects your ip address and saved it into the config-file

@BramWerbrouck
Copy link
Author

BramWerbrouck commented May 5, 2024

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 :-)

@BramWerbrouck BramWerbrouck changed the title QUESTION Local IP to download the picture May 5, 2024
@yoannpwln
Copy link

yoannpwln commented Jun 14, 2024

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
Copy link
Author

BramWerbrouck commented Jun 14, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants