A modern web-based monitoring and control system for IoT agriculture sensors, built with Node.js, Express, and SQLite database. This system replaces PHP-based solutions with a more maintainable and scalable architecture.
- π‘οΈ Real-time Sensor Monitoring: Temperature, humidity, and soil moisture tracking
- π‘ Remote LED Control: Turn devices on/off from the web interface
- π Data Visualization: Interactive charts showing sensor data history
- π Real-time Updates: Live data updates using WebSocket connections
- π± Responsive Design: Works on desktop, tablet, and mobile devices
- ποΈ Data Storage: SQLite database for reliable data persistence
- π Modern Architecture: Node.js backend with RESTful API
- ESP8266 (NodeMCU or similar)
- DHT11 Temperature & Humidity Sensor
- Soil Moisture Sensor (analog)
- LED for control demonstration
- Jumper wires and breadboard
- Node.js (v14 or higher)
- npm (Node Package Manager)
- Arduino IDE
- ESP8266 board support package
-
Install Node.js dependencies:
npm install
-
Start the server:
npm start
For development with auto-restart:
npm run dev
-
Access the web interface: Open your browser and navigate to
http://localhost:3000
-
Install required libraries:
- ESP8266WiFi
- ESP8266HTTPClient
- Arduino_JSON
- DHT sensor library
-
Update the Arduino code:
- Open
arduino_updated.inoin Arduino IDE - Update the WiFi credentials:
const char* ssid = "YOUR_WIFI_NAME"; const char* password = "YOUR_WIFI_PASSWORD";
- Update the server IP address:
const char* serverIP = "YOUR_SERVER_IP"; // e.g., "192.168.1.100"
- Open
-
Upload the code to your ESP8266
| ESP8266 Pin | Component | Notes |
|---|---|---|
| D5 | DHT11 Data | Temperature & Humidity Sensor |
| A0 | Soil Moisture Sensor | Analog input |
| D0 | LED | Control demonstration |
| 3.3V | DHT11 VCC | Power supply |
| 3.3V | Soil Moisture VCC | Power supply |
| GND | Common Ground | All components |
POST /getdata- Get pending commands for the devicePOST /updateDHT11data_and_recordtable- Send sensor data to server
GET /api/devices- Get all registered devicesGET /api/sensor-data/:deviceId- Get latest sensor dataGET /api/sensor-data/:deviceId/history- Get sensor data historyPOST /api/command- Send command to device
- Real-time Sensor Display: Shows current temperature, humidity, and soil moisture
- Status Indicators: Visual indicators for sensor health and device connection
- LED Control: Remote control for connected devices
- Interactive Charts: Line charts showing sensor data over time
- Historical Data: View up to 50 recent data points
- Real-time Updates: Charts update automatically with new data
- Connection Status: Monitor device connectivity
- Last Update Time: Track when data was last received
- Sensor Status: Monitor sensor health and functionality
The server runs on port 3000 by default. To change this:
-
Set the
PORTenvironment variable:export PORT=8080 npm start -
Or modify the
PORTvariable inserver.js:const PORT = process.env.PORT || 8080;
The system uses SQLite database (agriculture.db) which is created automatically. The database includes:
- devices: Device information and status
- sensor_data: Historical sensor readings
- device_commands: Pending commands for devices
-
ESP8266 not connecting to WiFi
- Check WiFi credentials in Arduino code
- Ensure WiFi network is accessible
- Check signal strength
-
Server not receiving data
- Verify server IP address in Arduino code
- Check if server is running on correct port
- Ensure firewall allows connections
-
Web interface not loading
- Check if Node.js server is running
- Verify port 3000 is accessible
- Check browser console for errors
-
Database errors
- Ensure write permissions in project directory
- Check if SQLite is properly installed
- Verify database file is not corrupted
Enable debug logging by setting the environment variable:
DEBUG=* npm startβββ server.js # Main server file
βββ package.json # Dependencies and scripts
βββ agriculture.db # SQLite database (auto-created)
βββ public/ # Web interface files
β βββ index.html # Main web page
β βββ script.js # Frontend JavaScript
βββ arduino_updated.ino # Updated Arduino code
βββ README.md # This file
- New Sensor Types: Add to database schema and API endpoints
- Additional Controls: Extend command system in Arduino code
- Custom Visualizations: Modify Chart.js configuration
- Mobile App: Use existing API endpoints for mobile development
- Change default device IDs
- Implement authentication for production use
- Use HTTPS in production environments
- Secure database access
- Validate all input data
- Database indexing for large datasets
- Connection pooling for multiple devices
- Caching for frequently accessed data
- Compression for API responses
MIT License - feel free to use and modify for your projects.
For issues and questions:
- Check the troubleshooting section
- Review the code comments
- Check the browser console for errors
- Verify all connections and configurations
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
Happy Farming! π±