AnswerBun.com

RFID RC522 Reader & Chromium Web Page

Raspberry Pi Asked on December 5, 2020

I’m having a bit of difficulty locating a specific example, however I have found people referencing that they have accomplished what I am looking for.

At a basic level, I have a webpage being served through Chromium and I have my RC522 RFID module. What I’d like to do is be able to scan an RFID card and to submit the ID of the RFID either through an AJAX script or pull the ID into an input field.

I’m fine with the web side and the page itself, but I am still learning Raspberry Pi, and this is a bit beyond what the little DIY books discuss haha.

There are cases like these where they pull the RFID through Python:

https://rickyventrella.com/2017/05/08/raspberryrfid/

http://helloraspberrypi.blogspot.com/2015/10/raspberry-pi-2-mfrc522-python-dump-rfid.html

https://www.electromaker.io/blog/article/launch-applications-using-an-rfid-card-reader-and-raspberry-pi

And then there is a case like this one where I get close, but it doesn’t seem to quite get there:

http://www.blog.emmeshop.eu/node/48

If anyone can give me any leads or suggestions, I’d greatly appreciate it. Our little museum is trying to update ourselves for grants and some things are doable and others are a stretch.

Thank you so very much –
Matt

//—–UPDATE—–//

My issue is the connection of the two. I’m in new territory here and not sure how I would pass the data from the RFID reader to the Chromium browser. If I use the basics through this python GIT – https://github.com/mxgxw/MFRC522-python – and use the read.py file through the console, I can easily pull the ID from the RFID chip/card. But I’m not sure how I’d be using the script in the background and passing the RFID ID to the Chromium browser.

I’ve continued to browse around the internet and found that some people have suggested using node.js instead to pass the data from the RFID Card and Reader to the Chromium browser.

I’m open to any suggestions, some of these posts I’m sifting through are older and I’m not sure if one suggestion is better off than the other for recent updates of Raspberry Pi and its operating system. Even the python I mentioned above, which is widely used, states that their haven’t been any large overhauls to the code and at some point, might become unusable as Raspberry Pi progresses.

One Answer

We achieved this using php.

using python to load the site with ?id=(your id variable).

then in the php using $_GET['id'].

Edit as requested:

Python:

import RPi.GPIO as GPIO
import SimpleMFRC522
import time
import urllib
import pygame
reader = SimpleMFRC522.SimpleMFRC522()

while True:

    try:
            id, text = reader.read()
        print(id)
            url =("https://our.url.com/rfid.php?card_id={}&card_value={}".format(id,text))
        print(text)
        print (url)
        urllib.urlopen(url)
        pygame.mixer.init()
        pygame.mixer.music.load("/home/pi/Music/Beep.wav")
        pygame.mixer.music.play()
        while pygame.mixer.music.get_busy() == True:
             continue   
        time.sleep(1)

    finally:
            GPIO.cleanup()

Php:

<?php
date_default_timezone_set('Europe/London');
$card_id = $_GET['card_id'];
$card_value = $_GET['card_value'];
$time_out = date('Y-m-d H:i:s.ms ', time());
include ($_SERVER['DOCUMENT_ROOT']."/_includes/pdo_intranet.php");

try {
        $sql = "INSERT INTO `rfid` (`card_id`, `card_value`) VALUES ('".$card_id."', '".$card_value."')";
        $pallet = $conn->query($sql);
    }
catch(PDOException $e) {
    echo "DB ERROR: " . $e->getMessage();
}

?>

Ignore some of our weird variable names, I hope this can help point you in the right direction.

This stores the id and name into a database, i suppose you can then use ajax to do what you want.

Answered by Carl Piper on December 5, 2020

Add your own answers!

Related Questions

Raspberry 4 usbmount not working

5  Asked on December 12, 2021 by papatrexas

   

RPI 4B – Bluetooth unavailable on Ubuntu 20.04

1  Asked on December 12, 2021 by aymdev

     

Autostart chromium browser other user than pi

2  Asked on December 12, 2021

   

3B+ fails to boot Ubuntu mate

1  Asked on December 10, 2021 by washy

   

What is going on with my GPIO pins?

1  Asked on December 4, 2021 by dubstepzedd

 

can’t login after modifying .bash_aliases

0  Asked on December 2, 2021 by abstract

 

Network boot with rootfs on USB3 drive fails with Ubuntu 20.04

1  Asked on November 30, 2021 by peter-wishart

     

Alpine Linux – Changing/Moving the file system

1  Asked on November 25, 2021 by lisandro-di-meo

 

3.5 Inch RPi LCD with colors problem

2  Asked on November 25, 2021 by gabriel-schubert

   

Sub-process /usr/bin/dpkg returned an error code (1)

2  Asked on November 23, 2021 by lolok

   

PWM issues with pigpio and RPi.GPIO

2  Asked on November 23, 2021

       

Can I identify my PI by domain name in a LAN?

3  Asked on November 21, 2021 by dorin-botan

     

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP, SolveDir