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.txtto.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.pyfile - 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_topicdefined inmain.py - Input requests to a topic in
input_topicsdefined inmain.py
username
usernameis an alphanumeric string.
username, alarmTime, facialRecognitionDuration
usernameis a registered username.alarmTimeis a 12-hour format string followingHH:MM (A|P)MfacialRecognitionDurationis 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_durationwhich the system uses for timing out the recognition.
t&h, param
paramcan be either a positive integer specifying number of days before current date or a specific date formatted asmm/dd/yyyy
username, (columns), param
-
usernameis a registered username -
paramas defined here -
columnsis 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), paramusername, (wake_up_duration), paramusername, (completed_face_recognition), param





