Skip to content

This project showcases a simple inter-connectivity among server, mobile application and hardware. The mobile application (android) majorly deals with user input and exchanges data with the server (PHP). The server in turn publishes data onto the MQTT channel. The hardware (raspberry pi 3) is connected to the same MQTT channel and depending on th…

License

Notifications You must be signed in to change notification settings

iamsudiptasaha/smartToll_server

Repository files navigation

smartToll_server

Smart Toll

This project showcases a simple inter-connectivity among a server, a mobile application and a hardware. The mobile application (android) majorly deals with user input and exchanges data with the server (PHP). The server in turn publishes data onto the mqtt channel. The hardware (raspberry pi 3) is connected to the same mqtt channel and depending on the message sent over the channel does specific operation.

Proposed Working Principle:

Consider a metro station with tollbooth. Commutators scan a QR Code on the tollbooth which unlocks the toll gate. The travel through the metro and once they reach the destination station, they scan the QR Code on the toll booth again to unlock the gate. The transaction not only gets recorded but the entire process requires no physical exchange of money.

  • A tollbooth consists a QR Code attached to it.
  • The QR Code encodes the station and gate number of the tollbooth. This helps to note which tollbooth is the commutator using. The information is sent to the server when the QR Code is scanned.
  • Use the mobile application to scan the QR code on the tollbooth.
  • Data associated with the tollbooth and user is spent over to the server.
  • Server updates the database and spends message over MQTT Channel to open the connected toll gate.
  • Simlarly the commutator can unlock the gate at the destination station.

Requirements:

  1. Raspberry Pi/Arduino - This handles the hardware part of the system. We have used Raspberry to avoid the trouble of setting up ethernet for arduino.
  2. Ultrasonic Sensor (HC-SR04) - This will enable the auto closing of the gate after a commutator passes through the gate.
  3. Server - This handles the centralized transaction and updation of user records. We have used XAMPP and coded our server with PHP.
  4. Mobile Application - This handles the interaction with the user. The camera of the mobile scans the QR Code and use internet to relay data to the server. We have used Android.
  5. MQTT Broker - (Message Queuing Telemetry Transport) In lucid terms it is just a channel where devices can publish or subscribe to a topic. There are many free brokers available for testing!
  6. Database System - Store the user data for authentication, transaction and tour details. We have used MYSQL.

Repositories:

About this repository:

This repository contains our PHP functionalities to handle the server. The PHP is coded using vanilla framework, so that developers can get a rough idea of the basic operations. It is recommended to use PHP frameworks that support MVC Architecture. The code is documented as and where required.

Link to download PHP MQTT : https://github.com/bluerhinos/phpMQTT

Link to download XAMPP : https://www.apachefriends.org/download.html

Set up the MySQL Database:

  1. Customer Record Table - Stores records of the customers.

    CREATE TABLE `cusrecord` ( `id` int(11) NOT NULL AUTO_INCREMENT, `username` varchar(50) NOT NULL, `password` varchar(100) NOT NULL, `name` varchar(100) NOT NULL, `phoneno` varchar(15) NOT NULL, `joindate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`), UNIQUE KEY `username` (`username`) ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1

  2. Tour Record Table - Stores tour information of every user.

    CREATE TABLE `tourdetails` ( `tourid` varchar(15) NOT NULL, `userid` int(11) NOT NULL, `station_from` varchar(50) NOT NULL, `entry_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `station_to` varchar(50) DEFAULT NULL, `exit_time` timestamp NULL DEFAULT NULL, `status` int(11) NOT NULL DEFAULT '0', `tourcost` int(11) NOT NULL DEFAULT '5', PRIMARY KEY (`tourid`), UNIQUE KEY `tourid` (`tourid`), KEY `userid` (`userid`), CONSTRAINT `tourdetails_ibfk_1` FOREIGN KEY (`userid`) REFERENCES `cusrecord` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION ) ENGINE=InnoDB DEFAULT CHARSET=latin1

  3. Bank Account Table - Stores bank records of the customers. This is a replica of the banking system. In real time you will have to link existing third party banking systems.

    CREATE TABLE `bankaccount` ( `id` int(11) NOT NULL AUTO_INCREMENT, `username` varchar(50) NOT NULL, `money` double NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `username` (`username`) ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1

Server Page Definitions :

  1. cus.getEntryInfo.smartToll.php - This page returns information about a tour based on tourid.
  2. cus.getHistoryEntry.smartToll.php - This page returns information about all the tours associated with an user.
  3. cus.getLastEntry.smartToll.php - This page returns information about the last tour associated with an user.
  4. cus.login.smartToll.php - This page returns information about an user if correct username-password pair is supplied.
  5. cus.manageBankAccount.smartToll.php - This page is a replica of a bank account having simple transaction functionalities for the user.
  6. cus.setEntry.smartToll.php - This page is used to update the current status of an user and set the entry information.
  7. cus.setExit.smartToll.php - This page is used to update the current status of an user and set the entry information.
  8. cus.updateBankAccount.smartToll.php - This page is a replica of a bank account having simple transaction functionalities to add money to bank account.
  9. DatabaseConnect.smartToll.php - This page makes connection to the database.
  10. phpMQTT.php - The downloaded MQTT Script.

Miscellaneous informations :

  • Please update the MQTT authentication details in the files!
    1. cus.setEntry.smartToll.php
    2. cus.setExit.smartToll.php
  • Return values : JSON Encoded data. Contains two mandatory fields to determine successful server operation:

    "sucess" : "true"/"false" - If the operation was successful or not.

    "errorCode" : If sucess is false then we may get the following error codes. The associated error is mentioned alongside.

    • "1" = Invalid data or empty data.
    • "2"= Improper option.
    • "3"= Failed DatabaseConnectivity, try again.
    • "4"= Duplicate username, rejected.
    • "5"= MYSQL error.
    • "6"= no such user

  • Tour status : Different status codes for tours and their associated status is mentioned along side:

    • "0" = Default tour status value.
    • "1"= Travelling.
    • "2"= Completed.

About

This project showcases a simple inter-connectivity among server, mobile application and hardware. The mobile application (android) majorly deals with user input and exchanges data with the server (PHP). The server in turn publishes data onto the MQTT channel. The hardware (raspberry pi 3) is connected to the same MQTT channel and depending on th…

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages