TTN Setup

Configure The Things Network (TTN) for LoRaWAN communication with your JalRakshak.AI water quality sensors.

LoRaWAN
TTN Console
OTAA
Device Management

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:

🌍 Europe: eu1.cloud.thethings.network
🇺🇸 North America: nam1.cloud.thethings.network
🌏 Asia-Pacific: au1.cloud.thethings.network
🇮🇳 India: Use eu1 with India 865-867 MHz

Create Application

1

Navigate to Applications

In the TTN Console, click on "Applications" in the left sidebar.

2

Create New Application

Click "+ Create application" button and fill in the details:

Application ID:
jalrakshak-ai
Application name:
JalRakshak Water Monitor
Description:
LoRaWAN water quality monitoring sensors
3

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

1

Register End Device

In your application, click "Register end device"

2

Enter End Device Specifics Manually

Choose "Enter end device specifics manually" option

3

Select Frequency Plan

Frequency Plan:
India 865-867 MHz (FSK)
For deployment in India
4

Select LoRaWAN Version

LoRaWAN version:
MAC V1.0.2
Regional Parameters Version:
RP001 1.0.2 rev B
5

Set Join EUI (AppEUI)

JoinEUI / AppEUI:
0000000000000000
All Zeros
Set to all zeros (0000000000000000)
6

Generate DEVEUI and AppKey

DevEUI (Device EUI):
Click Generate to create
Auto-generated 16-character hex (LSB format for Arduino)
AppKey (Application Key):
Click Generate to create
Auto-generated 32-character key (MSB format for Arduino)

Important: DevEUI must be copied in LSB format. AppKey in MSB format. Use the ↕ toggle in the TTN Console.

7

Give Device ID

End device ID:
jalrakshak-node-01
Choose a unique identifier for this device (e.g., location-based)
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.

8

Register End Device

Review all settings and click "Register end device" button

Device will be registered and credentials will be available

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

1

Go to your application → Payload formattersUplink

2

Select Formatter type: Custom Javascript formatter

3

Paste the following code in the formatter field:

JavaScript Decoder Function:
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

Bytes 0-1 - Temperature:
Value ÷ 10 = °C
Example: 253 → 25.3°C
Bytes 2-3 - TDS:
Direct value in ppm
Example: 312 → 312 ppm
Bytes 4-5 - pH:
Value ÷ 100 = pH
Example: 721 → 7.21
Example Output:
// Input bytes: [00, FD, 01, 38, 02, D1]
{
"temperature": 25.3,
"tds": 312,
"ph": 7.21
}

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

Urban areas: 2-5 km range
Suburban areas: 5-15 km range
Rural areas: 15+ km range
Indoor deployment: Reduced range

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

What's Configured:

TTN Account & Application Setup
Device Registration & Keys
Payload Decoder Function
Gateway Coverage Verification

🚀 Next Steps:

1.Configure webhooks to send data to your JalRakshak.AI backend
2.Upload the generated Arduino code to your ESP32
3.Deploy your water quality sensor and monitor dashboard