Visit us at: Farmpulse Website
FarmPulse is an advanced IoT-based cattle health monitoring system that enables real-time tracking of vital health metrics, early detection of health issues, and specialized monitoring for pregnant cattle. The system uses wearable IoT sensors and ESP32 devices to collect data, with a central dashboard providing real-time visualization and alerts.
- System Overview
- Key Features
- Technology Stack
- System Architecture
- Installation
- Usage Guide
- WebSocket Connection
- ESP32 Integration
- Anomaly Detection
- Troubleshooting
- Development
- License
FarmPulse revolutionizes cattle health monitoring by providing:
- Real-time health tracking: Monitor temperature, heart rate, activity levels, and other vital parameters
- Pregnancy monitoring: Special features for monitoring pregnant cattle including fetal heart rate
- Anomaly detection: AI-powered early warning system for health issues
- WebSocket communication: Real-time data flow from sensors to dashboard
- Simulation capabilities: Test the system without physical sensors
The system consists of:
- ESP32 sensors (or simulator): Collect and transmit animal health data
- Backend server: Process incoming sensor data and manage WebSocket connections
- Frontend dashboard: Real-time visualization of health metrics and alerts
- Database systems: Store and retrieve historical data
- Live Sensor Data Display: Real-time visualization of temperature, heart rate, activity level, and more
- Anomaly Detection: AI-powered analysis to flag potential health issues
- Pregnancy Monitoring: Special tracking for pregnant cattle, including fetal heart rate
- Simulation Tools: Built-in data simulation for testing and demonstration
- WebSocket Communication: Persistent connections for instant data updates
- Multi-animal Support: Monitor multiple animals simultaneously
- Responsive Design: Works on desktop and mobile devices
- React: UI framework
- Vite: Build tool and development server
- TypeScript: Type-safe JavaScript
- ShadCN/UI: UI component library
- Lucide React: Icons
- Tailwind CSS: Utility-first CSS framework
- Node.js: Runtime environment
- Express: Web server framework
- WebSocket: Real-time communication
- SQLite/MongoDB: Data storage (configurable)
- InfluxDB: Time-series data storage
- ESP32: Microcontroller for sensor data collection
- DHT11: Temperature and humidity sensor
- MPU6050: Accelerometer for activity monitoring
- Simulation tools: Software for testing without physical hardware
FarmPulse employs a modern, real-time architecture:
┌─────────────┐ ┌──────────────┐ ┌────────────────┐
│ ESP32 IoT │ │ │ │ │
│ Sensors │◄────►│ WebSocket │◄────►│ Web Frontend │
│ (or Sim) │ │ Server │ │ (React/Vite) │
└─────────────┘ │ │ │ │
└──────┬───────┘ └────────────────┘
│
┌──────▼───────┐ ┌────────────────┐
│ │ │ │
│ Express.js │◄────►│ MongoDB/ │
│ Backend │ │ SQLite │
│ │ │ │
└──────┬───────┘ └────────────────┘
│
┌──────▼───────┐ ┌────────────────┐
│ │ │ │
│ Anomaly │◄────►│ InfluxDB │
│ Detection │ │ (Time Series) │
- Node.js (v16 or higher)
- npm (v7 or higher)
- Git
- MongoDB (optional, SQLite is used by default)
- InfluxDB (optional for time-series data)
-
Clone the repository:
git clone https://github.com/yourusername/farmpulse.git cd farmpulse -
Create a
.envfile in the root directory:PORT=3001 MONGODB_URI=mongodb://localhost:27017/farmpulse INFLUXDB_URL=http://localhost:8086 INFLUXDB_TOKEN=my-super-secret-auth-token INFLUXDB_ORG=farmpulse INFLUXDB_BUCKET=iot_sensors USE_SQLITE=trueNote: Setting
USE_SQLITE=trueallows the application to run without MongoDB.
-
Install dependencies:
npm install
-
Start the backend server:
npm run backend
Look for output confirming WebSocket initialization:
WebSocket server initialized on port 3001 WebSocket path: ws://localhost:3001 -
Start the frontend development server (in a new terminal):
npm run dev
-
Open your browser and navigate to the URL shown in the terminal (usually http://localhost:8080)
- Navigate to http://localhost:8080 in your web browser
- Select an animal from the dropdown menu (default samples: A12345, A12346, A12347)
- View real-time sensor data in the dashboard
The dashboard displays:
- Temperature: Current body temperature in Celsius
- Heart Rate: Beats per minute (BPM)
- Activity Level: Scale from 0-10 showing movement intensity
- Humidity: Environmental humidity percentage
- Fetal Heart Rate: For pregnant cattle
- Audio Level: Environmental sound detection
FarmPulse includes a powerful simulator to test without physical hardware:
-
Start the simulator:
npm run simulate:enhanced
-
Configure simulation settings:
- WebSocket URL: ws://localhost:3001
- Device ID: DEV-SIMULATOR (or any custom ID)
- API Key: (use default)
- Animal ID: CATTLE001 (or any ID in your system)
- Data interval: 5000 (5 seconds)
-
Select sensors to simulate:
- DHT11 (temperature/humidity)
- MPU6050 (movement/activity)
- HEALTH (vital signs)
- PREGNANCY (fetal monitoring) - for pregnant cattle
-
Choose simulation scenario:
- Normal: Baseline healthy readings
- Fever: Elevated temperature
- Distress: Abnormal vital signs
- Low Activity: Reduced movement
- Custom: Define your own parameters
FarmPulse uses WebSockets for real-time data communication. The system is configured to use:
- Backend WebSocket Server: ws://localhost:3001
- Client Connection: Direct connection from frontend to backend
- Connection Types:
- Dashboard clients:
?type=dashboard&animalId=ANIMAL_ID - Device/simulator clients:
?type=device&deviceId=DEVICE_ID&apiKey=API_KEY
- Dashboard clients:
Use the built-in WebSocket testing tool:
npm run test:wsThis tool helps diagnose connection issues between components.
For physical ESP32 implementation:
-
Required Components:
- ESP32 development board
- DHT11 temperature sensor
- MPU6050 accelerometer
- Optional heart rate sensor
- Power supply (battery for wearable use)
-
ESP32 Firmware:
- Use the Arduino framework
- Install required libraries (WiFi, WebSockets, DHT, etc.)
- Configure to connect to your WiFi network
- Set WebSocket URL to point to your server
- Flash the firmware to the ESP32
Each physical device needs to be registered:
- Create a device in the system with a unique device ID
- Associate the device with a specific animal
- Generate an API key for authentication
- Configure the ESP32 with these credentials
FarmPulse includes AI-powered anomaly detection:
- Temperature Analysis: Detects fever and hypothermia
- Heart Rate Monitoring: Alerts for tachycardia or bradycardia
- Activity Analysis: Identifies abnormal activity patterns
- Pregnancy Monitoring: Special algorithms for pregnant cattle
When an anomaly is detected, the system:
- Displays an alert on the dashboard
- Stores the anomaly in the database for review
- Provides contextual information about the potential issue
- Problem: Dashboard shows "Disconnected"
- Solution:
- Ensure backend server is running
- Check that WebSocket URL is configured correctly (
ws://localhost:3001) - Use
npm run test:wsto diagnose connection issues
- Problem: Connected but no data shows
- Solution:
- Verify simulator is running and connected
- Ensure simulator and dashboard are using the same animal ID
- Check browser console for errors
- Problem: "Cannot connect to database" errors
- Solution:
- For MongoDB issues: Ensure MongoDB is running or set
USE_SQLITE=truein .env - For InfluxDB: Set up InfluxDB or the system will fall back to limited functionality
- For MongoDB issues: Ensure MongoDB is running or set
farmpulse/
├── src/
│ ├── backend/ # Backend server code
│ │ ├── api/ # REST API routes
│ │ ├── db/ # Database configurations
│ │ ├── middleware/ # Auth and middleware
│ │ ├── ml/ # Anomaly detection and ML
│ │ ├── tools/ # Simulation and utilities
│ │ ├── utils/ # Helper functions
│ │ └── websocket/ # WebSocket server
│ ├── components/ # React components
│ │ ├── Dashboard/ # Dashboard components
│ │ └── ui/ # UI components
│ ├── hooks/ # Custom React hooks
│ ├── lib/ # Utility functions
│ └── pages/ # Page components
├── public/ # Static assets
│ └── ...
├── .env # Environment variables
├── package.json # Dependencies and scripts
├── vite.config.ts # Vite configuration
└── README.md # Project documentation
npm run dev: Start frontend development servernpm run backend: Start backend servernpm run start: Start both frontend and backendnpm run build: Build for productionnpm run simulate: Run basic simulatornpm run simulate:enhanced: Run advanced simulator with scenariosnpm run test:ws: Test WebSocket connectivity
Copyright © 2025 FarmPulse Technologies
This project is licensed under the MIT License - see the LICENSE file for details.