Zelta/Documentation

Azure IoT Hub Integration

Integrate Zelta with Azure IoT Hub to route device messages to your Azure infrastructure while maintaining Zelta's OTA capabilities.

Overview

The Azure IoT Hub integration allows you to:

  • ✅ Route device messages to Azure Event Hubs, Service Bus, and Storage
  • ✅ Keep Zelta for firmware updates and device management
  • ✅ Use Azure Functions, Stream Analytics, and AI services
  • ✅ Maintain a single MQTT connection from devices to Zelta

Architecture

Device → Zelta MQTT Broker → Zelta Cloud (OTA)
              ↓
       Azure IoT Hub → Your Azure Services

Prerequisites

  1. Azure Subscription with IoT Hub resource
  2. Zelta Account (Pro plan or higher for cloud integrations)
  3. Azure IoT Hub created with shared access policy

Setup Steps

1. Create Azure IoT Hub

# Create resource group
az group create --name zelta-integration --location eastus

# Create IoT Hub (S1 tier for production)
az iot hub create \
  --name zelta-bridge-hub \
  --resource-group zelta-integration \
  --sku S1 \
  --partition-count 2

# Get connection string
az iot hub connection-string show \
  --hub-name zelta-bridge-hub \
  --policy-name iothubowner

2. Create Device Identity

# Create a device for the bridge
az iot hub device-identity create \
  --hub-name zelta-bridge-hub \
  --device-id zelta-bridge-device

# Get device connection string
az iot hub device-identity connection-string show \
  --hub-name zelta-bridge-hub \
  --device-id zelta-bridge-device

3. Generate SAS Token (Alternative to Connection String)

# Generate SAS token valid for 1 year
az iot hub generate-sas-token \
  --hub-name zelta-bridge-hub \
  --device-id zelta-bridge-device \
  --duration 31536000

4. Configure in Zelta Dashboard

  1. Go to Settings → Cloud Integrations

  2. Click Add Integration → Azure IoT Hub

  3. Fill in the form:

    • Name: My Azure IoT Integration
    • Azure Hostname: zelta-bridge-hub.azure-devices.net
    • Device ID: zelta-bridge-device
    • Connection String: (Paste from step 2) OR
    • Shared Access Key: (Paste SAS token from step 3)
  4. Configure message routing:

    • ✅ Forward Heartbeats
    • ✅ Forward Telemetry
    • ⬜ Forward Events
    • ⬜ Forward Logs
  5. Set up topic mapping (optional):

{
  "zelta/+/+/up/heartbeat": "devices/{device_id}/messages/events/",
  "zelta/+/+/up/telemetry": "devices/{device_id}/messages/events/telemetry",
  "zelta/+/+/up/event": "devices/{device_id}/messages/events/alerts"
}
  1. Click Test Connection to verify
  2. Click Save and Activate

Topic Mapping

Default Mapping

If no custom mapping is provided, Zelta routes all messages to:

devices/{device_id}/messages/events/

Custom Mapping with Message Properties

Azure IoT Hub doesn't support custom topics, but you can add message properties:

{
  "zelta/+/+/up/heartbeat": "devices/{device_id}/messages/events/?type=heartbeat",
  "zelta/+/+/up/telemetry": "devices/{device_id}/messages/events/?type=telemetry&source=zelta"
}

These properties can be used in Azure routing queries.

Use Cases

1. Time Series Insights

Route telemetry to Azure Time Series Insights:

# Create TSI environment
az tsi environment create \
  --name zelta-tsi \
  --resource-group zelta-integration \
  --sku S1 \
  --data-retention-time P30D

# Create event source from IoT Hub
az tsi event-source iothub create \
  --environment-name zelta-tsi \
  --name IotHubSource \
  --iot-hub-name zelta-bridge-hub \
  --consumer-group tsi-consumer \
  --key-name iothubowner

2. Stream Analytics

Process device data in real-time:

-- Azure Stream Analytics Query
SELECT
    deviceId,
    AVG(temperature) as avgTemp,
    MAX(temperature) as maxTemp,
    System.Timestamp() as windowEnd
INTO
    [CosmosDB-Output]
FROM
    [IoTHub-Input]
WHERE
    type = 'telemetry'
GROUP BY
    deviceId,
    TumblingWindow(minute, 5)

3. Event Grid Integration

Trigger Azure Functions on device events:

# Create Event Grid subscription
az eventgrid event-subscription create \
  --name device-events \
  --source-resource-id /subscriptions/.../resourceGroups/.../providers/Microsoft.Devices/IotHubs/zelta-bridge-hub \
  --endpoint https://zelta-function.azurewebsites.net/api/DeviceEvent \
  --endpoint-type webhook

4. Device Twin Synchronization

Update device twins with heartbeat data:

// Azure Function triggered by IoT Hub messages
module.exports = async function (context, IoTHubMessage) {
    const deviceId = context.bindingData.systemProperties['iothub-connection-device-id'];
    
    if (IoTHubMessage.type === 'heartbeat') {
        const twin = await getTwin(deviceId);
        await twin.update({
            properties: {
                reported: {
                    online: true,
                    lastSeen: new Date().toISOString(),
                    firmwareVersion: IoTHubMessage.version
                }
            }
        });
    }
};

Message Routing

Built-in Endpoints

Route to Azure services without code:

# Route to Event Hub
az iot hub route create \
  --hub-name zelta-bridge-hub \
  --route-name ToEventHub \
  --source DeviceMessages \
  --endpoint-name eventHubEndpoint \
  --condition "type='telemetry'"

# Route to Storage
az iot hub route create \
  --hub-name zelta-bridge-hub \
  --route-name ToStorage \
  --source DeviceMessages \
  --endpoint-name storageEndpoint \
  --condition "type='heartbeat'"

# Route to Service Bus
az iot hub route create \
  --hub-name zelta-bridge-hub \
  --route-name ToServiceBus \
  --source DeviceMessages \
  --endpoint-name serviceBusEndpoint \
  --condition "type='alert'"

Security Best Practices

  1. Use Managed Identities: Avoid storing connection strings
  2. Rotate SAS Tokens: Regenerate every 90 days
  3. Least Privilege: Use custom shared access policies
  4. Enable Diagnostics: Send logs to Log Analytics
  5. Monitor Security Alerts: Use Azure Security Center

Troubleshooting

Connection Failed

Check:

  1. Hostname is correct (format: {hub-name}.azure-devices.net)
  2. Device exists in IoT Hub
  3. Connection string or SAS token is valid
  4. Network connectivity to Azure

Messages Not Arriving

  1. Check IoT Hub message routing rules
  2. Verify consumer groups are not exhausted
  3. Test with Azure IoT Explorer
  4. Check built-in events endpoint

Authentication Errors

  1. Regenerate SAS token
  2. Verify device ID matches
  3. Check shared access policy permissions
  4. Ensure connection string format is correct

Pricing

  • Zelta: Cloud integrations available on Pro plan ($29/mo) and higher
  • Azure IoT Hub:
    • S1 tier: $25/month + $0.50 per million messages
    • Free tier: 8,000 messages/day (good for testing)

Monitoring

View Metrics

# Get message count
az monitor metrics list \
  --resource /subscriptions/.../resourceGroups/.../providers/Microsoft.Devices/IotHubs/zelta-bridge-hub \
  --metric "d2c.telemetry.ingress.allProtocol"

# View diagnostics
az monitor diagnostic-settings create \
  --name zelta-diagnostics \
  --resource /subscriptions/.../resourceGroups/.../providers/Microsoft.Devices/IotHubs/zelta-bridge-hub \
  --workspace /subscriptions/.../resourceGroups/.../providers/Microsoft.OperationalInsights/workspaces/zelta-logs

Next Steps