TTN Setup
Configure The Things Network (TTN) for LoRaWAN communication with your JalRakshak.AI water quality sensors.
TTN Account Setup
1. Create TTN Account
• Visit console.thethingsnetwork.org
• Click "Sign up" to create a free account
• Verify your email address
• Complete your profile setup
2. Choose Your Region
Select the appropriate TTN cluster for your region:
Create Application
Navigate to Applications
In the TTN Console, click on "Applications" in the left sidebar.
Create New Application
Click "+ Create application" button and fill in the details:
Configure Application Settings
After creation, you can modify additional settings in the application overview.
Register End Device
OTAA vs ABP
This guide uses OTAA (Over-The-Air Activation) which is more secure and the recommended approach for production deployments.
Device Registration Process
Register End Device
In your application, click "Register end device"
Enter End Device Specifics Manually
Choose "Enter end device specifics manually" option
Select Frequency Plan
Select LoRaWAN Version
Set Join EUI (AppEUI)
Generate DEVEUI and AppKey
Important: DevEUI must be copied in LSB format. AppKey in MSB format. Use the ↕ toggle in the TTN Console.
Give Device ID
Important: Device ID Linking
This Device ID becomes the deviceId stored in MongoDB. It will be used to identify this sensor in the dashboard and database.
Register End Device
Review all settings and click "Register end device" button
Payload Formatter
Why Payload Formatter?
TTN can decode binary payloads before sending to your webhook, making data more readable. Configure this in the TTN Console under Payload formatters section.
Configure Custom JavaScript Formatter
Go to your application → Payload formatters → Uplink
Select Formatter type: Custom Javascript formatter
Paste the following code in the formatter field:
function decodeUplink(input) {
// Byte layout (6 bytes total):
// [0-1] temperature ÷ 10 → °C
// [2-3] TDS × 1 → ppm
// [4-5] pH ÷ 100 → 0–14
var temp = (input.bytes[0] << 8 | input.bytes[1]) / 10;
var tds = (input.bytes[2] << 8 | input.bytes[3]);
var ph = (input.bytes[4] << 8 | input.bytes[5]) / 100;
return {
data: {
temperature: temp,
tds: tds,
ph: ph
}
};
}Payload Structure Explanation
Example: 253 → 25.3°C
Example: 312 → 312 ppm
Example: 721 → 7.21
Example Output:
Note: Turbidity and conductivity are generated server-side. Turbidity is a placeholder random value (1-10 NTU) until hardware is added. Conductivity is calculated as TDS × 2 μS/cm.
Gateway Coverage
Check Coverage
• Visit TTN Coverage Map
• Zoom to your deployment location
• Verify gateway coverage in your area
• Note nearest gateways and their range
Range Considerations
No Coverage?
If there are no gateways in your area, consider setting up your own TTN gateway or using a private LoRaWAN network server.
🎉 TTN Configuration Complete!
Your device is now registered and ready for webhook integration