Smart classroom with IOT system (attendance system using Raspberry pi and STM32)



Abstract :

 In today’s world automation, gaining a lot of importance and IOT is becoming more popular day by day. Technology has affected us in every aspect of our life right from communication to education.  Quality of education is an essential requisite in today’s competitive environment. The Smart Learning approach provides learners of all ages and backgrounds with a framework and a host of Smart Thinking Tools that motivate higher levels of understanding

This project focuses on smart classrooms by installing connected devices and smart Display systems.

What is a smart classroom?

It’s a new educational concept. On the one hand, a smart learning environment enables learners to access digital resources and interact with learning systems in any place and at any time.On the other hand, it actively provides the necessary learning guidance, hints, supportive tools learning suggestions to them in the right place, at the right time and in the right form.


                      
Smart Classroom research and development project aims at combining entrepreneurial pedagogy, collaborative teaching, and the latest technological teaching tools to create a modern and effective education service environment in a higher education setting




you can find a long list of terms and expressions that can describe smart classroom in several ways, this article may help you :


There is an interesting element that is essential in the smart class such as the Smart Board.

Smart Board Technology in the classroom can enrich your curriculum by taking a typical lesson and turning it into a fun and more interactive one.
 To know more about some of the amazing advantages of utilizing technology in the classroom by having a smartboard in your classroom please follow this link :

Project Description:

Raspberry Pi is used as the controlling system, sending students information to the MySQL hosting server.

The STM32f4 board will be used to collect certain data from the RFID card.
In this paperwork, a smart classroom application is proposed and developed in order to monitor the attendance of the students in a classroom environment. Using MySQL, C programming language, phpMyadmin we will start by collecting basic information about students.

The attendance system using RFID

Radio Frequency Identification technology is used at universities, school, and business sites. Several studies are published in this field for improving and replacing the classical method of taking attendance.


The RFID technique gives several benefits over the classical method of taking attendance in class,
whereas, the system is able to uniquely identify each person depending on their RFID tag so that
  the operation of taking the attendance is easier, faster, and more secure compared with the classical method.

MySQL:
                                         

Is a very fast robust relational database management system (RDBMS). With a database, you can efficiently store, search, sort, and retrieve data. The MySQL server controls access to your data to ensure that multiple users can work with it, provide quick access to it, and ensure that only authorized users to gain access. Therefore, MySQL is a multithreaded server with multiple users. It uses Structured Query Language (SQL), the database's default query language worldwide



phpMyAdmin :




Is a free web application that provides a convenient GUI for working with the MySQL database management system. It is the most popular MySQL administration tool that is used by millions of users worldwide and has won numerous awards and honors.

Before starting the coding part, Let’s define the database

In simple words, Data can be facts related to any object in consideration for example;
your name, age, weight, height, identity card number (ID) and your home address are some data related to you. 


Now, what is a DataBase?


We all know what Data is, but this data cloud could be random. A database is a systematic collection of data. Database support storage and manipulation of data. Database makes data management easy.


DBMS  stands for Data Base Management System
is a collection of programs which enables its users to access DATABASE and Manipulate data.
It accepts commands written in a language called SQL to create the database’s structure, store data and search /retrieve it.

This video illustrates a great example to describe the database concept 



What is Database Hosting?
Database hosting is the art and science of providing a managed server that is optimized for running a relational database.  Almost any host can run a web server, mail server, file share, or other file-based application.  Databases are different in that they demand specific hardware and software configurations to correctly support the database.

In our project, we chose the “free MYSQL hosting” server for our database
Right after creating an account in this server, you will receive immediately an email which contains the basic information about the database server, size and other details as it’s shown below :

  1. The received e-mail :

Your MYSQL host will be updated in this way :



Some of the advantages of this MYSQL hosting server :

  • Multi-user access
  • Enhanced connectivity
  • Scalability (easily handles large databases)
  • Speedy performance
  • Open source (free to use and large support community)


You can use another MYSQL hosting servers like Infinity Free



Based on the MYSQL reference manual:  we used specific Data manipulation statements such as :
 SELECTINSERTUPDATEDELETE, SET.

Here is a full documentation about the world's most popular open source database MYSQL,
(this link will lead you directly to the manipulation statements part)


