Skip to content

Latest commit

Β 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Here’s the fully translated and polished English version of your documentation β€” formatted cleanly for GitHub (Markdown-ready). All technical terms are kept accurate, and phrasing is natural for professional English README files.


πŸ’Š MediMind Pro – Smart Medicine Box 2.0

A real-time medication management system built with IoT, AI, and a web dashboard.


🎯 Features

  • Pill detection using load cell and IR sensors
  • Real-time MQTT communication between ESP32 and backend
  • Web dashboard built with React and TailwindCSS
  • Local SQLite database for lightweight storage
  • JWT authentication for secure access
  • Real-time alerts via MQTT
  • Live charts for medicine event visualization

πŸ—οΈ Architecture

ESP32 (Firmware)
    ↓ MQTT
Backend: Node.js (Express + MQTT + SQLite)
    ↓ REST API
Frontend: React (Dashboard)

πŸ“‹ Requirements

Hardware

  • ESP32 DevKit
  • Load Cell (HX711 + Sensor) or simulated input
  • IR Sensor (optional)
  • WiFi connection

Software

  • Node.js 16+
  • npm or yarn
  • PlatformIO (for ESP32 firmware)
  • Mosquitto MQTT Broker (local or remote)
  • Python 3.8+ (for PlatformIO support)

πŸš€ Installation

1. Clone and install dependencies

# Backend
cd backend
npm install
cp .env.example .env
# Edit .env with your settings

# Frontend
cd ../web
npm install

2. Configure MQTT Broker (Mosquitto)

Windows

# Download and install: https://mosquitto.org/download/
# or via Chocolatey:
choco install mosquitto

# Start broker (usually runs as a service)
# or manually:
mosquitto -c mosquitto.conf

Linux/Mac

# Install
sudo apt-get install mosquitto mosquitto-clients  # Ubuntu/Debian
brew install mosquitto  # Mac

# Start broker
mosquitto -c /etc/mosquitto/mosquitto.conf

Basic Configuration (mosquitto.conf)

listener 1883
allow_anonymous true

3. Configure Backend

Edit backend/.env:

PORT=3000
MQTT_BROKER=mqtt://localhost:1883
JWT_SECRET=your_jwt_secret_here

Start the backend:

cd backend
npm start

4. Configure Frontend

Create web/.env:

REACT_APP_API_URL=http://localhost:3000/api
REACT_APP_MQTT_BROKER=ws://localhost:9001

Note: For MQTT WebSocket communication, enable WebSocket support in Mosquitto:

listener 9001
protocol websockets

Start the frontend:

cd web
npm start

5. Configure ESP32 Firmware

  1. Install PlatformIO (VS Code extension or CLI).

  2. Edit firmware/esp32/src/main.cpp:

    • Set YOUR_WIFI_SSID and YOUR_WIFI_PASSWORD
    • Update mqtt_server to your MQTT broker IP
    • Adjust device_id if needed
  3. Build and upload:

cd firmware/esp32
pio run -t upload
pio device monitor

πŸ“ Project Structure

medimind-pro/
β”œβ”€β”€ firmware/
β”‚   └── esp32/
β”‚       β”œβ”€β”€ platformio.ini
β”‚       └── src/
β”‚           β”œβ”€β”€ main.cpp
β”‚           β”œβ”€β”€ sensors.cpp
β”‚           β”œβ”€β”€ sensors.h
β”‚           β”œβ”€β”€ wifi_mqtt.cpp
β”‚           └── wifi_mqtt.h
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ index.js
β”‚   β”œβ”€β”€ db.js
β”‚   β”œβ”€β”€ mqtt.js
β”‚   β”œβ”€β”€ api.js
β”‚   β”œβ”€β”€ package.json
β”‚   └── .env.example
β”œβ”€β”€ web/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ App.jsx
β”‚   β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”‚   β”œβ”€β”€ Login.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ Dashboard.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ EventList.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ StatsCard.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ AlertButton.jsx
β”‚   β”‚   β”‚   └── RealTimeChart.jsx
β”‚   β”‚   └── services/
β”‚   β”‚       β”œβ”€β”€ api.js
β”‚   β”‚       β”œβ”€β”€ AuthService.js
β”‚   β”‚       └── mqttService.js
β”‚   β”œβ”€β”€ package.json
β”‚   └── tailwind.config.js
└── README.md

πŸ”§ Usage

1. Start Services

# Terminal 1: MQTT Broker
mosquitto -c mosquitto.conf

# Terminal 2: Backend
cd backend
npm start

# Terminal 3: Frontend
cd web
npm start

2. Register a User

  1. Open http://localhost:3000

  2. Register with:

    • Username
    • Email
    • Password
    • Device ID (must match ESP32 device_id)

3. Connect ESP32

  1. Ensure ESP32 is connected to WiFi
  2. Verify it connects to MQTT broker
  3. Pill events will be published automatically

4. View Real-Time Events

  • Dashboard displays real-time pill events
  • Charts auto-update
  • Alerts can be sent manually from the β€œSend Alert” button

πŸ”Œ API Endpoints

Authentication

  • POST /api/register β€” Register a new user
  • POST /api/login β€” Log in

Events

  • GET /api/events β€” List all events (requires auth)
  • GET /api/stats β€” Retrieve event statistics (requires auth)

Alerts

  • POST /api/alert β€” Send alert (requires auth)

πŸ“‘ MQTT Topics

Topic Description
medibox/<device_id>/event Pill events (published by ESP32)
medibox/<device_id>/alert Alerts (subscribed by ESP32)

πŸ” Security

  • JWT authentication for all protected routes
  • Passwords hashed with bcrypt
  • CORS configured for frontend
  • Input validation on all backend routes

πŸ› Troubleshooting

ESP32 fails to connect to WiFi

  • Check WiFi credentials in main.cpp
  • Ensure the WiFi network is 2.4GHz (ESP32 doesn’t support 5GHz)

MQTT not connecting

  • Verify Mosquitto is running
  • Check broker IP in main.cpp
  • Confirm port 1883 is open

Backend not receiving events

  • Ensure MQTT broker is active
  • Check ESP32 connectivity
  • View backend logs for errors

Frontend not connecting to MQTT

  • Confirm WebSocket is enabled in Mosquitto
  • Verify REACT_APP_MQTT_BROKER in .env
  • Ensure port 9001 is open

🚧 Upcoming Enhancements

  • TensorFlow Lite Micro integration for pill recognition
  • Push notifications
  • Medication history view
  • Reminder scheduling
  • Multi-device support
  • Mobile-friendly dashboard
  • Data export (CSV/PDF)
  • Integration with health APIs

πŸ“ License

MIT License


πŸ‘₯ Contributions

Contributions are welcome! Please open an issue or pull request in the repository.


About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages