Webhook Configuration
Configure TTN webhooks to automatically send water quality sensor data to your JalRakshak.AI backend for processing and storage.
What are Webhooks?
Webhooks are HTTP callbacks that automatically send data from TTN to your application when events occur (like receiving sensor uplinks). The JalRakshak.AI webhook endpoint receives, decodes, and stores water quality readings in MongoDB.
Data Flow:
Setting Up Webhooks
Important
Ensure your JalRakshak.AI application is deployed and publicly accessible before configuring webhooks. For local development, you can use the SmartPark relay as a bridge.
Webhook Configuration Steps
Navigate to Webhooks
In your TTN application, go to "Integrations" → "Webhooks"
Add Webhook
Click "+ Add webhook" → "Custom webhook"
Configure Webhook ID
Set Base URL
Production (after Vercel deploy):
Local Development (use SmartPark relay as bridge):
The relay forwards data to your localhost. Useful during development when your server isn't publicly accessible.
Enable Uplink Message
Under Enabled messages, tick Uplink message only.
Optional: Secure with Shared Secret
For production, secure your webhook with a shared secret:
Add custom header in TTN:
Set the same value in Vercel environment:
Leave both unset for open access (fine for hackathon / development).
Webhook API Endpoint
Receives TTN uplink data, decodes payload, and stores readings in MongoDB.
Expected Payload Structure:
{
"end_device_ids": {
"device_id": "jalrakshak-node-01",
"application_ids": {
"application_id": "jalrakshak-ai"
}
},
"uplink_message": {
"decoded_payload": {
"temperature": 25.3,
"tds": 312,
"ph": 7.21
},
"rx_metadata": [
{
"gateway_ids": {
"gateway_id": "your-gateway"
},
"rssi": -85,
"snr": 9.5
}
]
}
}Backend Processing:
Testing & Verification
After configuring the webhook, verify it's working correctly:
1Check Webhook Status in TTN Console
2Check Database for New Readings
/api/sensor-data in your browser3Verify Dashboard Updates
4Monitor Serial Output (ESP32)
Troubleshooting Common Issues
❌ Webhook returns 404 or 500 errors
- Webhook URL is incorrect or server is not deployed
- API route doesn't exist or has errors
- Server is not publicly accessible
- Verify URL matches your deployed application
- Check Vercel deployment logs for errors
- Test endpoint manually with curl or Postman
❌ Data received but not stored in database
- MongoDB connection string is incorrect
- Payload structure doesn't match expected format
- TTN payload decoder not configured
- Check
DATABASE_URLin environment variables - Verify payload decoder is set up correctly in TTN
- Test database connection with
/api/db-test
❌ Dashboard not showing new data
- Dashboard polling interval too long
- Device ID mismatch between TTN and expected format
- Data stuck in relay (for local development)
- Manually refresh dashboard page
- Verify device ID format matches exactly
- Check if MongoDB has recent readings for this device
- Clear browser cache and reload
Need More Help?
Check TTN Console → Application → Live data to see real-time messages from your devices. This is the best way to debug webhook and payload issues.
🎉 Setup Complete!
Your JalRakshak.AI system is now fully configured and ready to monitor water quality.