Before coding, you will need to connect to your server and fill in the blanks the required information.

 Now, it’s time for coding J 

The first section is for declaring variables and initializing data fields :

----------------------------------------------------------------------------------
-- Company: 
-- Engineers: Ibtihel Ben Ali and Mohamed Taher Massrouki
-- 
-- Create Date:    19:28:06 7/08/2018 
-- Design Name: 
-- Module Name:    attendance students system  
-- Project Name: Smart classroom with IOT system 
-- Target Devices: 
-- Tool versions: 
-- Description: 
--
-- Dependencies: 
--
-- Revision: 
-- Revision 0.01 - File Created
-- Additional Comments: 
--
----------------------------------------------------------------------------------


#include <mysql/mysql.h>
#include <stdio.h>
#include <string.h>
int scanstr(char *chaine, int longeur ); 
int main() {   
    MYSQL *conn ;
    MYSQL_RES *res ;
    MYSQL_ROW row ;
    int qstate ;
    //My database account setup
    char query[200];
    char *server = "sql7.freemysqlhosting.net";
    char *user = "sql9263462";
    char *password = " MwQbVQ5gIf";  
    char *database = "sql9263462";
    conn =mysql_init(NULL); 
   
//preparing the data related to every student
    char id[100] ; //(C.I.N)
    char name[100]; // (NAME)
    char phone[100]; // (PHONE)
////// Connect to database
   
if (!mysql_real_connect(conn, server,user, password, database, 0, NULL,0))      
{
       
fprintf(stderr, "%s\n", mysql_error(conn));
       
exit(1);
      
}
  
if (conn)
     
{
       
printf("----------------- Hello in your database ----------------\n");
char choose[0];
choose[0]='0';
while(choose[0] !='q')
      
{
///////////Read from Database query ///////////
  if (choose[0]=='1')
           {     
        qstate = mysql_query(conn, "SELECT * from mcastudents");
                
if(!qstate)
           { int i = 0;
              res = mysql_use_result(conn);
                printf("MySQL Tables in mysql database of Smart Classrom By BeaTaher :\n");
              while ((row = mysql_fetch_row(res)) != NULL)
                { i++;
                  printf("--- student %d --- \nC.I.N       : %s \nName        : %s \nPhone Number: %s \n\n\n", i,row[0] , row[1] , row [2]);
                }
                i=0;
            }
               mysql_free_result(res);    
              }            
printf("\n\nTo print database type \"1\"   \n");
     printf("To add studant type \"2\"   \n");
        printf("To update student's data type\"3\"  \n");
        printf("To delete studant type\"4 \" \n");
        printf("To quit type \"q\"          \n");
     scanstr(choose, 10);
  
/////////// Insert into Database query////////
if (choose[0] =='2')
        {
        printf(" \n---------------- INSERT ----------------\n");
        printf("enter Id : ");
     scanstr( id, 100);
        printf("enter Name : ");
      scanstr(name, 100 );
    printf("enter phone : ");
        scanstr(phone, 100);
char query[200] = "INSERT INTO mcastudents values (";


 Section two is devoted for filling and sending the necessary data to the server :



///filling  field 1
       for( int a = 0; a < strlen(id); a ++ )
                {
            query[a+32] = id[a] ;
                }
     
query[32+strlen(id)]=',';        
 query[32+strlen(id)+1]='"';
       //// filling field 2
       for( int a = 0; a < strlen(name); a ++ )
            {
              query[32+strlen(id)+2+a] = name[a] ;
                }
    query[32+strlen(id)+2+strlen(name)]='"';        
       query[32+strlen(id)+2+strlen(name)+1]=',';      
       //// filling field 3
       for( int a = 0; a < strlen(phone); a ++ )
           {               
query[32+strlen(id)+2+strlen(name)+2+a] = phone[a] ;               
}
       query[32+strlen(id)+2+strlen(name)+2+strlen(phone)]=')';        
       query[32+strlen(id)+2+strlen(name)+2+strlen(phone)+1]='\0';
  ///start the connection
qstate = mysql_query(conn, query);
        if(!qstate )
            printf("\n\nStudent inserted successfully \n\n\n" );
        else
         {   
fprintf(stderr, "%s\n", mysql_error(conn));
         }
       }

The third section is about manipulating data with certain controlling statements as "update", "insert", "select "and "delete". 


/////////// Update query ///////////
  if (
choose [0]=='3')
         { 
          printf(" \n---------------- Update ----------------\n");         
printf("\nTo update name type 5 ; To update phone number type 6 \n ");
      scanstr( choose, 100);          
printf("\nenter Id : ");       
scanstr( id, 100);
           
///// Update Name
if ( choose [0]=='5')
            { 
printf("\nenter new name : ");
           scanstr( name, 100);
            char query21[200] = "UPDATE mcastudents SET name= \"";
    // filling the name’s field
           for( int a = 0; a < strlen(name); a ++ )
            {
                query21[30+a] = name[a] ;
                }
            char query211[15] ="\" WHERE id=" ;
            for( int a = 0; a < strlen(query211); a ++ )
            {
              query21[30+strlen(name)+a] = query211[a] ;
                }
            for( int a = 0; a < strlen(id); a ++ )
                {
             query21[a+30+strlen(name)+strlen(query211)] = id[a] ;
                }
           query21[30+strlen(name)+strlen(query211)+strlen(id)+1]='\0';
         qstate = mysql_query(conn,query21);
            printf("Name updated");
            }
  ///// Update phone number
     if ( choose [0]=='6')
            {
printf("\nenter new phone number: ");
   
scanstr( phone, 100);
      char query22[200] = "UPDATE mcastudents SET phone= ";
// filling the phone number’s field
for( int a = 0; a < strlen(phone); a ++ )            
{
         query22[29+a] = phone[a] ;
               
}       
           char query221[12] =" WHERE id= ";
             
for( int a = 0; a < strlen(query221); a ++ )
                {
                query22[29+strlen(phone)+a] = query221[a] ;
               
}
 for( int a = 0; a < strlen(id); a ++ )            
{
            query22[a+28+strlen(phone)+strlen(query221)] = id[a] ;
                }
       
query22[29+strlen(phone)+strlen(query221)+strlen(id)+2]='\0';
qstate= mysql_query(conn,query22);
            printf("Phone number updated");
            }
         }
     if (choose [0]=='4')
         {
           printf(" \n---------------- DELETE ----------------\n");
           printf("enter Id : ");
           scanstr( id, 20);
                 
char query1[200] = "DELETE FROM mcastudents WHERE id=" ;
                      
for( int a = 0; a < strlen(id); a ++ )
                {            
query1[a+33] = id[a] ;         
}         
printf("\n\nStudent deleted \n\n\n");
           qstate = mysql_query(conn,query1);
       
}
       }// no quit
       } //end if connection
mysql_close(conn);          //close connection 
      return 0;
    }


