Skip to main content

Develop a provider

A provider is a service that speaks to devices over some protocol, and speaks to BeaconTower over NATS. It is the one component you add to a tenant rather than replace in it. Everything else in a tenant is supplied; a provider is what a customer writes.

Start one​

btk3s provider new acme-http

That writes a project that compiles and connects, and adds it to btk3s.yaml. Use --dir to put it somewhere other than the current directory.

It also downloads BeaconTower.ProviderSdk and the packages it depends on into packages/ in the project. With the btk3s binary, the output says otherwise:

    packages/: empty - BeaconTower.* resolves from the private feed
...
ProviderSdk 3.9.3, from the private feed (no bundle here)

Both lines are worked out before the download runs. Ignore them. The private feed is BeaconTower's own GitHub Packages feed, and you do not need access to it. Check that the packages arrived instead:

ls acme-http/packages/*.nupkg

It should include beacontower.providersdk.3.9.3.nupkg. If the output also had a line starting note: no vendored packages, the download failed; run btk3s provider fetch acme-http and check again.

Your protocol goes in src/AcmeHttpAdapter.cs, and, for a protocol that arrives over HTTP, in the endpoints in src/Program.cs. The SDK owns NATS, provisioning, the twin and the telemetry pipeline. The TODOs mark what to fill in. As generated, Program.cs serves only GET /health: the project connects to the tenant, but a device has nothing to talk to until you add your protocol.

What your adapter has to do​

An adapter works in two directions. Both have to be implemented.

Devices talk to you. Whatever arrives on your wire goes into the SDK through Telemetry.SendAsync — a reading, or the same call with IsReportedProperties = true for a twin update.

You talk to devices. SendCommandAsync and SendDesiredPropertiesAsync have to reach a device that is idle. If your transport cannot do that, set SupportsCommands = false. Every command the platform sends then returns "not supported", and desired properties never arrive.

A working pair is in beacontower/tools: an HTTP provider and a device simulator that talks to it. The adapter is about two hundred lines, and is worth reading alongside this page.

The loop​

btk3s provider dev acme-http

Leave it running and press F5. The provider runs on your machine against the tenant's NATS, so breakpoints work the way they do in any local project — there is no debugger to install and no image to rebuild between changes.

Without an editor, one command does both:

btk3s provider run acme-http

Ctrl-C releases the provider and puts the cluster copy back.

dev stops the deployed copy while you work. Two of them would share a NATS queue group, so half your device traffic would go to the pod and half to your laptop, intermittently. --no-stop overrides this.

provider dev, run and deploy are the part of btk3s that runs on your machine rather than in its container. They build and run with your own docker, buildx and .NET SDK, and they also need jq, curl, and python3 with PyYAML on your PATH, plus helm and flux for deploy. btk3s doctor warns about any of these it cannot find.

Connect a device​

btpy simulates an MQTT device. Use it only when you are writing an MQTT provider. It publishes to the broker, and only provider-mqtt subscribes there, so pointing it at a provider that speaks another protocol registers the device but delivers no telemetry.

For an HTTP provider, use the simulator that speaks HTTP. It needs a provider that speaks its protocol, and the generated project does not: it has no /api/devices/{id}/register, /telemetry or /properties endpoints and makes no webhook calls. To try the simulator before you have written your own, turn your project into the working pair by copying the two provider files from beacontower/tools over the generated ones. They use the same namespace and class names:

for f in Program.cs AcmeHttpAdapter.cs; do
curl -fsSLo acme-http/src/$f \
https://raw.githubusercontent.com/beacontower/tools/main/acme-http/provider/$f
done
btk3s provider run acme-http

Leave that running in its own terminal while you provision the device and run the simulator. Provisioning goes through the running provider, and with it stopped, the provision call below fails with a bare HTTP 500.

Then get the simulator from its release, or build it from source. The assets are acme-http-device-linux-x64, acme-http-device-linux-arm64, acme-http-device-osx-x64, acme-http-device-osx-arm64 and acme-http-device-win-x64.exe. On Linux x64:

curl -fLO https://github.com/beacontower/tools/releases/download/acme-http-device-v0.1.0/acme-http-device-linux-x64
chmod +x acme-http-device-linux-x64
./acme-http-device-linux-x64 -provider http://localhost:5000 -id acme-01

The project listens on http://localhost:5000. The simulator defaults to :5080, so pass -provider, or start the provider with ASPNETCORE_URLS=http://localhost:5080.

It POSTs telemetry and reported properties up, and serves a webhook so the platform can push commands and desired properties back down.

Provision the device before you start it. A device that reports properties before it has been provisioned cannot then be provisioned: the SDK creates a twin for the unknown device, and provisioning afterwards fails on a duplicate key, permanently, for that device id. The recovery is a new device id.

btk3s api -X POST /providers/acme-http/clients \
-d '{"id":"acme-01","displayName":"acme-01","enabled":true,"organizationId":"<org>"}'
btk3s api -X POST /providers/acme-http/clients/acme-01/provision -d '{"options":{}}'

Create an asset for it​

A provider client on its own is not visible anywhere. The web client, the asset APIs and SignalR all work on assets, so until an asset is bound to your provider client there is nothing to open and nothing to subscribe to. The data reaches the device twin and stops there.

Three steps: a model describing what the device sends, an asset built from it, and a binding to the provider client.

The model's content names are the contract. A telemetry key your device sends that is not on the model is dropped silently, so celsius here matches the payload the simulator posts. Note the version: the minor must be present and non-zero, ;1.1 rather than ;1 or ;1.0, or the model is rejected with an empty 400.

// model.json
{
"id": "dtmi:acme_http_device;1.1",
"displayName": "Acme HTTP device",
"organizationId": "<org>",
"modelData": [{
"@id": "dtmi:acme_http_device;1.1",
"@context": ["dtmi:dtdl:context;3", "dtmi:bt:extension:metaProperty;1",
"dtmi:dtdl:extension:quantitativeTypes;1"],
"@type": "Interface",
"displayName": "Acme HTTP device",
"contents": [
{"@id": "dtmi:acme_http_device:_c:celsius;1.1", "@type": "Telemetry",
"name": "celsius", "displayName": "celsius", "schema": "double"},
{"@id": "dtmi:acme_http_device:_c:firmware;1.1", "@type": "Property",
"name": "firmware", "displayName": "firmware", "schema": "string"},
{"@id": "dtmi:acme_http_device:_c:reportInterval;1.1", "@type": "Property",
"name": "reportInterval", "displayName": "reportInterval",
"schema": "integer", "writable": true}
]
}]
}

writable: true is what makes a property settable as a desired property.

btk3s api -X POST /models -d @model.json

btk3s api -X POST /assets \
-d '{"id":"acme-01","displayName":"Acme HTTP device 01",
"modelId":"dtmi:acme_http_device;1.1","organizationId":"<org>"}'

btk3s api -X POST /assets/acme-01/bind \
-d '{"autobindRemoteInstanceIds":["acme-http::acme-01"]}'

The bind is by name: every content on the model is matched to the like-named signal on the provider client, and the response lists what it paired. An empty endpointBindResults means nothing bound — check the names against the model.

Now start the device.

Watch it in the web client​

Open the tenant and find asset acme-01. Its readings are on the asset's chart. The web client is the normal way to check this.

The same things through the asset API, which is what the UI calls:

btk3s api /assets/acme-01/properties/reported
btk3s api -X PUT /assets/acme-01/properties/desired -d '{"reportInterval":45}'

Setting a desired property travels platform -> NATS -> your adapter -> the device's webhook. The device applies it and reports it back, and the reported properties then show the new value. That round trip, not the 200, is how you know a setting took.

Commands go through the provider client:

btk3s api -X POST /providers/acme-http/clients/acme-01/directmethod \
-d '{"method":"ping"}'

The simulator answers Ok to ping and reboot, and DeviceError to anything else. That is what a device should do with a command it does not know: the platform then sees 400 rather than a false success.

Deploy it to the cluster​

btk3s provider deploy acme-http

Builds the image, publishes the chart, waits, and prints the image it is running. Re-run it after any change to the code or the chart.

btk3s provider status              # who is serving each provider
btk3s provider logs acme-http -f
btk3s provider stop acme-http # still deployed, serving nothing
btk3s provider start acme-http
btk3s provider rm acme-http # out of the cluster and out of btk3s.yaml

When it does not work​

Work down this list; each step rules out a layer.

Is anything serving it?

btk3s provider status

local and cluster at once is impossible by construction, but - means nothing is running at all.

Just registered it, and the API says it does not exist? provider dev and provider deploy create the provider in core, but the authorization relations behind it settle a moment later. Until they do, GET /providers/<name> answers 404 while GET /providers still lists it. It clears within about a minute — retry before believing the 404.

Is the tenant healthy?

btk3s doctor

If the broker's certificate or the tenant's credentials are wrong, every provider looks broken in the same way. Rule that out before reading your code.

Did the message become telemetry? A payload the provider accepts is still dropped, silently, when its keys are not telemetry channels on the asset's model, or when the asset's channels are not bound to the device:

btk3s doctor          # the Assets section names unbound channels
btk3s repair # binds them

The same is true of the parser. Your provider template selects one, and a payload the parser does not understand is consumed and dropped whole. Not even celsius arrives, and nothing is logged. provider dev --parser <name> sets it. The default jemacTest matches the seeded dtmi:jemac;4.4 model and expects JEMAC telegrams; for flat JSON, use anything that is not jemacTest, jemacTest2 or iqrTest and the default JSON parser takes it, deriving the signal name from each payload key.

Did you change the provider template? A device provisioned before the change keeps the old one:

btk3s btpy device reprovision -d dev-01

Check this first when telemetry stops after a template change.

What btk3s owns​

It registers your provider and its template, publishes your chart, installs it, and builds your image.

Routing targets and enrollment groups are yours. They are choices about how devices onboard. Your chart's values pass through untouched — whether it uses a plain Secret or an ExternalSecret is your decision, and anything your provider needs must be in the chart, because btk3s treats it as opaque.

What a provider must implement is the SDK's own documentation.


Advanced

The commands above each do several things. This section describes what, for when you need to work around one of them.

The equivalent commands​

btk3sunderneath
provider deploy Xdocker build, push to localhost:31500/btk3s-X:dev, helm package, helm push, then a Flux reconcile
provider stop Xflux -n btk3s suspend helmrelease X then kubectl -n btk3s scale deploy/X --replicas=0
provider logs Xkubectl -n btk3s logs <newest pod by selector>
provider statuskubectl -n btk3s get deploy,helmrelease
provider dev Xkubectl -n btk3s port-forward svc/nats 4222:4222, a local postgres container, and a .env

provider stop suspends before it scales, because providers live in their own btk3s-providers Kustomization. provider logs resolves a pod by name rather than using deploy/X, which picks one pod of the set and can stream the old one during a rollout.

What the scaffold wrote​

  • src/*.csproj — net10.0 and one PackageReference to BeaconTower.ProviderSdk, at the version upstream.lock pins. Microsoft.NET.Sdk.Web, because the SDK declares a framework reference on Microsoft.AspNetCore.App.
  • nuget.config — maps BeaconTower.* to the packages/ directory beside the project AND to the private feed. provider new fills packages/ from the published release of the SDK version upstream.lock pins, so the project restores without contacting the feed; if that download failed, run btk3s provider fetch <name> to fill it.
  • .env — written by provider dev, gitignored, and holding secrets. The values are environment variables rather than appsettings placeholders because ASP.NET Core does not expand ${VAR} inside a JSON config file.
  • chart/values.yaml — pullPolicy: Always is not optional. The tag stays :dev across rebuilds, so IfNotPresent keeps serving the cached copy and your rebuild appears to do nothing.
  • chart/templates/postgres.yaml — a development database. The SDK keeps devices, credentials and twin state there and bootstraps the schema itself with dbup, so an empty one is enough; without it the provider stops at "ConnectionStrings:beacontower-providerdb is not configured". Its data lives in an emptyDir and goes with the pod. Set database.embedded: false and fill in database.connectionString for anything you care about. It runs as its own user, which owns what the migrations create. A provider built against an SDK before 3.9.3 had to run as the postgres superuser, because the first migration granted to that hardcoded role and died with 42704: role "postgres" does not exist without it.
  • The deployment sets Nats__Url and ASPNETCORE_ENVIRONMENT. The SDK's NATS default is localhost:4222, which is right for provider dev on your machine and wrong in a pod. Since SDK 3.9.3 a loopback URL fails at start in a pod, naming Nats__Url, rather than connecting to nothing and receiving no work in silence. Development is required because the SDK refuses an unauthenticated NATS connection in any other environment, and a local tenant's NATS has no credentials; a tenant whose NATS has them sets environment: Production and supplies Nats__User and Nats__Password.
  • The connection string is named beacontower-providerdb, the SDK's default since 3.9. Override it with ProviderSdk__ConnectionStringName if your host already has one. A provider written against an older SDK used beacontower-mqttproviderdb, which still works.

Registering by hand​

provider dev and provider deploy do this for you. The full chain, of which btk3s creates the first two:

core       POST /api/v1/providers          id = your provider id, type = its kind ("mqtt", "iothub", "http")
core POST /api/v1/providerTemplates options.tags.parser selects the parser
onboarding POST /api/v1/routing-targets NATS -> the provider
onboarding POST /api/v1/enrollment-groups references the template + routing target

btk3s api -X POST /providers -d '{...}' makes the calls as the default user. seed/setup-fixtures.sh scripts all four, idempotently, for the built-in mqtt provider.

Debugging the deployed copy​

Local development covers almost everything, but a failure that only happens in the cluster needs a debugger in the pod. Build a debug image — derive from your normal build stage and publish with -c Debug so symbols survive — install vsdbg into it, and attach over kubectl exec with a pipeTransport launch configuration. The pod selector is whatever your chart sets; the scaffold's is app=<name>.

Next​

  • Drive devices — the tiers, and what each one authenticates with.