{"id":23386929,"url":"https://github.com/nhathout/fit-cat","last_synced_at":"2026-05-07T01:05:17.912Z","repository":{"id":268914994,"uuid":"905605337","full_name":"nhathout/Fit-Cat","owner":"nhathout","description":"Connected network of Smart Cat Collars with live video and biometric feedback.","archived":false,"fork":false,"pushed_at":"2024-12-22T17:13:46.000Z","size":2483,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-27T07:46:55.151Z","etag":null,"topics":["cats","iot","nodejs","raspberry-pi","wifi"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nhathout.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-19T06:59:19.000Z","updated_at":"2024-12-22T17:13:50.000Z","dependencies_parsed_at":null,"dependency_job_id":"0d520dbe-808c-4360-b9a9-1a7a29abe308","html_url":"https://github.com/nhathout/Fit-Cat","commit_stats":null,"previous_names":["nhathout/fit-cat"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/nhathout/Fit-Cat","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nhathout%2FFit-Cat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nhathout%2FFit-Cat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nhathout%2FFit-Cat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nhathout%2FFit-Cat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nhathout","download_url":"https://codeload.github.com/nhathout/Fit-Cat/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nhathout%2FFit-Cat/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273093574,"owners_count":25044437,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-01T02:00:09.058Z","response_time":120,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cats","iot","nodejs","raspberry-pi","wifi"],"created_at":"2024-12-22T01:13:49.226Z","updated_at":"2026-05-07T01:05:17.874Z","avatar_url":"https://github.com/nhathout.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# FitCat: Network of Smart Cat Collars with Activity Monitoring\n\n**Date:** October 27, 2024\n\n## Overview\nThis smart cat collar project is designed to capture, log, and transmit real-time activity data of cats. Using an accelerometer, a networked server, and an alphanumeric display, the collar determines whether a cat is sleeping, wandering, or performing a unique \"moonwalk\" activity. The collar displays its current activity on an alphanumeric display and communicates with a central server to participate in a leader determination system. Additionally, a button interface allows switching display modes, and a buzzer indicates leadership changes or continuous leadership status.\n\n## Key Features\n\n- **Activity Detection:**  \n  Utilizes an ADXL343 accelerometer to detect and classify activities.  \n  Supports states such as \"Sleepy Time,\" \"Wander Time,\" and \"Moonwalk Time.\"\n\n- **State Reporting:**  \n  Shows the current activity state on a 14-segment alphanumeric display.  \n  Sends real-time activity data and timestamps to a central server over Wi-Fi.\n\n- **Leader Determination:**  \n  Integrates with a central server to determine which cat is the \"leader\" based on accumulated active time over a rolling 10-minute window.  \n  Responds to leader updates with a buzzer signal: continuous buzzing if currently the leader, and a single buzz on leader change events.\n\n- **Button Interface:**  \n  Cycles through multiple display modes at the press of a button:  \n  - **Mode 0:** Default message (\"Boots and Cats\").  \n  - **Mode 1:** Current activity state.  \n  - **Mode 2:** Elapsed time in the current state.\n\n- **Buzzing Mechanism:**  \n  Continuous buzzing if the device’s cat is the leader.  \n  A single buzz on receiving a leader change notification.\n\n## Implementation Details\n\n### Sensor Integration\n- The ADXL343 accelerometer is used to read x, y, and z accelerations.\n- Derived pitch and roll values help classify the cat’s current state.\n- Thresholds and classification logic translate raw sensor readings into human-readable states.\n\n### Display Interface\n- A 14-segment alphanumeric display shows various messages:\n  - Default greeting.\n  - Current activity state.\n  - Elapsed time in that state.\n- I²C communication manages updates and scrolling text if needed.\n\n### Network Communication\n- Uses Wi-Fi to connect to a central server.\n- Relies on both WebSockets and UDP for data exchange.\n  - Activity data and timestamps are sent to the server.\n  - Leader updates are received, prompting local buzzer events.\n\n### Concurrency and Synchronization\n- Multiple FreeRTOS tasks handle sensor data, display updates, button input, and network communication concurrently.\n- Mutexes protect shared data to ensure thread-safe operations.\n- Tasks are organized for predictable and stable behavior across all system functions.\n\n## Solution Design\n\n### Initialization (app_main)\n- Initialize shared mutexes.\n- Set up I2C and UART communication.\n- Configure GPIOs for the button and buzzer.\n- Connect to the Wi-Fi network.\n- Initialize the accelerometer and prepare for sensor readings.\n- Create and start FreeRTOS tasks for sensor reading, button handling, display updates, and network listening.\n\n### Tasks and Functions\n\n**Sensor Task (test_adxl343):**  \n- Periodically reads accelerometer values (x, y, z).  \n- Calculates roll, pitch, and overall acceleration to classify the cat’s activity state with `getCatState()`.  \n- Updates shared state variables and resets timers as needed.\n\n**Button Task (task_button_presses):**  \n- Polls the button input.  \n- On button press, cycles through display modes (0 → 1 → 2 → back to 0).  \n- Uses a mutex to safely modify shared variables that determine the display content.\n\n**Display Task (test_alpha_display):**  \n- Updates the alphanumeric display based on the current display mode.  \n- Mode 0: Shows \"Boots and Cats\".  \n- Mode 1: Shows the cat’s current activity state.  \n- Mode 2: Shows the elapsed time in the current activity state.  \n- Handles scrolling for longer messages and communicates via I²C.\n\n**Network Listener Task (network_listener_task):**  \n- Listens for leader updates from the server using UDP.  \n- On receiving a new leader ID, updates the local leader status and triggers the buzzer accordingly.\n\n**WebSocket Event Handler (websocket_event_handler):**  \n- On receiving data from the central server, parses the leader ID.  \n- Updates buzzing state if this collar’s cat is the leader.  \n- Implements a single buzz for leader change or continuous buzzing for ongoing leadership.\n\n**Buzz Function (buzz):**  \n- If `isBuzzing` is true and this cat is the leader, buzz continuously (on/off at intervals).  \n- If a leader change occurred, buzz once.  \n- Otherwise, ensure the buzzer remains off.\n\n## Results and Learnings\n\n**Achievements:**\n- Successfully integrated sensor readings, network communications, and display output into one cohesive system.\n- Achieved accurate classification of cat activities based on acceleration data.\n- Established a leader determination mechanism that updates in real-time and is clearly signaled by the buzzer.\n\n**Challenges:**\n- Fine-tuning thresholds and logic for accurate activity classification proved time-consuming.  \n- Managing concurrent tasks and ensuring thread-safe data access required careful synchronization.\n\n**Potential Improvements:**\n- Introduce hardware interrupts instead of polling for the button, improving efficiency.\n- Refine circuit design to reduce complexity and improve reliability.\n- Enhance power management for extended battery life in real-world scenarios.\n- Include more robust error handling, especially around network communications.\n\n## Demonstrations\n\n- [**Device Functionality Demo Video**](https://drive.google.com/file/d/1tmxS8HGcO_dwnGMNcW7fP4neTti4bQX-/view?usp=sharing)\n- [**Design Walkthrough Video**](https://drive.google.com/file/d/1KdEOFxNXSFyghgzOxwIRIRRMS36AR_G7/view?usp=sharing)\n\n## Appendix\ncircuit diagram:\n![circuit-diagram](https://github.com/nhathout/Fit-Cat/blob/main/CatCollarDiagram.jpg)\n\n---\n\nThis smart cat collar prototype demonstrates a robust system capable of monitoring feline activity, displaying meaningful states on an alphanumeric display, and participating in a networked leader determination setup. Its extensible architecture, modular tasks, and well-defined communication patterns make it a strong foundation for future enhancements, fine-tuning, and real-world adoption.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnhathout%2Ffit-cat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnhathout%2Ffit-cat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnhathout%2Ffit-cat/lists"}