A professional Flask-based backend system for monitoring renewable energy installations with ThingsBoard integration.
- Real-time Data Ingestion: Receive sensor data from ESP32/IoT devices
- ThingsBoard Integration: Automatic data forwarding and querying
- Professional API: RESTful endpoints with authentication
- Data Processing: Calculate power output and efficiency metrics
- Historical Data: Query last 20 telemetry records
- Error Handling: Comprehensive validation and error responses
- Logging: Detailed request and error logging
- Security: API key authentication for all endpoints
- Python 3.8+
- ThingsBoard instance (local or cloud)
- ESP32 or compatible IoT device
git clone <repository-url>
cd jyotiyantra-backend
chmod +x setup.sh
./setup.shgit clone <repository-url>
cd jyotiyantra-backend
setup.bat- Copy
.env.exampleto.env - Edit
.envwith your ThingsBoard configuration:
THINGSBOARD_HOST=your-thingsboard-host
THINGSBOARD_PORT=8080
THINGSBOARD_USERNAME=tenant@thingsboard.org
THINGSBOARD_PASSWORD=your-password
DEVICE_ID=your-device-id
DEVICE_TOKEN=your-device-token
API_KEY=your-secure-api-key
PANEL_AREA=1.5# Activate virtual environment
source venv/bin/activate # Linux/MacOS
# or
venv\Scripts\activate.bat # Windows
# Start the server
python app.pyServer will start on http://localhost:5000
GET /healthPOST /ingest
X-API-Key: your-api-key
Content-Type: application/json
{
"voltage": 12.3,
"current": 1.4,
"irradiance": 850,
"temperature": 30,
"battery_voltage": 12.6
}GET /api/data
X-API-Key: your-api-keySee API_DOCS.md for complete documentation.
- Voltage sensor โ A0
- Current sensor โ A1
- Temperature sensor โ A2
- Irradiance sensor โ A3
#include <WiFi.h>
#include <HTTPClient.h>
const char* ssid = "your-wifi";
const char* password = "your-password";
const char* serverURL = "http://your-server:5000/ingest";
const char* apiKey = "your-api-key";
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
}
void loop() {
// Read sensors
float voltage = readVoltage();
float current = readCurrent();
float irradiance = readIrradiance();
float temperature = readTemperature();
float batteryVoltage = readBatteryVoltage();
// Send to backend
sendSensorData(voltage, current, irradiance, temperature, batteryVoltage);
delay(30000); // Send every 30 seconds
}The system automatically calculates:
- Power Output:
P = V ร I - Efficiency:
ฮท = (P / (Irradiance ร Panel Area)) ร 100
- Create device in ThingsBoard
- Copy device ID and access token
- Configure credentials in
.env - Data flows automatically to ThingsBoard dashboards
ESP32 โ Flask Backend โ ThingsBoard โ Dashboard
โ
Historical API โ Web Frontend
Optional data cleaner for old records:
python data_cleaner.pyAutomatically removes data older than configured retention period.
Logs are written to:
- Console (real-time)
jyotiyantra.log(persistent)
Log levels: INFO, WARNING, ERROR
- API key authentication
- Input validation
- SQL injection protection
- Rate limiting ready
- CORS enabled for frontend integration
FROM python:3.9-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
EXPOSE 5000
CMD ["gunicorn", "--bind", "0.0.0.0:5000", "app:app"]The system tracks:
- Request count and response times
- ThingsBoard connection status
- Data validation errors
- API authentication failures
- Fork the repository
- Create feature branch
- Commit changes
- Push to branch
- Create Pull Request
MIT License - see LICENSE file for details.
For issues and questions:
- Check API_DOCS.md
- Review logs in
jyotiyantra.log - Open GitHub issue
- WebSocket support for real-time updates
- Database caching layer
- Advanced analytics endpoints
- Mobile app integration
- Machine learning predictions
- Multi-device support
- Cloud deployment guides
EcoVisionPro - Illuminating renewable energy monitoring ๐โก