- Docker Engine
- Python
- Flask micro web framework
Move from the command line in the 'universome-authentication' folder and run the following command start the project.
docker compose up
The application can be used from the http://127.0.0.1:8000 The CoAP Server can be used from the http://127.0.0.1:5683
The application factory is coded into the file _init_.py The library python-dotenv can be used to load important initial configuration parameters.
Al primo avvio, l'intero sistema vien configurato affinchè il Database disponga del profilo di amministratore di base e consenta l'inserimento di nuovi utenti, dopo aver inizializzato il database. Viene fatta una verifica facendo degli inserimenti di test per verificare se le operazioni di Lettura, Creazione, Aggiornamento ed Eliminazione vengono effettuate correttamente.
La Home page dell'applicativo conterrà un messaggio di Benvenuto, con una sezione "Chi siamo" e un pulsante per effettuare l'accesso a chi è registrato.
La dashboard dell'amministratore, consente la registrazione di nuovi utenti al sistema, o nuovi terminali.
APPROCCIO SHAZAM: Il client invia una richiesta al server che si desidera avvicinare un Tag RFID e rimane in attesa della risposta dal server per la convalida.
Un profili "Utente normale" è un profilo assegnato ad un soggetto, membro del progetto, che darà la possibilità di aggiornare, modificare e cancellare le proprie informazioni dal sistema.
Un profilo con ruolo "Terminale" è un profilo assegnato ad un dispositivo che potrà leggere e verificare gli utenti registrati, per controllare se hanno accesso o no alla sede.
Per ogni dispositivo distribuito all'interno degli spazi dell'ateneo, questo verrà configurato con un profilo autorizzato solo alla lettura. I membri
Use BCrypt module from Flask Extension
- REST APIs tests
- CoAP tests
- Python script tests.
Testing the CoAP Server endpoint CoRE Resource Discovery: When a client discovers the list of resources hosted by a server, their attributes, and other link relations by accessing "/.well-known/core".
Example request: aiocoap-client coap://localhost:5683/.well-known/core
Sending a GET request to a resource:
Example request: aiocoap-client -m GET coap://localhost:5683/[RESOURCE-PATH]
Sending a GET request to a resource with payload:
Example request: aiocoap-client -m GET --payload "CONTENT" coap://localhost:5683/[RESOURCE-PATH]
Sending a PUT request to an Observable resource with a payload:
Example request aiocoap-client -m PUT --payload="2024-07-01 12:59:33,Marco,ZZYY,False" coap://localhost:5683/unauthorized
Important: The USBIPD Utility use network drivers to attach devices to WSL. Check Firewall configuration or disable it. Run the Command Line with administrator privileges
> usbipd list # Find the Arduino device
# If STATE is "Not shared" run
> usbipd bind --busid [ARDUINO BUSID] # Put device in STATE: Shared
# If STATE is "Shared" run
> usbipd attach --wsl --busid [ARDUINO BUSID]
From the WSL terminal, check if /dev/ttyACM0
exists, running
$ ls /dev/tty*
- [uWSGI] (https://en.wikipedia.org/wiki/UWSGI)
- Important: Application Context
- Dinamyc HTML Page: JavaScript, fetch, and JSON - Flask
- [DB Browser for SQLite] (https://sqlitebrowser.org/)
- [Database Connection and Cursor closing] (https://www.quora.com/What-is-the-difference-between-cursor-and-connection-when-performing-operations-on-databases)
Flask: Using SQLite 3 with Flask - Flask Doc
Other useful resources for Database
- libsass - https://sass.github.io/libsass-python/index.html
- libsass with Flask - https://sass.github.io/libsass-python/frameworks/flask.html
ImportError: cannot import name 'url_decode' from 'werkzeug.urls' (/opt/venv/lib/python3.10/site-packages/werkzeug/urls.py)
sqlite3.OperationalError: attempt to write a readonly database
Solution:RUN chown ${UID}:${UID} instance -R
in Dockerfile
-
Python:
- File
__init__.py
: https://betterstack.com/community/questions/what-is-init-py-for/ - The Try, Except and Finally block: https://medium.com/analytics-vidhya/do-you-really-understand-try-finally-in-python-110cee4c1a8
- File
-
Flask:
-
Flask-Login: https://flask-login.readthedocs.io/en/latest/
-
Flask-Bcrypt: https://flask-bcrypt.readthedocs.io/en/1.0.1/index.html
-
Flask-WTF - Documentation https://flask-wtf.readthedocs.io/en/1.2.x/quickstart/
-
WTForms - Crash course: https://wtforms.readthedocs.io/en/3.0.x/crash_course/
-
PySerial - Documentation: https://pyserial.readthedocs.io/en/latest/
-
Server-Sent Event: https://dev.to/cloudx/backend-to-frontend-communication-with-server-sent-events-56kf
-
Flask-SSE: https://flask-sse.readthedocs.io/en/latest/quickstart.html
-
Flask-CORS: https://flask-cors.readthedocs.io/en/3.0.10/
WebSocket in Flask
- For Real Time Client-Server communication, it is possible to use flask_socketio module.
- Virtual environment and container: https://stackoverflow.com/questions/48561981/activate-python-virtualenv-in-dockerfile
- Baud rate: Common Baud rate
- TTY: Keep TTY open in Docker
- dmesg: Operation not permitted: Privileged Docker container
- Permission problems in TTY from Docker to RaspberryOS
- Docker installation (for RPi 3B+ with aarch64, 64bit RaspberryOS): https://docs.docker.com/engine/install/debian/
- Docker Compose Flask Sample: https://github.com/docker/awesome-compose/tree/master/flask
- Static IP in container: https://stackoverflow.com/questions/39493490/provide-static-ip-to-docker-containers-via-docker-compose
- Expose UDP ports: How do I publish a UDP Port on Docker? - stackoverflow.com
- Logic Level Shifter / Converter
- aiocoap - https://github.com/chrysn/aiocoap
- aiocoap Sample
Client, Toolkit IoT - https://github.com/IoT-Technology/IoT-Toolkit CoAP Wireshark Packet Analyzer - https://www.youtube.com/watch?v=RfCbpUYcjdc
- Add authentication to your app with Flask-Login
- How to authenticate users in Flask
- How Flask-Login works
- Dr. Gianluca Carbone - Engineering and Computer Science student