PN532 connected to Pi 3b+ open URL with tag

Hi there,

I am using a PN532 on a Pi 3b+ using the SPI interface to detect the tags. I have coded tags with a URL and am looking for a code that would open these URL’s when the tag hits the hat, I have struggled to find any codes that actually activate the URL rather they just provide information on the URL like they would the UID. Any suggestions / thoughts?

Thanks

Renee

1 Like

Hey @Renee294992 ,

This sounds like a cool project! I have played around with a few PN532 HATs before, they are a lot of fun.

Would you be able to tell us more about how you want to open these URLs? Is the intention to have your Pi outputting to a display and have a browser window open up the URL when the tag is detected, or are you trying to achieve something else?

They are! Yes that is exactly what we are hoping to achieve. For context we are developing a prototype that could support a health monitoring initiative where individuals own their own data. We are simulating a bit of it for the prototype but what we a hoping to show is how a wearable would add a extra layer of security by utilising a NFC tag that holds the URL which hosts this information.

I have currently coded one of the tags with a dummy URL to test this concept but am struggling that next step which would be exactly as you stated :slight_smile:

Hi, @Renee294992,

Probably the easiest way to do this is to open a subshell with the Python script. This would essentially load the Pi’s BASH Shell and send the URL to the default browser. This might be quite slow on the 3B+, so you may need to find a low memory browser.

Something like this should work:

import os


URL = yoururl 
os.system(f'xdg-open {URL}')

Two things to note, however:

  1. This will open the URL, but closing the webpage will have to be done manually.
  2. That code will open ANY URL you are given which leads you with a major security risk. You can get around that by having code that will compare the received URL to the correct domain before it opens the URL, but you still want to be careful.

I just tested this and have a slight correction.

If the URL does not specify ‘http://’ or ‘https://’ at the front of the url, you will receive an ‘Open File does not work’ error.

You should make sure the protocol is specified in what is read from the RFC tag.