Skip to main content

Setup Environment for Schema Validation

Before building the complete schema validation solution, you'll set up edge nodes and prepare sample data.

Prerequisites

This example requires the following services to be running:

Before you begin, please ensure these services are set up and running according to their respective guides. Additionally, ensure you have completed the Local Development Setup guide for general environment configuration.

Step 1: Create Schema Directory

Create a local directory for schema files:

mkdir -p /tmp/expanso/schemas

Step 2: Prepare Sample Sensor Data

Create test data to verify schema validation works correctly:

# Create sample data directory
mkdir -p /tmp/sensor-test-data

# Create valid sensor reading
cat > /tmp/sensor-test-data/valid-reading.json << 'EOF'
{
"sensor_id": "sensor-42",
"timestamp": "2025-10-20T14:30:00Z",
"location": {
"building": "warehouse-3",
"floor": 2,
"zone": "A"
},
"readings": {
"temperature_celsius": 23.5,
"humidity_percent": 45.2
},
"metadata": {
"firmware_version": "2.1.0",
"battery_percent": 87
}
}
EOF

# Create invalid sensor reading (missing required fields)
cat > /tmp/sensor-test-data/invalid-reading-1.json << 'EOF'
{
"sensor_id": "sensor-99",
"timestamp": "2025-10-20T14:30:00Z"
}
EOF

# Create invalid sensor reading (wrong data types)
cat > /tmp/sensor-test-data/invalid-reading-2.json << 'EOF'
{
"sensor_id": "sensor-42",
"timestamp": "2025-10-20T14:30:00Z",
"location": {
"building": "warehouse-3",
"floor": "second floor",
"zone": "A"
},
"readings": {
"temperature_celsius": "twenty-three point five",
"humidity_percent": 45.2
},
"metadata": {
"firmware_version": "2.1.0",
"battery_percent": 87
}
}
EOF

# Create invalid sensor reading (values out of range)
cat > /tmp/sensor-test-data/invalid-reading-3.json << 'EOF'
{
"sensor_id": "sensor-42",
"timestamp": "not-a-timestamp",
"location": {
"building": "warehouse-3",
"floor": 2,
"zone": "A"
},
"readings": {
"temperature_celsius": -500,
"humidity_percent": 150
},
"metadata": {
"firmware_version": "2.1.0",
"battery_percent": 87
}
}
EOF

# Verify test data files
echo "Test data files created:"
ls -la /tmp/sensor-test-data/
echo ""

echo "Valid reading sample:"
jq . /tmp/sensor-test-data/valid-reading.json

Step 3: Set Environment Variables

Configure endpoints for analytics and metrics collection:

# Set up environment variables for pipeline configuration
export ANALYTICS_ENDPOINT="http://localhost:9000"
export METRICS_ENDPOINT="http://localhost:9001"
export NODE_ID="edge-sensor-001"

# Verify environment variables
echo "Analytics endpoint: $ANALYTICS_ENDPOINT"
echo "Metrics endpoint: $METRICS_ENDPOINT"
echo "Node ID: $NODE_ID"

Step 4: Set Up Mock Analytics Endpoint

Create a simple HTTP server to capture messages for testing:

# Start mock analytics endpoint in background
echo "Starting mock analytics endpoint..."
python3 -m http.server 9000 --bind localhost &
ANALYTICS_PID=$!

echo "Analytics endpoint PID: $ANALYTICS_PID"

# Start mock metrics endpoint
python3 -m http.server 9001 --bind localhost &
METRICS_PID=$!

echo "Metrics endpoint PID: $METRICS_PID"

Next Steps

With your environment set up and verified, you're ready to build the complete schema validation solution: