Giter Club home page Giter Club logo

espauthabsent's Introduction

ESP AUTH ABSENT

Untuk versi bahasa Indonesia, Klik ini

A school attendance system that compatible with ESP32 and ESP8266 Microcontroller that supports WiFi and HTTP POST Request

Runs on Express.js with Node.js

Compatible with MySql Server and Firebase Firestore

Can be run with other app, including PHP as long as they are in different ports

With version 2.1.1, now runs with MQTT Server running on Aedes which provide faster data transfer than http (Should have realized sooner)

Contents

Requirements

Requires NPM, to get NPM please install Node.js

Download Node.js

Requires the pm2 package enabled globally

npm i pm2 -g

Dependencies

The application server used several packages:

  1. body-parser
  2. cors
  3. dotenv
  4. express
  5. express-rate-limit
  6. firebase-admin
  7. helmet
  8. http
  9. mysql
  10. pm2
  11. util
  12. aedes
  13. mqtt

Initial Setup

Before starting the server, configure the .env file located inside the server folder

For more information about what each lines means go to Process Environment

  1. Navigate to server folder
  2. Install all required package library with npm
  3. Configure the .env file
  4. If you used MYSQL, you can import the test table for attendance located inside the /server/mysql folder
  5. Add all your identities with their corresponding HexID inside the identity.json inside the /server/auth folder
  6. Go to mq folder, and install all package with npm
  7. Start the test

To install all package

npm i

To start the test

npm devmysql //If you are using mysql
npm devfirebase //If you are using firebase

To run the app, use pm2 library that you have installed globally

pm2 start appDefault.js --name espAuth //If you are using mysql
pm2 start appFirebase.js --name espAuth //If you are using Firebase Firestore
pm2 start index.js --name mqttLocal //Inside the mq folder

Identity Format

The identity.json file follows a specific format, you can change the format however you like to suit your database info

Reminder, if you don't use the recommended format, You have to change all functions parameters and the queries

However, there should always have a hexID key in every entry

The Format: { "hexID": The holder card HexID, "name": The holder name "number": The holder attendance number, "division": The holder class, "type": The holder type }

For type, it is used to specify if the holder is a master (Who should authorized attendance) or a follower (Who can only submit attendance if their master is already attend)

By default, the type are member and kaichou

Process Environment

For definition what process environment in Node.js means, please refer to this explanation from knowledgehut

The .env file in server folders contain severals variables which will be used by the application

For ease of use, just edit the .env file, you may edit the mysqlQuery.js and firebaseQuery.js to suits your query needs

  1. SERVER_PORT = Defines the port where the application runs, on default is 5128
  2. ESP_ORIGIN = Defines the IP Address of the ESP8266 or the ESP 32 or the client
  3. MYSQL_HOST = Defines the host server of the MYSQL Database
  4. MYSQL_USER = Defines the user who will be connected to the mysql host server
  5. MYSQL_PASSWORD = Defines the password that will be used to connect to the mysql host server
  6. MYSQL_DATABASE = Defines the Database that will be used from the Mysql Server
  7. MYSQL_ABSENT_TABLE = Defines the table that will be used for attendance query (primarily for inserting new attendance)
  8. FIREBASE_API = Defines the API key that will be used to connect to your Firebase Project
  9. FIREBASE_AUTH_DOMAIN = Defines the authorized domains to connect to your firebase project
  10. FIREBASE_PROJECT_ID = Defines the Id of your project that will be used by the app
  11. FIREBASE_STORAGE_BUCKET = Defines the your firebase storage bucket
  12. FIREBASE_MESSAGE_ID = Defines the Message Id of your Firebase project
  13. FIREBASE_APP_ID = Defines the your app ID that will be used to connect to Firebase
  14. FIREBASE_MEASUREMENT_ID = Defines the measurement ID of your firebase project
  15. FIREBASE_KEYS = Defines your admin secret keys to use in Firebase
  16. START_TIME = Defines the start time when data is allowed
  17. END_TIME = Defines the finish time when data is allowed

START_TIME SHOULD BE LESSER THAN END_TIME

To know how to get the Firebase credentials, please refer to their Documentation

Recommended Schemas

You can customized the query inside the firebase / mysql Query.js files respectively to suits your schemas need

But if you want ease of use, please follow this recommended schemas

For MySQL

userId name absentNum class type date status
int varchar(255) varchar char(5) varchar Datetime char(8)

For FireStore

TBA

Penjelasan

Sebuah sistem absensi sekolah yang kompatibel dengan mikrokontroller ESP8266 atau ESP32 yang mendukung fitur WiFi dan permintaan POST HTTP

Menggunakan Express.js dengan Node.js

Kompatibel dengan MySql Server dan Firebase Firestore

Dengan versi 2.1.1, sekarang berjalan dengan server MQTT menggunakan package Aedes yang memberikan kecepatan pertukaran data yang lebih cepat daripada HTTP (Seharusnya sudah sadar dari dulu)

Konten

Hal yang Dibutuhkan

Membutuhkan NPM, untuk mendapatkan NPM unduh dan install Node.js pada sistem

Download Node.js

Membutuhkan package pm2 untuk dinyalakn secara global

npm i pm2 -g

Package yang Digunakan

Aplikasi server membutuhkan beberapa package:

  1. body-parser
  2. cors
  3. dotenv
  4. express
  5. express-rate-limit
  6. firebase-admin
  7. helmet
  8. http
  9. mysql
  10. pm2
  11. util
  12. aedes
  13. mqtt

Setup Awal

Sebelum memulai aplikasi server, Atur file .env yang terletak di dalam folder server

Untuk mengetahui apa arti dari setiap baris di dalam file .env, pergi ke Lingkungan Process

  1. Masuk ke dalam folder server
  2. Install semua package yang dibutuhkan menggunakan npm
  3. Atur file .env
  4. Jika Anda menggunakan MYSQL, Anda bisa mengimpor tabel dari sebuah file yang terletak di dalam folder /server/mysql
  5. Tambahkan semua identitas bersamaan dengan hexID mereka di dalam file identity.json di dalam direktori /server/auth
  6. Pergi ke folder mq, dan install semua package dengan npm
  7. Mulai tes

Untuk menginstall semua package

npm i

Untuk memulai test

npm devmysql //Jika menggunakan mysql
npm devfirebase //Jika menggunakan firebase

Untuk menjalan aplikasi, gunakan pm2

pm2 start appDefault.js --name espAuth //Jika menggunakan mysql
pm2 start appFirebase.js --name espAuth //Jika menggunakan firebase
pm2 start index.js --name mqttLocal //Di dalam folder mq

Format Identitas

File identity.json mengikuti sebuah format spesifik, Anda bisa mengubah formatnya menjadi apapun yang Anda inginkan untuk menyesuaikan dengan kueri Anda

Perlu diketahui, jika Anda mengganti format yang direkomendasikan, Anda juga perlu mengganti parameter fungsi dan kueri

Walaupun demikian, harus selalu ada sebuah kunci hexID di dalam setiap entry

Formatnya: { "hexID": Identitas heksadesimal si pemilik kartu, "name": Nama si pemilik kartu, "number": Nomor absensi si pemilik kartu, "division": Kelas si pemilik kartu, "type": Tipe si pemilik karti }

Untuk type, dia digunakan untuk mendefinisikan apakah seseorang itu master (Orang yang memperbolehkan mulainya absensi untuk kelasnya) atau seorang follower (Orang yang bisa absen jika master sudah memperbolehkannya)

Secara default, isi dari type adalah member dan kaichou

Lingkungan Process

Untuk mengetahui lebih lanjut apa maksud dari Lingkungan Process / Process environment di dalam Node.js, pergi ke link ini

Filre .env di dalam folder server berisikan beberapa variabel yang akan digunakan di dalam proses aplikasi

Untuk kenyamanan dalam kegunaan, sunting saja file .env, Anda bisa menyunting file mysqlQuery.js dan firebaseQuery.js untuk menyesuaikan kebutuhan kueri anda

  1. SERVER_PORT = Mendefinisikan di port mana aplikasi berjalan, secara default aplikasi berjalan di port 5128
  2. ESP_ORIGIN = Mendefinisikan alamat sumber (alamat IP) dari ESP8266 atau ESP32 atau Client
  3. MYSQL_HOST = Mendefinisikan host / server di mana database MySQL berada
  4. MYSQL_USER = Mendifiniskan user yang akan terhubung ke database MySQL
  5. MYSQL_PASSWORD = Mendefinisikan password dari MYSQL_USER yang digunakan untuk terhubung ke host
  6. MYSQL_DATABASE = Mendefinisikan database apa yang akan digunakan
  7. MYSQL_ABSENT_TABLE = Mendefinisikan tabel apa yang akan digunakan untuk menginsert data
  8. FIREBASE_API = Mendefinisikan kunci API yang akan digunakan untuk terhubung ke Project Firebase Anda
  9. FIREBASE_AUTH_DOMAIN = Mendifinisikan domain yang terautentikasi untuk terkoneksi ke Project Firebase Anda
  10. FIREBASE_PROJECT_ID = Mendefinisikan ID Project dari Project Firebase Anda
  11. FIREBASE_STORAGE_BUCKET = Mendefinisikan Storage Bucket dari Project Firebase Anda
  12. FIREBASE_MESSAGE_ID = Mendefinisikan ID Message dari Project Firebase Anda
  13. FIREBASE_APP_ID = Mendefinisikan ID App dari Project Firebase Anda
  14. FIREBASE_MEASUREMENT_ID = Mendefinisikan ID Measurement dari Projek Firebase Anda
  15. FIREBASE_KEYS = Mendefinisikan Kunci Admin Privat dari Projek Firebase Anda
  16. START_TIME = Mendefinisikan kapan data mulai diperbolehkan masuk
  17. END_TIME = Mendefinisikan kapan waktu akhir data diperbolehkan masuk

START_TIME HARUS LEBIH KECIL DARIPADA END_TIME

Untuk mengetahui bagaimana mendapatkan kredensial dari Project Firebase, tolong rujuk ke Dokumentasi Firebase

Skema yang Direkomendasikan

Anda bisa mengkustomisasi kueri di dalam firebase / mysql Query.js untuk menyesuaikan dengan skema anda

Tetapi jika Anda ingin kemudahan dalam kegunaan, ikuti skema yang direkomendasikan di bawah

Untuk MYSQL

userId name absentNum class type date status
int varchar(255) varchar char(5) varchar Datetime char(8)

Untuk Firestore

TBA

espauthabsent's People

Contributors

cydnirn avatar dependabot[bot] avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.