Marco Bianchi

17 may 2017
Interface and application programming

This week we need to write an application that interfaces an input and / or output device.
To do this, I chose to use the rfid reader builded this week connecting it to a javascript program.
The main function of the program will be to manage users who will log on to the system through the use of magnetic cards and rfid reader.
I think I will try to implement this system even in my final project using it to manage the players at the table

Node js and Javascript

Javascript is a programming language often used to build graphical interfaces for web sites and webpages that, with the advent of nodejs, has become a complete language that allows you to produce complete applications.
Through the use of specific plugins, we can implement various features such as creating a web server, creating folders, or reading input or output devices through controllers.
The plugins used to control the controllers are:


Thanks to the library Firmata, Which implements the fimed protocol for communication between the controller and the computer, these plugins allow us to control and manage our cards.
Even though I'm a big fan of Battlestar Galactica I've chosen to use the two plugins Johnny Five for its compatibility with ESP modules.

Install all programs

First of all, in order to work, we have to install the following programs in our work environment:

  • Nodejs
  • Npm
  • Express
  • MongoDB

These are the instructions for installing nodejs using the node version manager (nvm):

sudo apt-get update
sudo apt-get install build-essential libssl-dev
curl -sL https://raw.githubusercontent.com/creationix/nvm/v0.31.0/install.sh -o install_nvm.sh
nano install_nvm.sh
bash install_nvm.sh
//reboot the pc
source ~/.profile
nvm install 6.0.0

After installing nodes, we must install the software that manages packages (npm) and a handy plugin that allows us to manage routing within the application:

sudo apt-get install npm
sudo npm install express -g
sudo npm install express-generator -g

To end our work stack we only have to install the database.

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
echo "deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list
mongodb-org-3.2.list
sudo apt-get update
sudo apt-get install -y mongodb-org
sudo cp Backup/Mongo/mongo.service /etc/systemd/system/mongodb.service
sudo systemctl start mongodb
sudo service apache2 restart

The Software

After finishing the work on stack we can download the software And initialize it. Once downloaded, you have to unpack the file, move inside the directory, and use the "npm install" command to download server dependencies and "bower install" to download the client dependecies. Import the database that is in the DB folder.
localhost:3000

tar -xvzf agarthi.tar.gz
cd agarthi
npm install
bower install
cd DB
mongorestore -d agarthi dump/agarthi
cd ..
npm start

The sensor

The program is written to read the modifications of a photoresist and a gyroscope.
To test them, simply load firmata on two separate arduino bard from arduino's idee examples than connect the photoresistance to the analog pin 2 on the first board and connect the gyro to the analog pin 5 (SCL) analog pin number 4 (SDA) pin 5 on the second one.
If properly connected, the program reads the variations of value in the two sensors and updates the web page using socket.io.

RFID

Could not read the value of the magnetic card using Johnny-five I used a specific plugin to read the serial console directly from nodejs.
The plugin name is node-serialport.js.
To make it work just load the scatch you find between the downloads and connect the card via USB cable to the PC running the software.


Downloads