Azure IoT Hub

Integrate Thingsee IoT with Microsoft Azure IoT Hub.

Azure IoT Hub is one of the most common integration points for Thingsee data. This guide explains how to set up the connection.

How It Works

Thingsee Operations Cloud connects as a single device to your Azure IoT Hub. All sensor data is forwarded through this connection with individual device identifiers inside each message.

%%{init: {'theme':'base','themeVariables':{'primaryColor':'#73F9C1','primaryTextColor':'#143633','primaryBorderColor':'#143633','lineColor':'#143633','secondaryColor':'#C7FDE6','tertiaryColor':'#F6FAFA','clusterBkg':'#F6FAFA','clusterBorder':'#143633'}}}%%
flowchart TB
    subgraph Azure["Azure"]
        App[Your App]
        EH[Event Hub]
        Hub[IoT Hub]
    end
    
    subgraph ThingseeCloud["Thingsee Cloud"]
        Cloud[Operations Cloud]
    end
    
    subgraph Gateway["Gateway"]
        GW[Gateway]
    end
    
    subgraph Sensors["Sensors"]
        S1[Sensor 1]
        S2[Sensor 2]
    end
    
    Sensors --> Gateway
    Gateway --> ThingseeCloud
    ThingseeCloud -->|Single Device Connection| Hub
    Hub --> EH --> App

Setup Requirements

Provide Haltian with your Azure IoT Hub connection string:

HostName=<your-hub>.azure-devices.net;DeviceId=<device-id>;SharedAccessKey=<key>

Contact support@haltian.com with this information to enable the integration.


Message Format

Messages arrive as JSON arrays containing multiple message types:

[
  {
    "tsmId": 12101,
    "tsmEv": 10,
    "hall": 0,
    "hallCount": 0,
    "tsmTs": 1520416221,
    "tsmTuid": "XXXX03X2Z80562557",
    "tsmGw": "XXXX00EFS80560445"
  },
  {
    "tsmId": 1110,
    "tsmEv": 10,
    "batl": 100,
    "tsmTs": 1520416221,
    "tsmTuid": "XXXX03X2Z80562557",
    "tsmGw": "XXXX00EFS80560445"
  },
  {
    "tsmId": 12100,
    "tsmEv": 10,
    "airp": 101364.599,
    "lght": 6,
    "temp": 21.3,
    "humd": 21.7,
    "tsmTs": 1520416221,
    "tsmTuid": "XXXX03X2Z80562557",
    "tsmGw": "XXXX00EFS80560445"
  }
]

Parsing Strategy

  1. Iterate through the array
  2. Check tsmId to determine message type
  3. Extract properties based on the message profile
  4. Use tsmTuid to identify the originating device

See Message Profiles for complete field definitions.


Processing in Azure

Event Hub Consumer

// C# example using Azure.Messaging.EventHubs
using Azure.Messaging.EventHubs.Consumer;
using System.Text.Json;

await foreach (PartitionEvent partitionEvent in consumer.ReadEventsAsync())
{
    string body = Encoding.UTF8.GetString(partitionEvent.Data.Body.ToArray());
    var messages = JsonSerializer.Deserialize<List<ThingseeMessage>>(body);
    
    foreach (var msg in messages)
    {
        Console.WriteLine($"Device: {msg.TsmTuid}, Type: {msg.TsmId}");
        
        switch (msg.TsmId)
        {
            case 12100: // Environment
                ProcessEnvironmentData(msg);
                break;
            case 1110: // Battery
                ProcessBatteryData(msg);
                break;
            // ... handle other message types
        }
    }
}

Azure Function Trigger

[FunctionName("ProcessThingseeData")]
public static async Task Run(
    [EventHubTrigger("messages/events", Connection = "IoTHubConnection")] EventData[] events,
    ILogger log)
{
    foreach (EventData eventData in events)
    {
        string body = Encoding.UTF8.GetString(eventData.Body.ToArray());
        var messages = JsonSerializer.Deserialize<List<ThingseeMessage>>(body);
        
        foreach (var msg in messages)
        {
            log.LogInformation($"Received {msg.TsmId} from {msg.TsmTuid}");
            // Process message...
        }
    }
}

Alternative: Per-Device Mapping

If your architecture requires unique Azure Device IDs per sensor, this can be configured. Each tsmTuid would map to its own Azure device.

Trade-offs:

  • ✅ Native Azure device management
  • ✅ Per-device twins and direct methods
  • ❌ Requires pre-registration of all devices
  • ❌ More complex message routing
  • ❌ Bundled messages become per-device

Contact Haltian to discuss this option for your deployment.