A smart alarm clock supporting configurable timed facial recognition, ambient climate sensing and data querying. Skip to Run to see how to run the application.
The architecture of Sparky uses multithreading for concurrent execution of MQTT requests, alarm time checking and ambient climate data upload.
Sparky captures multiple facial images and trains a local OpenCV model with those images. The resultant encodings file is stored in the database.
Deleting a user is a simple database call. See register_user and delete_user for its request schema.
Setting an alarm entails:
- Verifying the user.
- Retrieving their facial encodings from the database.
- Persisting the returned file locally.
- Updating local state to configure the alarm time.
See set alarm for its request schema.
- Facial Recognition: OpenCV
- Database: Azure MySQL
- Message Queue: EMQ MQTT
- Raspberry Pi (guaranteed to work on a 4)
- Audio output compatible with a Pi.
- Camera compatible with a Pi.
- DHT 11 temperature sensor
- Access to MQTT X Web
By design, connecting to a MySQL database or MQTT broker requires a configured .env
file.
To that end, please follow the steps below:
- Populate the fields without values in
template.txt
. - Rename from
template.txt
to.env
.
NB: EMQ provides a free broker. See here for more details.
The SQL code for generating the data model above is available in tables.sql.
- Install all external dependencies on the import listing.
- If you do not have DHT11 connected, then comment out
t_and_h_upload_worker.start()
in the main function. - Execute the
main.py
file - Verify database connection was successful through stdout output:
Connection established Successfully!
- Go to MQTT X Web and set up a connection to your broker or the free broker.
- Subscribe to
output_topic
defined inmain.py
- Input requests to a topic in
input_topics
defined inmain.py
username
username
is an alphanumeric string.
username, alarmTime, facialRecognitionDuration
username
is a registered username.alarmTime
is a 12-hour format string followingHH:MM (A|P)M
facialRecognitionDuration
is the number of seconds the system will maintain continuous facial recognition. The system restarts the timer whenever the recognition fails. Note this value must be lesser thanmax_facial_recognition_duration
which the system uses for timing out the recognition.
t&h, param
param
can be either a positive integer specifying number of days before current date or a specific date formatted asmm/dd/yyyy
username, (columns), param
-
username
is a registered username -
param
as defined here -
columns
is a subset of[wake_up_duration, completed_face_recognition]
delimited by a semicolon. If empty, the request becomesusername, param
-
Example queries:
username, (wake_up_duration; completed_face_recognition), param
username, (wake_up_duration), param
username, (completed_face_recognition), param