Skip to content

An Example Function app which Auto ingests data from an Event Hub into ADT

License

Notifications You must be signed in to change notification settings

WaywardHayward/adt-auto-ingestor

Repository files navigation

Azure Digital Twin Auto Ingestor

Build and Test Azure Digital Twins Auto Ingester

Function app which Auto ingests data from an Event Hub into Azure Digital Twins

How to Run the Function Locally

To debug this function locally in vscode you will require the following items.

ℹ️ You must have Access to the Azure Digital Twins instance you are running against and have the role "Azure Digital Twins Data Owner" as a minimum to run this function app.

This function app uses dotnetcore 3.1 LTS to build and run it use the standard dotnet commands from within the src directory

cd src
dotnet restore
dotnet build

This function app makes use of a local.settings.json file which you must populate with settings described in the Settings section below.

Architecture

The function app is designed to ingest data from an Event Hub into Azure Digital Twins using the following architecture.

Architecture

Function App Settings

The following settings are required on top of the standard Azure Function app settings to run the function.

Setting Name Type Description
INGESTION_EVENTHUB_CONNECTION_STRING string This is the connection string for the event hub you want to connect to
INGESTION_EVENTHUB_NAME string This is the name of the event hub you want to connect to
INGESTION_EVENTHUB_CONSUMERGROUP string The Consumer Group you want to use to listen to the event hub with
INGESTION_TWIN_URL string The fully qualified Azure Digital Twins instance url https://<your-instance-name>.api.<your-instance-location-shortcode>.digitaltwins.azure.net
INGESTION_ADT_TWIN_IDENTIFIERS string An Optional Property, comprising of a semi-colon separated list of Json Paths to extract the Twin Identifier from the Generic Messages. if not supplied the Path message.DeviceId or the iot-device-identifier from the message properties are used.
INGESTION_MODEL_IDENTIFIERS string An Optional Property, comprising of a semi-colon separated list of Json Paths to extract the Model Identifier from the Generic Messages. if not supplied the Path message.ModelId or the iot-model-identifier from the message properties are used.
INGESTION_TIMESTAMP_IDENTIFIERS string An Optional Property, comprising of a semi-colon separated list of Json Paths to extract the Timestamp from the Generic Messages. if not supplied the The current time in UTC is used
INGESTION_OPC_ENABLED boolean An Optional Property, defines if the function app should auto ingest OPC Sensors - when not supplied is treated as false
INGESTION_GENERIC_ENABLED boolean An Optional Property, defines if the function app should auto ingest any messages - when not supplied is treated as false

ℹ️ The Azure Function App must run with a Managed Identity which has Access to the Azure Digital Twins instance you are running against and have the role "Azure Digital Twins Data Owner" as a minimum to run this function app.

OPC Message Ingestion

When the flag INGESTION_OPC_ENABLED is set to true, the function will ingest messages which are identified as OPC messages into a Twin.

The function will automatically provision an OPC Sensor Model and create a twin per OPC Node Id it detects.

An OPC Twin Node Id is made of the following

ApplicationUri + (NodeId or Id) 

A message is identified as an OPC Message by the presence of the following properties.

  • NodeId
  • ApplicationUri
  • Value

Expected OPC Message Format

The expected OPC message format expected is one of the two schemas referenced below

 {
      "NodeId": "i=2058",
      "ApplicationUri": "urn:myopcserver",
      "DisplayName": "CurrentTime",
      "Value": {
          "Value": "10.11.2017 14:03:17",
          "SourceTimestamp": "2017-11-10T14:03:17Z"
      }
  }

or

 {
      "NodeId": "i=2058",
      "ApplicationUri": "urn:myopcserver",
      "DisplayName": "CurrentTime",
      "Value": "10.11.2017 14:03:17",
      "SourceTimestamp": "2017-11-10T14:03:17Z"
  }

Generic Message Ingestion

When the flag INGESTION_GENERIC_ENABLED is set to true, the function will ingest all messages (other than OPC and TIQ messages if enabled) into a Twin.

Trademarks This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow Microsoft’s Trademark & Brand Guidelines. Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party’s policies.

About

An Example Function app which Auto ingests data from an Event Hub into ADT

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks