This project aims to authenticate/authorize users from RFID tags using a simple integration with database.
The project aims to meet a pending that I already had with the theme in question and also to meet a demand from community users who seek such topics. - In 1 day, I think I saw about 3 people looking for something.
So let the games start - I hope you like it :)
In the above diagram, one can observe the flow of the application that was developed. It sounds complicated, but when you start understanding as if you give network communication, you take such an architecture.
Basically we have 2 flows in this project - the ping and the pong . Both will be addressed below.
The flow for ping is the initial flow of communication. It is from it that all communication had begun. See the image referring below:
Basically the steps below will be made:
... follows in the next topic
The Pong will be responsible for the return, ie if the read tag is active/blocked or simply does not exist. The result will be a simple boolean return - 0 or 1 . See how was the flow in the image below:
Therefore, continuing with the flow of application, continuity will be given according to the 5th step addressed in the topic above.
The repository is organized due to the responsibilities it offers.
The firmware as stated is located inside the ESP8266 folder, so open it with the Arduino IDE.
Note: Remember that you need to have 2 libraries installed, both were cited in the topic used technologies
Having the firmware already open, you will have to change some variables to your scope. Like wifi network, broker, topics.
So be aware of the following variables:
SSID - nome de sua rede wifi
PASSWORD - senha de sua rede wifi
BROKER_MQTT - url do broker mqtt
BROKER_PORT - porta do broker mqtt
TOPIC_PING - topico utilizado para publicar o valor tag rfid
TOPIC_PONG - topico responsavel por receber o status da autenticação rfid
Note an addendum to the broker used. This broker I have implemented on my PS for personal use. You can use it, but I do not guarantee 100% stability since all the time I am testing something new: p. The tip is to have your own Broker Mosquitto at home or in some VPS.
With every circuit of the board ready, now just upload the plate and keep an eye on the serial monitor. See if everything is ok. If you are, you are able to test your RFID tags to see if everything really is well regarding the shipped. Now let's go to the next topic.
Web application - located in the client folder, is 100% html, so you don't need anything extraordinary for you to run. You can even open directly with the browser.
Below are some tips for having a more pleasant test/development environment.
In the web application part, we have to make only 2 changes. It is basically the API URL and also the broker URL.
All URL's are in the app.js file, located in Assets/JS/App.js .
const apiPath = 'http://127.0.0.1:3000/api'; // caso esteja em localhost, pode deixar assim mesmo.
const mqttConfig = {
broker: 'broker.iot-br.com', // url do broker
topic: '/empresas/douglaszuqueto/catraca/entrada/ping', // topico ouvinte
port: 8083 // porta referente ao WebSockets do Broker
};
The database will be MySQL (I decided to choose it, as it is one of the best known, so most people have gone through it: P).
The name you assign to the database is RFID , if you want to choose another name without problems. The bank structure is within the Database/Database.sql file.
Basically there is no mystery, just create the structure according to the file :).
Entering the back end, as you may have realized, you will have 2 alternatives. In python or nodejs.
So far (05/06/2017), it has been developed only in Nodejs, as soon as I give, I will create one using Python with Flask.
For starters, nothing fairer than having the nodejs installed, do you agree? To do this, enter the official website and install according to your operating system.
Secondly, navigate to the Nodejs: Server/Nodejs folder.
Being in the folder, you should perform some initial procedures, such as installing project facilities as well as setting up access to the database, among other settings.
As a dependency manager I used Yarn, if you don't have it yet, the quote link will have the necessary steps.
Once installed, just run the Yarn command.
To centralize in a cool way the variables of our environment, I used Dotenv for this purpose.
You will realize that at the root of the project, it has a .env.example file, make a copy named .env . You will see this structure:
APP_URL=http://127.0.0.1:3000/ // url base do webservice
DB_HOST=127.0.0.1 // ip/host do Mysql
DB_DATABASE=rfid // nome dado ao banco de dados
DB_USER=rfid // usuário do banco de dados
DB_PASS=rfid // senha do banco de dados
BROKER_HOST=broker.iot-br.com // ip/host do broker
BROKER_PORT=1883 // porta do broker mqtt
Once configured, everything is ready to climb our Webservice.
To do this, just run the Yarn Prod command (one alias from the node index command)
If everything went well, you will have access to the WebService running at URL 127.0.0.1:3000/api . In the endpoints topic, available appeal will be treated.
For each table of our application - users, tags, Access_Log - we will have an API to make CRUD (Create, Read, Update, Delete) of each available feature.
Therefore, for each feature, you can make a request in the following format:
MÉTODO - URL - RECURSO
GET http://127.0.0.1:3000/api/tags
Neste simples caso, irá retornar todas tags cadastradas no sistema :)
With every environment ready, you can start tests. For this, have the id of your tags by hand.
Shortly thereafter, you should register in the system, and if, just like me that I only have two, I left an active tag and one disabled. Thus simulating an environment where a tag will be authenticated and another will be denied.
Bueno guys, for now that, I think I was able to achieve my goal where it was simply to demonstrate what a RFID tag authentication with database would be. I went a little beyond creating webrservice and etc, but it was a very cool ecosystem.
As you can see, this project is the basics of the basics. It has no layer of user authentication, encryption, ie - safety in general.
Another point that already asked me was about the automatic registration of the tag through the embedded, LEDs, LCD and etc - soon actually focused on the real goal.
I want to make a more complete project if there is a certain interest from the community, I confess that it was a very nice project to develop, even with all the 'simplicity' involved.
I'm staying here, any feedback, doubt - already know where to find me. So if you really enjoyed the project, be sure to leave that Star in the repository :). It is very important to assess what was the degree of contribution it caused.
Don't forget to follow the blog :): https://douglaszuqueto.com
If you enjoyed this and other projects I maintain, on 06/18/2017 I opened a recurring funding campaign to raise funds for a fulfill dedication to Open Source projects.
So if you want to help me, here is the link of my support. Thanks in advance: d.