Read UID from Card and Send to server via HTTP request

Hello Dear Friends
I want to get UID from RFID card using MFRC-522 and than send this UID to my server using HTTP GET request, based on answer I want to take some action, for example 1 - open door, 0 - red light

can someone help me with my project? thank you

Break the project into parts.

In this case... (You can tackle them in any order, or both at once... but keep them separate until working as parts...

Part 1...

Set up an Arduino with two push buttons. When one is pressed, send the character "A" to the server. When the other is pressed, send "B" to the server

Part 2...

Get the RFID module working. Have it send the UID to the serial monitor.

(See...sheepdogguides.com/arduino/aht1serimoni.htm for "what is serial monitor")

How are you planning on connecting to your 'server'?

(and what is this server?)

I posted some code/examples here:
http://forum.arduino.cc/index.php?topic=452765.msg3134238#msg3134238

That lets an Arduino (with Ethernet shield) connect to a local install of a WAMP server (but shouldnt matter what server you use I suppose)

MySQL
PHP
Apache (web server)

all free to install and test with if you like.

IMHO.. this project should be easy.

read card
get id
(not sure if you have to do any conditional checking on the id?)
send to server

(php script will handle insert/retrieval as well as response you want back)

parse response

and do whatever actions you want based on said response.

Dear XL97...

I've seen most of the steps you so clearly identified written up many times... but not the bit about ...

send to server

(php script will handle inser

Any good web pages on that out there? (Forgive me... my Google button broke earlier... but also I wouldn't know good advice from bad.)

Or can you post some approximate code for us to work from?

I can send a "thing" to an Arduino webserver, to, say, get it to turn an LED connected to the server on or off. I presume that to insert a record in a WAMP MySQL database (under my direct control) it is sort of similar? Just "ask the server" for a page of .php?

If your goal is to log users to a database PHP: MySQL Functions - Manual shows functions and examples. You could also save to a text file .txt or .CSV using file_put_contents.

tkbyd:
Dear XL97...

I've seen most of the steps you so clearly identified written up many times... but not the bit about ...

Any good web pages on that out there? (Forgive me... my Google button broke earlier... but also I wouldn't know good advice from bad.)

Or can you post some approximate code for us to work from?

I can send a "thing" to an Arduino webserver, to, say, get it to turn an LED connected to the server on or off. I presume that to insert a record in a WAMP MySQL database (under my direct control) it is sort of similar? Just "ask the server" for a page of .php?

That is correct.

Just call up the .php script and it will execute/do what its coded for.

In the link I posted in my reply to you.. there is a complete working example.

Including database set-up, insert and query (request) example .ph scripts..

as well as insert and query (request) .ino example files..

I posted some code/examples here:
Using MySQLConnector with Ethenet Shield 2 - #27 by xl97 - Project Guidance - Arduino Forum

Meat & potatoes of the post:

If you do want to learn how to make an Arduino send some data to a PHP script that is logged to a database, I have some example of code to:

set up an example database with a few test fields (columns)
2 php scripts (although with little effort could be combined into one I suppose) that handle saving data received from an Arduino to a database and also retrieve requested data/values from a database (MySQL)
and some example sketches that you can use for sending/saving data to a DB and requesting data from a DB, and you can test/run this all from a (free) local install of WAMP Server.

this is more or less a generic starting point... you will need to edit some things, like:

IP address for your network/ip range
right now there is now parsing of the returned data/response.. just outputs it all to serial monitor, so if you are expecting a 1 to turn on the led/pin..etc.. you need to add that portion to handle the data response as you see fit.

Package contains:
1 x db set-up script
2 x php files for saving send data and retrieving requested data (values)
2 x arduino sketches for sending/saving data and requesting data

All files:
http://dmstudios.net/misc/Arduino_Save_Retrieve_Database/Arduino_Save_Retrieve_Database.zip

MySQL table setup:
http://dmstudios.net/misc/Arduino_Save_Retrieve_Database/database_setup.txt

Insert Data PHP: (rename to .php instead of .txt)
http://dmstudios.net/misc/Arduino_Save_Retrieve_Database/insert_data2.txt

Retrieve Data PHP: (rename to .php instead of .txt)
http://dmstudios.net/misc/Arduino_Save_Retrieve_Database/get_data2.txt

Send/Log Data Sketch:
http://dmstudios.net/misc/Arduino_Save_Retrieve_Database/WAMP_server_logging_v1.ino

Request/Retrieve Data Sketch:
http://dmstudios.net/misc/Arduino_Save_Retrieve_Database/WAMP_server_requesting_v1.ino

The general concept is:

Saving/Logging Data:

  • Arduino requests specific .php script (see sketch and matching .php file)

  • Each 'adruino' has a device name (ie: LR_temp1 = living room temp 1 sensor for example) (which is sent over via query string parameter)

  • Each 'submission' (logging) of data checks to see if 'device name' is in the database.. if not, it makes a new entry with this device's IP address, timestamp, device name, and (sensor) value it needs to save/log. It the device name -is- already in the database, then it just updates that record with the new value (and ip and updated timestamp)

  • logging/saving doesnt have to be done through an arduino..

Requesting/Retrieving Data:

  • Arduino requests specific .php script (see sketch and matching .php file)
  • Arduino sends along its device name and list of query parameters WITHOUT values as its list of requested data.
  • PHP script checks database for device name.. if found it will loop through all query params (which should match the database columns you want data from) and get the matching data for the device name.

so if you just want to see what is in column/field value1... then you just send over the device name and value1.. if you also want the timestamp it was updated.. then you can add time_stamp to query params..

All files could be cleaned up a bit from commented out code.. and notes..

As always if there is a better way to accomplish this, I'm open for discussion. Not saying anything I do is the best way, just that is works for me. :slight_smile:

On a side note.. I just set up a Raspberry Pi 3, as a webserver (LAMP w/phpMyAdmin), along with an MQTT broker/server

There is even a quick and easy PHP class that lets you talk to an MQTT broker from a .php script!

This is perfect for a 'networked' example of what you want to do...

RFID card is read, transaction is logged/booked in a database, and you can then send an MQTT update (message) to all subscribed devices on the network.

(imagine you scan RFID card, and 5 ESP8266 wi-fi modules light up at same time, alerting whomever that the RFID card was scanned....etc..etc.. or whatever actions you want)

Absolutely magnificent!

Many thanks... had just what I was looking for... and lots of fun other ideas to pursue later.

Apologies for missing the bit I wanted in the broad vistas of useful stuff in the page you cited earlier... I did go looking!