In this last section of the program , we will give some indication about the reason behind using fgets() instead of scanf() function
There are multiple differences. Two crucial ones are:
  •        fgets() can read from any open file, but scanf() only reads standard input.
  •            fgets() reads 'a line of text' from a file; scanf() can be used for that but also handles conversions from string to built-in numeric types.                                                                        

We give you this good example that can briefly explain the effects of scanf function in certain cases 




///// Fonction solution de saisir un texte //////
int scanstr(char *chaine, int longueur)
{
    char *positionEntree = NULL;
  char  *Adresse_initialle = positionEntree;
  int n ;
// On lit le texte saisi au clavier
    if (fgets(chaine, longueur, stdin) != NULL)  // Pas d'erreur de saisie ?
    {  
       positionEntree = strchr(chaine, '\n'); // On recherche l'"Entrée"
       if
(positionEntree != NULL) // Si on a trouvé le retour à la ligne
  {
              *positionEntree = '\0'; // On remplace ce caractère par \0
    }
      
return 1; // On renvoie 1 si la fonction s'est déroulée sans erreur
    }
    else
    {
    
return 0; // On renvoie 0 s'il y a eu une erreur
    }
}


To run the C code on raspberry pi use this command line :
gcc first.c –o first `mysql_config - - cflags  - -libs`
sudo ./first
You will see in terminal of Raspberry pi your MSQL Table in this format :




