https://github.com/nhathout/elect-a-leader
Secure E-Voting System.
https://github.com/nhathout/elect-a-leader
infrared-sensors nfc raspberry-pi wireless
Last synced: 2 months ago
JSON representation
Secure E-Voting System.
- Host: GitHub
- URL: https://github.com/nhathout/elect-a-leader
- Owner: nhathout
- Created: 2024-12-19T07:03:46.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-12-23T06:20:19.000Z (over 1 year ago)
- Last Synced: 2025-02-14T08:37:04.849Z (over 1 year ago)
- Topics: infrared-sensors, nfc, raspberry-pi, wireless
- Language: C
- Homepage:
- Size: 3.4 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Elect-A-Leader
**Date:** November 7, 2024
## Overview
Secure E-Voting is a distributed, fail-safe system for casting and recording votes via a network of devices. Each fob device, equipped with an IR transmitter and receiver, simulates NFC-like communication to authenticate voters and send votes. A dynamically elected Coordinator handles vote aggregation, communication with a central server, and ensures continuous operation through failover mechanisms.
## Key Features
- **Voter Authentication & Vote Casting**
- Each voter’s unique ID is sent alongside the vote using IR-based communication.
- The Coordinator relays this data to a central database and confirms receipt.
- **Coordinator Election & Failover**
- Fobs use a leader election algorithm to select a Coordinator.
- The system detects Coordinator failures, triggering an automatic failover to ensure uninterrupted voting.
- **Secure Vote Transmission**
- Voter IDs and votes flow through IR from the casting fob to the Coordinator.
- The Coordinator securely forwards data to a central server running a Node.js and TingoDB backend.
- **Data Logging & Web Interface**
- Votes are logged in a central database, storing voter IDs and timestamps.
- A web UI displays real-time results, and features a reset option for the database.
- **Device Status Indication**
- **Red LED:** Non-leader device.
- **Blue LED:** Leader device (Coordinator).
- **Green LED:** Timeouts or other status notifications.
## Implementation Details
### Hardware Integration
- **Fobs with IR Transmitters/Receivers**
- Simulate NFC, allowing each device to broadcast and receive messages.
- Integrated buttons for initiating votes.
- LED indicators for state feedback.
- **ESP32 Microcontrollers**
- Manage IR communication (transmit/receive).
- Connect via Wi-Fi for Coordinator-to-server data flow.
- Utilize FreeRTOS tasks and mutexes for concurrency and synchronization.
### Network Communication
- **Wi-Fi Connectivity**
- Devices join a common network.
- Votes and leader election messages are exchanged using UDP.
- **Coordinator Role**
- Receives votes (ID and chosen option).
- Transmits data to the server on port 4000.
- Confirms receipt to the voting fob.
- **Backend (store_votes.js)**
- Hosts a Node.js server with a TingoDB database (`mydb/votes`).
- Exposes a web interface at `http://192.168.1.103:8080`, providing real-time results.
- Allows database resets and debugging through a simple UI.
### Leader Election
- **Bully Algorithm**
- Devices exchange messages (`MSG_ELECTION`, `MSG_ALIVE`, `MSG_VICTORY`, `MSG_KEEP_ALIVE`) to decide on a Coordinator.
- If a Coordinator is unresponsive, other devices trigger a new election.
- The newly elected Coordinator broadcasts a victory message and updates the system state.
### FreeRTOS Tasks
- **button_task**
- Detects button presses and interprets them as votes.
- Commits a vote transmission after a debounce or timeout.
- **ir_rx_task**
- Continuously listens for IR messages.
- Processes commands for joining the system, receiving Coordinator signals, and votes.
- **bully_algorithm_task**
- Manages leader election processes and monitors Coordinator health.
- **recv_task (UDP Receive)**
- Handles incoming UDP messages (e.g., election calls, votes, keep-alive signals).
- **id_task**
- Blinks the onboard LED a set number of times to indicate the device’s ID for diagnostics.
- **continuous_ir_transmit_task**
- If the device is Coordinator, broadcasts `MSG_COORDINATOR_SIGNAL` via IR to maintain leadership status.
### Vote Casting Workflow
1. **Fob Device (Non-Coordinator):**
- User presses a button to select a vote option (e.g., Red/Blue/Green).
- Vote data (Voter ID + selected option) is sent to the Coordinator via UDP.
2. **Coordinator:**
- Logs vote data locally.
- Confirms receipt back to the voter.
- Transmits the vote to the central server via UDP on port 4000.
3. **Server (store_votes.js):**
- Inserts each vote record into TingoDB.
- Updates the web interface for real-time voting results.
## Results and Learnings
- **Achievements:**
- Achieved a robust distributed system where devices dynamically elect a Coordinator and handle failovers seamlessly.
- IR-based “NFC” simulation successfully captured votes and authenticated users.
- The centralized database and web UI provided an accessible snapshot of voting progress.
- **Challenges:**
- Fine-tuning IR signals to handle interference and ensure accurate detection.
- Coordinating UDP messages in real-time to avoid missed or duplicated votes.
- Preserving data integrity while managing concurrent device states demanded careful synchronization.
- **Potential Improvements:**
- Implement hardware interrupts for IR reception to improve responsiveness.
- Enhance error detection and encryption for added security in vote transmission.
- Include more elaborate logging and diagnostics for debugging complex failover events.
## Demonstrations
- [**Functionality Demo Video**](https://drive.google.com/file/d/14ioolii2PttAG8Jn80Jt-KU8r46mR65U/view?usp=sharing)
- [**Design Walkthrough Video**](https://drive.google.com/file/d/1l6wGfmdgtvITa7rTuvHjnD1I_g9CTXzG/view?usp=sharing)
## Appendix
circuit diagram:

---
By combining IR-based “NFC” authentication, leader election, and a central database, Secure E-Voting showcases how ESP32 devices can form a resilient, distributed voting network. The fail-safe coordinator mechanism and real-time web interface underscore the system’s robustness and transparency for real-world voting scenarios.