Mobile Quiz App with Raspberry Pi Integration

Замовник: AI | Опубліковано: 09.10.2025

I need a complete, production-ready solution that lets employees at 1000 different locations take a simple true/false quiz on their phones and instantly see how they did when the session ends—green LED on the local Raspberry Pi for a perfect score, red if any answer is wrong. Overview We are building a production-ready IoT system to manage a fleet of 1,000 Raspberry Pi Zero 2 W devices used as interactive POS units in restaurants. Each device reacts with LED lights to answers in a short web quiz and communicates with the cloud via LTE (no Wi-Fi). The system must include: Real-time LED control (<1s latency) Secure two-way communication (MQTT + TLS + X.509 certificates) Remote over-the-air updates (OTA) via AWS IoT Jobs Monitoring, diagnostics, and provisioning for large-scale deployment System Components 1. Frontend Web quiz built with Express (Node.js). Hosted on AWS S3 + CloudFront for global CDN delivery. Each device has a unique QR code (e.g., https://quiz.quizapp.app?d=LL-01234) linking to its session. Users answer 6–8 quiz questions; results are submitted via HTTPS to the backend. 2. Backend (AWS) AWS API Gateway handles all REST API requests. AWS Lambda (Node.js or Python) processes quiz results: Saves results to DynamoDB. Publishes MQTT messages to specific devices through AWS IoT Core. AWS DynamoDB stores: Quiz results and user sessions. Device configurations (deviceId, firmware version, last seen time, signal strength, etc.). 3. IoT Messaging Layer AWS IoT Core manages secure device communication: Uses MQTT over TLS (port 8883). Each device has a unique X.509 certificate for authentication. Topics: device/{deviceId}/cmd – commands sent from backend to devices. device/{deviceId}/status – device status reports sent to the cloud. Supports Device Shadow for maintaining the latest device state. Integrates with IoT Jobs for OTA updates and diagnostics. Uses Fleet Provisioning (JITP/JITR) to register new devices automatically. 4. OTA (Over-the-Air Updates) OTA updates are managed via AWS IoT Jobs. Each new firmware version is uploaded as a ZIP file to S3 and digitally signed. AWS IoT Jobs sends update instructions to all or specific devices. Devices download the update, verify the checksum and signature, apply it (A/B slot), restart, and report success/failure back to AWS. 5. Monitoring & Security AWS CloudWatch and IoT Defender monitor: Online/offline devices (heartbeat signals). OTA job results and failure rates. Network anomalies. Alerts via SNS (email or Slack) for devices not reporting within 10 minutes. Security: TLS 1.2 encryption. Individual X.509 certificates per device. IAM policies restricting each device to its own MQTT topics. Signed OTA packages. Read-only root filesystem on devices. Outbound-only network access (ports 443 and 8883). Device Architecture (Raspberry Pi Zero 2 W) Each unit consists of: Hardware: Raspberry Pi Zero 2 W, Quectel EC25-EU LTE modem, UPS HAT with dual 18650 batteries, and an ABS+PC enclosure. Software (two processes): agent.service Connects to AWS IoT Core using MQTT with X.509 certificates. Handles all cloud communications: /cmd, /status, and IoT Jobs. Downloads OTA packages from S3, verifies integrity, installs updates. Sends periodic heartbeats and diagnostic data (battery, signal, version). Communicates locally with the LED app via a UNIX socket (/tmp/led.sock). quizapp.service Controls LED lights via GPIO and MOSFETs. Executes commands received from the agent. Reports execution success/failure back to the agent. LED configuration: Small red and green LEDs (indicate quiz answer match/mismatch). Large top LED (shows overall quiz result). Physical service button (for maintenance/reset). End-to-End Data Flow The user scans a QR code on a device and opens the Express (Node.js) web quiz. The quiz collects answers and sends the final score to the backend via HTTPS. The Lambda function processes the score, stores it in DynamoDB, and publishes an MQTT message (e.g., “set_led green”) to the specific device. The agent on the Raspberry Pi receives the message, passes it to the LED app, and lights the appropriate LEDs. The device sends a confirmation message and periodic heartbeat updates (status) back to AWS IoT Core. CloudWatch and Defender log activity and raise alerts if devices go offline. Developers or operators can create IoT Jobs to roll out firmware updates or run diagnostics remotely. Devices automatically handle OTA download, verification, installation, and rollback in case of failure. Technologies Used Frontend: Express (Node.js), JavaScript, HTML5, S3, CloudFront Backend: AWS Lambda (Node.js / Python), API Gateway, DynamoDB IoT Communication: AWS IoT Core (MQTT/TLS, IoT Jobs, Shadow, Defender) Storage: Amazon S3 (OTA packages, signed manifests) Monitoring: AWS CloudWatch, IoT Defender, SNS Device OS: Raspberry Pi OS Lite (Linux) Device Programming: Python 3 (agent + LED app), systemd services Security: TLS 1.2, X.509 certificates, IAM policies, signed updates Provisioning: AWS Fleet Provisioning (JITP/JITR) or pre-loaded certs during factory flashing Security Summary Each device has a unique X.509 certificate and private key. Certificates are issued by a trusted CA and registered in AWS IoT Core. Device-level IAM policies ensure isolation — one device cannot impersonate another. OTA packages are signed and verified before installation. Communication is encrypted end-to-end (TLS 1.2). Factory provisioning ensures certificates and deviceId are mapped to each physical device. Deliverables Fully functional serverless backend on AWS (API + IoT + DB). Express (Node.js) web quiz with integration to the backend. Python code for Raspberry Pi (agent + LED app). OTA update mechanism using AWS IoT Jobs. Monitoring and alert setup in CloudWatch/Defender. Factory provisioning scripts for 5,000 units. Deployment documentation and test procedures. Outcome Users scan a QR → take the quiz → device LEDs react instantly (<1s). All devices are connected, monitored, and remotely updatable via AWS IoT Jobs. OTA rollouts, diagnostics, and monitoring are automated for all 5,000 units. The system is secure, scalable, and fully production-ready.