Connecting external systems
Data does not start in OctoMesh. It lives in a device, an API, a database or a file, and something has to carry it in. This tutorial helps you to choose how the connection works and walks you through one complete example: a pipeline that reads a public weather API on a schedule, updates an entity and stores every reading as a point of a time series.
Time: about 60 minutes.
- A tenant with communication enabled and a Mesh Adapter that is online, for example the local tenant of
getting-started (
octo-cli -c GetAdaptersshows the stateOnline). The examples use<tenant>for the tenant id. - octo-cli 3.5.0 or newer, logged in to that tenant, and
octo-ckcas in tutorial 6. - The idea of an HTTP endpoint on the Mesh Adapter from tutorial 5; this tutorial does not repeat it.
The example writes entities and a time series and starts a pipeline that runs every minute. Work in a local or test tenant and switch the trigger off at the end (step 6).
Four ways to connect a system
| HTTP push | Adapter | File | Scheduled pull | |
|---|---|---|---|---|
| Use it when | The source can call a URL and sends events or readings when they happen | The source speaks a protocol OctoMesh has no node for, or sits in a network the cloud cannot reach (plant, edge device) | Data arrives as an export: CSV, Excel, a report | The source is an API you can call and that does not call you |
| Who starts it | The external system | The adapter, next to the source | A person or a job that uploads the file | OctoMesh, on a cron schedule |
| Where it runs | Pipeline on the tenant's Mesh Adapter | Own adapter process (cloud or edge) registered at the tenant | Pipeline on the Mesh Adapter, file via an HTTP endpoint | Pipeline on the Mesh Adapter |
| Trigger node | FromHttpRequest@2 (tutorial 5) | Trigger nodes of the adapter | FromHttpRequest with the file at $.files, then ImportFromCsv@1 or ImportFromExcel@1 | FromPipelineTriggerEvent@1 plus a PipelineTrigger entity |
| Credentials | The caller needs a client and a role of the tenant | Connection data in the adapter's configuration | The uploader needs a role of the tenant | Key of the external API in a configuration entry of the tenant |
| If it fails | The caller sees the error and has to resend; nothing arrives without a call | The adapter shows Offline, its pipelines do not run | The upload is rejected or partly imported; the uploader sees the result | The next run tries again; with the default error handling a failed request is only logged |
| State | None on the OctoMesh side | The adapter keeps its connection | None | The schedule lives in the tenant |
How to decide:
- Can the source call a URL? Use HTTP push, it needs no extra process.
- Can OctoMesh call the source over the internet and is a delay of a minute or more acceptable? Use a scheduled pull; this is the example below.
- Is the data a file that someone hands over? Use file import.
- Does the source speak OPC UA, Modbus or another protocol, or can it only be reached from inside a site? Build or deploy an adapter (last section).
Step 1: The model
The example stores weather readings on a station entity. The model is small and built on the public Basic kit,
as in tutorial 6:
$schema: https://schemas.meshmakers.cloud/construction-kit-meta.schema.json
modelId: Tutorial.Weather-1.0.0
description: Weather stations with current measurements, built on the public Basic Construction Kit.
dependencies:
- Basic-[2.4,3.0)
attributes/weather.yaml:
$schema: https://schemas.meshmakers.cloud/construction-kit-elements.schema.json
attributes:
- id: Temperature
valueType: Double
description: Air temperature in degrees Celsius.
- id: WindSpeed
valueType: Double
description: Wind speed in kilometres per hour.
types/weather.yaml:
$schema: https://schemas.meshmakers.cloud/construction-kit-elements.schema.json
types:
- typeId: WeatherStation
description: A weather station that reports its current measurements.
derivedFromCkTypeId: ${Basic}/Asset
attributes:
- id: ${this}/Temperature
name: Temperature
isOptional: true
- id: ${this}/WindSpeed
name: WindSpeed
isOptional: true
Compile and import it together with Basic:
octo-cli -c ImportFromCatalog -cn PublicGitHubCatalog -m Basic-2.5.0 -w
octo-ckc -c Compile -p weather/ConstructionKit -o weather/out
octo-cli -c ImportCk -f weather/out/ck-tutorial.weather.yaml -w
The compile ends with Construction kit model directory compiled.
Step 2: Station entity and archive
Time series live in archives. An archive belongs to one CK type and keeps the listed attributes of every
entity update it receives. Enable stream data for the tenant, then import one station and one raw archive for
the type Tutorial.Weather/WeatherStation. Save as weather/seed.yaml:
$schema: https://schemas.meshmakers.cloud/runtime-model.schema.json
dependencies:
- Tutorial.Weather-[1.0,2.0)
- System.StreamData-[1.2,2.0)
entities:
- rtId: 6b0000000000000000000001
ckTypeId: Tutorial.Weather/WeatherStation-1
attributes:
- id: System/Name-1
value: Vienna
- rtId: 6b0000000000000000000010
ckTypeId: System.StreamData/RawArchive-1
rtWellKnownName: WeatherArchive
attributes:
- id: System.StreamData/Archive.TargetCkTypeId-1
value: Tutorial.Weather/WeatherStation
- id: System.StreamData/Archive.Status-1
value: 0
- id: System.StreamData/Archive.Columns-1
value:
- ckRecordId: System.StreamData/CkArchiveColumn-1
attributes:
- id: System.StreamData/CkArchiveColumn.Path-1
value: Temperature
- id: System.StreamData/CkArchiveColumn.Required-1
value: false
- id: System.StreamData/CkArchiveColumn.Indexed-1
value: true
- ckRecordId: System.StreamData/CkArchiveColumn-1
attributes:
- id: System.StreamData/CkArchiveColumn.Path-1
value: WindSpeed
- id: System.StreamData/CkArchiveColumn.Required-1
value: false
- id: System.StreamData/CkArchiveColumn.Indexed-1
value: true
octo-cli -c EnableStreamData
octo-cli -c ImportRt -f weather/seed.yaml -w
octo-cli -c ActivateArchive -id 6b0000000000000000000010
Writes into an archive that is not activated fail, so do not skip the last command.
Step 3: The pipeline
The pipeline has four nodes. It reads the current weather of Vienna from the public Open-Meteo API (no key needed), turns the answer into an entity update, writes the update to the archive and to the station:
triggers:
- type: FromPipelineTriggerEvent@1
transformations:
- type: MakeHttpRequest@1
description: Read the current weather of Vienna from the public Open-Meteo API
method: GET
url: https://api.open-meteo.com/v1/forecast?latitude=48.21&longitude=16.37¤t=temperature_2m,wind_speed_10m
targetPath: $.response
- type: CreateUpdateInfo@1
description: Update the weather station with the new values
targetPath: $.updates
targetValueWriteMode: Append
targetValueKind: Array
updateKind: Update
rtId: 6b0000000000000000000001
ckTypeId: Tutorial.Weather/WeatherStation
attributeUpdates:
- attributeName: temperature
attributeValueType: Double
valuePath: $.response.current.temperature_2m
- attributeName: windSpeed
attributeValueType: Double
valuePath: $.response.current.wind_speed_10m
- type: SaveStreamDataInArchive@1
description: Keep every reading as a time series point
path: $.updates
archiveRtId: 6b0000000000000000000010
- type: ApplyChanges@2
description: Write the latest values to the station entity
entityUpdatesPath: $.updates
What happens, node by node:
FromPipelineTriggerEvent@1starts the pipeline when aPipelineTriggerfires (step 4).MakeHttpRequest@1calls the URL and stores the parsed JSON answer at$.response. The API answers with{"current": {"time": "...", "temperature_2m": 15.6, "wind_speed_10m": 0.8}}.CreateUpdateInfo@1builds an update of the station: the attribute values are read withvaluePathfrom the answer. Attribute names are the camelCase names of the CK type (temperature,windSpeed).SaveStreamDataInArchive@1writes the update as a row of the archive (the archive column paths are the attribute namesTemperatureandWindSpeed);ApplyChanges@2writes the same update to the station entity.
The YAML is valid against the schema of the Mesh Adapter (pipeline schema of the adapter build,
checked with pipeline_validate.py of the octo skill); to check it against your adapter, fetch its schema:
octo-cli -c GetAdapters
octo-cli -c GetPipelineSchema -aid <adapter-rtid> -o weather/schema.json
Step 4: Data flow, pipeline and schedule
A pipeline belongs to a data flow and runs on an adapter; a pipeline trigger starts it on a cron schedule.
Create the three entities. The adapter 670000000000000000000002 is the Mesh Adapter that enabling communication
seeds. Save as weather/dataflow.yaml, with the pipeline definition of step 3 indented under
System.Communication/PipelineDefinition-1:
$schema: https://schemas.meshmakers.cloud/runtime-model.schema.json
dependencies:
- System.Communication-[4.5,5.0)
entities:
- rtId: 6b0000000000000000000020
ckTypeId: System.Communication/DataFlow-1
attributes:
- id: System/Name-1
value: Weather pull
- rtId: 6b0000000000000000000021
ckTypeId: System.Communication/Pipeline-1
associations:
- roleId: System/ParentChild-1
targetRtId: 6b0000000000000000000020
targetCkTypeId: System.Communication/DataFlow-1
- roleId: System.Communication/Executes-1
targetRtId: '670000000000000000000002'
targetCkTypeId: System.Communication/Adapter-1
attributes:
- id: System/Name-1
value: Read weather
- id: System/Enabled-1
value: true
- id: System.Communication/PipelineDefinition-1
value: <the YAML of step 3>
- rtId: 6b0000000000000000000022
ckTypeId: System.Communication/PipelineTrigger-1
associations:
- roleId: System/ParentChild-1
targetRtId: 6b0000000000000000000020
targetCkTypeId: System.Communication/DataFlow-1
- roleId: System.Communication/Triggers-1
targetRtId: 6b0000000000000000000021
targetCkTypeId: System.Communication/Pipeline-1
attributes:
- id: System/Name-1
value: Every minute
- id: System/Enabled-1
value: true
- id: System.Bot/CronExpression-1
value: '* * * * *'
octo-cli -c ImportRt -f weather/dataflow.yaml -w
octo-cli -c DeployDataFlow -id 6b0000000000000000000020
octo-cli -c DeployTriggers
DeployDataFlow registers the pipeline on the adapter; a seeded or imported pipeline does not run before. The
cron expression has five fields (minute, hour, day of month, month, day of week), so * * * * * fires every minute.
Step 5: See the result
After two minutes the pipeline has run at least twice. Check the executions and the entity:
octo-cli -c GetLatestPipelineExecution -id 6b0000000000000000000021
The latest execution shows when it ran, its status (1, completed) and its duration. Read the station through
GraphQL (tutorial 2):
query Station {
runtime {
tutorialWeatherWeatherStation(first: 5) {
items { rtId name temperature windSpeed }
}
}
}
and the time series through the stream-data query described in tutorial 2
(raw values), with the archive 6b0000000000000000000010 and the
column paths temperature and windSpeed:
query Readings($archive: OctoObjectId!, $station: OctoObjectId!, $from: DateTime!, $to: DateTime!) {
streamData {
transientStreamDataQuery {
simple(
archiveRtId: $archive
rtIds: [$station]
columnPaths: ["temperature", "windSpeed"]
arg: { from: $from, to: $to, queryMode: DEFAULT }
) {
items {
columns { attributePath }
rows(first: 20) {
totalCount
items { timestamp cells { items { attributePath value } } }
}
}
}
}
}
}
Each run adds one row: after two runs totalCount is 2 and the station shows the latest values.
Step 6: Stop the schedule
A schedule that you forgot keeps calling the API. Disable the trigger entity or remove the data flow:
octo-cli -c UndeployDataFlow -id 6b0000000000000000000020
Is the connection alive? Operating hints
- The adapter:
octo-cli -c GetAdaptersshowsCommunicationState(Online,Offline) andDeploymentState. - The pipeline:
octo-cli -c GetPipelineStatus -id <pipeline>answers"state":1(success) after a deploy;GetLatestPipelineExecution -id <pipeline>shows time, status and duration of the last run. - A failed API call does not fail the run. By default
MakeHttpRequest@1logs a failed request and skips the nodes after it while the execution still counts as successful. Do not judge by the execution status alone; check the timestamp of the last data point, or setonHttpErrorof the node to a failing mode. - Silent pipelines: enable debug capture (
SetPipelineDebug -id <pipeline> -e true) and readGetPipelineDebugPoints; nodes missing from the tree never ran. - Secrets never go into a pipeline. The URL above carries none. For an API that needs a key, put base URL and
key into a configuration entry of the tenant and name it in the node with
apiConfiguration; the node sends the key in a header (authHeaderName,authHeaderValuePrefix). The pipeline then contains only the name of the entry. The same goes for passwords of databases and clients: they belong into the configuration of the adapter or the tenant, not into YAML files you commit.
Build your own adapter
You need your own adapter when no pipeline node reaches the source: a protocol OctoMesh has no node for, a source that only answers inside a plant network, or logic that has to run next to a device. An adapter is a .NET program built with the OctoMesh SDK. It registers its nodes (triggers, transformations) at the tenant and runs the pipelines that are assigned to it.
The repository meshmakers/octo-adapter-demos contains two small adapters, each with a demo trigger node (it fires on a TCP message) and a demo transformation node:
AdapterEdgeDemo | AdapterMeshDemo | |
|---|---|---|
| Kind | Plug: active, connects out | Socket: passive, runs as a web host |
| Runs | At the edge (on a device) or in the cloud | In the cloud only |
| Connection | Through the event hub (RabbitMQ) | Directly to the repositories |
| Target | .NET 10 or .NET Framework 4.8 | .NET 10 |
| SDK package | Meshmakers.Octo.Sdk.Common | Meshmakers.Octo.Sdk.MeshAdapter and Meshmakers.Octo.Sdk.Common.Web |
Choose an edge adapter if the source is far from the cloud or must keep working through short outages; choose a
mesh adapter if the source is reachable from the cloud and you need bandwidth. Both kinds are registered the same
way: you create an adapter entity of the type System.Communication/Adapter in the tenant, give the process its
tenant id and the runtime id of that entity as environment variables (OCTO_ADAPTER__TENANTID,
OCTO_ADAPTER__ADAPTERRTID), start it, and GetAdapters shows it Online. Then you deploy a pipeline that uses
its nodes to that adapter. The repository README walks through build, start and a first pipeline, and the
developer guide explains how to
write your first Edge Adapter,
Mesh Adapter and
trigger node. Follow those; this tutorial does not copy them.
Typical pitfalls
- The archive is not activated. Writes fail. Run
ActivateArchiveonce after importing the archive. - The pipeline never runs. The data flow is not deployed (
DeployDataFlow) or the trigger is not deployed (DeployTriggers), or the trigger is disabled. - Attribute not found. In
attributeNameuse the camelCase name of the CK attribute (temperature), not the id (Temperature). - A fixed
rtIdthat does not exist. AnUpdateof an entity that was never imported changes nothing; import the station first. - Empty answers pass unnoticed. See the operating hints: check the last data timestamp, not only the status.
Summary
- Choose the pattern by who can start the connection: the source (push), OctoMesh (scheduled pull), a person (file) or a program next to the source (adapter).
- A scheduled pull is a pipeline with
FromPipelineTriggerEvent@1, aPipelineTriggerwith a cron expression and a data flow that is deployed. CreateUpdateInfo@1,SaveStreamDataInArchive@1andApplyChanges@2turn one answer into an entity update, a time series point and the latest value on the entity.- Watch the last data timestamp and keep secrets in configuration, never in the pipeline.
- When no node reaches the source, build an adapter from the demos in
octo-adapter-demos.
Next: Data model with an AI assistant or back to tutorial 6.