5.4 KiB
Environment Variables Setup Guide
This guide explains all environment variables needed for the Omada Cloud Integration System.
Quick Setup
-
Copy the template:
cp env.example .envOr use the setup script:
pnpm run setup:env -
Edit
.envand fill in your values (see details below)
Required Environment Variables
Omada Cloud Authentication
You can use either OAuth (Client ID/Secret) or Username/Password authentication. The system will automatically detect which method to use based on which credentials are provided.
Option 1: OAuth Authentication (Recommended)
If you have TP-LINK Open API credentials:
TP_LINK_CLIENT_ID=your-client-id-here
TP_LINK_CLIENT_SECRET=your-client-secret-here
TP_LINK_APPLICATION=Datacenter-Control-Complete
TP_LINK_REDIRECT_URI=http://localhost:3000/callback
TP_LINK_API_BASE_URL=https://openapi.tplinkcloud.com
How to get these:
- Register your application at TP-LINK Developer Portal
- Create an OAuth app to get Client ID and Secret
- Set the redirect URI to match your application
Note: OAuth implementation is currently in progress. For now, use username/password authentication.
Option 2: Username/Password Authentication
OMADA_USERNAME=your-omada-email@example.com
OMADA_PASSWORD=your-strong-password
How to find these values:
OMADA_USERNAME: Your Omada cloud account emailOMADA_PASSWORD: Your Omada cloud account password
Omada Cloud Configuration (Required)
These are always required regardless of authentication method:
OMADA_ID=b7335e3ad40ef0df060a922dcf5abdf5
OMADA_CONTROLLER_BASE=https://euw1-omada-controller.tplinkcloud.com
OMADA_NORTHBOUND_BASE=https://euw1-omada-northbound.tplinkcloud.com
How to find these values:
OMADA_ID: Found in your Omada controller URL (the long hex string)OMADA_CONTROLLER_BASE: Base URL for authentication (usuallyhttps://{region}-omada-controller.tplinkcloud.com)OMADA_NORTHBOUND_BASE: Base URL for API calls (usuallyhttps://{region}-omada-northbound.tplinkcloud.com)
Database
DATABASE_URL=postgresql://user:password@localhost:5432/omada_db?schema=public
For Docker Compose (local development):
DATABASE_URL=postgresql://omada_user:omada_password@localhost:5432/omada_db?schema=public
For production: Use your actual PostgreSQL connection string.
Authentication
JWT_SECRET=your-jwt-secret-key-change-in-production-minimum-32-characters
Generate a secure secret:
openssl rand -base64 32
Optional Environment Variables
Server Configuration
PORT=3000 # API server port (default: 3000)
NODE_ENV=development # Environment: development, staging, production
Logging
LOG_LEVEL=info # Log level: error, warn, info, debug
Recommended values:
- Development:
debug(detailed logs) - Production:
infoorwarn(less verbose)
Background Jobs
SYNC_JOB_SCHEDULE=*/10 * * * * # Inventory sync schedule (default: every 10 minutes)
LICENSE_JOB_SCHEDULE=0 9 * * * # License check schedule (default: daily at 9 AM)
Cron format: minute hour day month day-of-week
Examples:
*/10 * * * *- Every 10 minutes0 * * * *- Every hour0 9 * * *- Daily at 9 AM0 9 * * 1- Every Monday at 9 AM0 0 1 * *- First day of every month at midnight
Complete Example
Here's a complete .env file example for local development:
# Omada Cloud Credentials
OMADA_USERNAME=admin@example.com
OMADA_PASSWORD=SecurePassword123!
OMADA_ID=b7335e3ad40ef0df060a922dcf5abdf5
OMADA_CONTROLLER_BASE=https://euw1-omada-controller.tplinkcloud.com
OMADA_NORTHBOUND_BASE=https://euw1-omada-northbound.tplinkcloud.com
# Database (Docker Compose)
DATABASE_URL=postgresql://omada_user:omada_password@localhost:5432/omada_db?schema=public
# Server
PORT=3000
NODE_ENV=development
# Authentication
JWT_SECRET=$(openssl rand -base64 32)
# Logging
LOG_LEVEL=debug
# Background Jobs
SYNC_JOB_SCHEDULE=*/10 * * * *
LICENSE_JOB_SCHEDULE=0 9 * * *
Validation
The application will validate all required environment variables on startup. If any are missing, you'll see an error message listing which variables need to be set.
Security Notes
- Never commit
.envto version control - it's already in.gitignore - Use strong passwords for
OMADA_PASSWORDandJWT_SECRET - Rotate secrets regularly in production
- Use environment-specific values - different
.envfiles for dev/staging/prod - Consider using secrets management in production (AWS Secrets Manager, HashiCorp Vault, etc.)
Troubleshooting
"Missing required environment variables" error
Check that all required variables are set in your .env file:
OMADA_USERNAMEOMADA_PASSWORDOMADA_IDOMADA_CONTROLLER_BASEOMADA_NORTHBOUND_BASEDATABASE_URLJWT_SECRET
Database connection errors
Verify your DATABASE_URL is correct:
- Check PostgreSQL is running
- Verify username, password, host, and port
- Ensure the database exists
- Check network connectivity
Omada authentication failures
Verify your Omada credentials:
- Check
OMADA_USERNAMEandOMADA_PASSWORDare correct - Verify
OMADA_IDmatches your controller - Ensure
OMADA_CONTROLLER_BASEandOMADA_NORTHBOUND_BASEare correct for your region