Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to Display a QR code
#1
Hi, this is my first post so go easy on me, haha.
I have very limited python experience so learning as i go. I apologise for the long winded nature of the post and any noob? mistakes in advance

I'm a beekeeper and i want to take photos during my inspections and be able to identify them automatically at a later point. (they all look the same at the end of the day) for record keeping and bio-security purposes.

I am trying to write a programme to create a qr code which is made up of a date.timestamp and a few user inputs that can be displayed on the screen ( this will be eventually replaced by RFID inputs). I wish to then take a photo of the QR code (and the frame out of a beehive) that is emailed, renamed and sorted to the correct folder.

I have so far managed to get a date and time stamp to generate whenever I run the script along with the programme asking me for the inputs that go along with the date & timestamp into making the QR code. I can make the code just fine but i want to be able to display it on the screen automatically so that when the programme continues to take a photograph of the frame and the QR code it has the right one.

At this stage i need to manually open the image file of the qr code and put it on the 5" screen i have with my PI4. This unfortunately means that the QR code is from the previous run of my programme and the timestamp will be incorrect for the image.

Can anyone help so that the Qr code generated is immediately shown on the screen so the photo has the right QR code on it?

import smtplib#,ssl  
from picamera import PiCamera  
from time import sleep  
from email.mime.multipart import MIMEMultipart  
from email.mime.base import MIMEBase  
#from email.mime.text import MIMEText  
#from email.utils import formatdate  
from email import encoders  
from PIL import Image
from datetime import datetime

# current date and time
now = datetime.now()

timestamp = datetime.timestamp(now)
print("timestamp =", timestamp)
dt_object = datetime.fromtimestamp(timestamp)

print("dt_object =", dt_object)
 
# asking for data bit to be replaced by autologging of RFID tag

Hive = input("Enter Hive Name")
Frame = input("Enter Frame Number")
Queen = input("Enter Queen Number")
  
# End of bit I added to get date and data

# Now i need the bit for the QR code generator

import qrcode
qr = qrcode.QRCode(
    version=1,
    error_correction=qrcode.constants.ERROR_CORRECT_L,
    box_size=10,
    border=4,
)
#add the data you want to store
qr_data = timestamp, Hive, Frame, Queen

#make qr code

qr.add_data(qr_data)
qr.make(fit=True)

img = qr.make_image(fill_color="blue", back_color="orange")

img.save('/home/pi/Python-3.8.0/QRImage.png')


img = Image.open('/home/pi/Python-3.8.0/QRImage.png')

img.show()

# this is the end of the qr code bit
 
camera = PiCamera()  
  
#camera.start_preview()  
#sleep(1)  
camera.capture('/home/pi/Python-3.8.0/image.jpg')     # image path set
#sleep(1)  
#camera.stop_preview()  
def send_an_email():  
    toaddr = 'mattlumb@**********.com.au'      # To id 
    me = '************@gmail.com'          # your id
    subject = "File with QR"                  # Subject 
  
    msg = MIMEMultipart()  
    msg['Subject'] = subject  
    msg['From'] = me  
    msg['To'] = toaddr  
    msg.preamble = "test "   
    #msg.attach(MIMEText(text))  
  
    part = MIMEBase('application', "octet-stream")  
    part.set_payload(open("image.jpg", "rb").read())  
    encoders.encode_base64(part)  
    part.add_header('Content-Disposition', 'attachment; filename="image.jpg"')   # File name and format name
    msg.attach(part)  
  
    try:  
        s = smtplib.SMTP('smtp.gmail.com', 587)  # Protocol
        s.ehlo()  
        s.starttls()  
        s.ehlo()  
        s.login(user = '***********@gmail.com', password = '*******')  # User id & password # this bit works well after changing security settings in GMail
        #s.send_message(msg)  
        s.sendmail(me, toaddr, msg.as_string())  
        s.quit()  
    #except:  
    #   print ("Error: unable to send email")    
    except SMTPException as error:  
        print ("Error")                # Exception
  
send_an_email()  
Reply
#2
I'm not 100% sure i understand what you want to do,
maybe this is a way forward: you can call a subprocess (executable)
from Python:
import subprocess
subprocess.call(['C:\.....\Irfanview....
Irfanview lets you define a default folder and it can be set to show the most
recent image in that folder.
?
my 2 cts,
Paul
Reply
#3
I agree it's not completely clear what you do - you annotate images taken earlier in the day, or you want QR code created and embeded into/combined with image at the time when you take it during the inspection of the hive

Maybe take a look at that thread
https://python-forum.io/Thread-Requireme...#pid107157
Creating web/GUI interface and maybe generating pdf with image and QR code, etc. is the way forward I think

Also, creating own software tool may be worth the effort if you also want to dive into programming, if not - why not use some of the available apps for diary of the hive (e.g. apiary book and similar) or even the smart systems for monitoring the hive (e.g. pollenity)?
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#4
Thanks DPaul and buran for the advice and apologies on clarity. Ill have a look and do some more research. I really appreciate the time you took to answer.

Matt
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to display <IPython.core.display.HTML object>? pythopen 3 45,908 May-06-2023, 08:14 AM
Last Post: pramod08728
Information Unable to display joystick's value from Python onto display box MelfoyGray 2 2,223 Nov-11-2020, 02:23 AM
Last Post: MelfoyGray
  NameError: name 'display' is not defined when running code on power bi beginner1 2 19,146 Jul-24-2019, 11:03 AM
Last Post: beginner1
  How To Display this Python Code in Web browser? pradhan 1 3,312 Jul-14-2019, 06:59 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020