The SQLTable is updated in phpmyadmin as well :




RFID MFRC522 using STM32F407

The MFRC522 is a highly integrated reader/writer IC for contactless communication at 13.56 MHz.
    

The following host interfaces are provided:
                       
Serial Peripheral Interface (SPI) up to 10Mbit/s
• Serial UART (similar to RS232 with voltage levels dependant on pin voltage supply)
• I2C-bus interface 


The MFRC522 identifies the host interface by sensing the logic levels on the control pins after the reset phase. This is done using a combination of fixed pin connections.

Select the UART interface: 
– Pin #1 (I2C) must be connected to 0 voltage
– Pin #32 (EA) must be connected to 0 voltage
Select the SPI interface: 
– Pin #1 (I2C) must be connected to 0 voltage
– Pin #32 (EA) must be connected to 1 voltage


In the next article, we will show you how to control MFRC522 via SPI2 using STM32F407.
Before examining the code,
we should have a quick look at the interfacing Board and MFRC522.

·         The SPI2 of STM32 is selected to communicate with RC522 at 9MHz speed.
·         STM32 is operating as Master, and  RC522 is operating as a Slave.
·         Both the RTS and VCC pins of RC522 must be connected to +3.3V supply and the GND pin of RC522 to the GND pin of STM32.


A brief Introduction to GraphQL that we will use in our project :



GraphQL is a query language for APIs and a runtime for fulfilling those queries with your existing data. GraphQL provides a complete and understandable description of the data in your API, gives clients the power to ask for exactly what they need and nothing more, makes it easier to evolve APIs over time, and enables powerful developer tools.
For more details, click on the link below:


QT c++:
  
Qt (pronounced as "cute", not "cu-tee") is a cross-platform framework that is usually used as a graphical toolkit, although it is also very helpful in creating CLI applications. It runs on the three major desktop OSes, as well as on mobile OSes


command-line interface or Command Language Interpreter (CLI), also known as command-line user interface, console user interface and character user interface (CUI), is a means of interacting with a computer program where the user (or client)  issues commands to the program in the form of successive lines of text (command lines). A program which handles the interface is called a command language interpreter or (shell computing)

Here is a full description of the Qt tool 

       

QT can also allow us to create a database with QtSql  classes and interfaces   




This is an example of a database created by Qt while the data are ID, the first and last name of each person. Using Database classes you will manipulate easily your data.

A full documentation is provided about connecting to the database under QT and QSQL query functions:





For more information:

contacts beaibtihelbenali@gmail.com and mohamedtahermassrouki@gmail.com

Our LinkedIn accounts

https://www.linkedin.com/in/mohamed-taher-massrouki-45832614a/
   and  https://www.linkedin.com/in/ibtihal-ben-ali-804189148/

Hope you enjoy it: #the_future_is_bright


Comments

  1. The website is looking bit flashy and it catches the visitors eyes. Design is pretty simple and a good user friendly interface.
    Attendance Control System

    ReplyDelete
    Replies
    1. thank you , I will work more on that in my next blog ( coming soon ) , it has been a very long time already

      Delete
  2. thank you . I miss posting again really :D

    ReplyDelete
  3. high five "redhead" ! xD no idea how this came across me so big hope u reach success and those dreams u seek!
    PS: dont reply to this :p
    PPS: hope u okay

    ReplyDelete
  4. very very informative post for me thanks for sharing

    Blockchain Course in Bangalore

    ReplyDelete
  5. IoT (Internet Of Things) systems are spearheading these incredible developments. IoT has the power to assist you in making correct decisions based on data it collates to streamline every aspect of human activity and make life simple. Making this possible is a network of sensors and actuators in IoT systems that erase the division between the physical and digital smart classes.

    ReplyDelete
  6. kya aap bhi apni sex karne ki timing badhane chhate hain toh aaj mein aap ko time badhane ke condom kaun se hain unke baare me bataunga ye vo condom hain jo aapke sex karni ki timing increase karne mein help karega

    ReplyDelete
  7. Excellent explanation. Thank you for providing such useful information. custom erp software

    ReplyDelete

Post a Comment

Popular posts from this blog