CLI Apply HAT Types
HAT types appear in a dropdown when creating or editing device records via the web ui. For new deployments with known equipment, the CLI makes it possible to seed this data from files.
Curate your assets
Using a directory managed by version control such as git, lay out a directory structure containing YAML or JSON assets. Any depth of folder hierarchy is supported.
my-hat-types/
Argon40/
FanHat.yaml
Seeed
UpsWithRtcCoulometer.yaml
SixFab/
UpsHat.yaml
The JSON layout of a HAT type can be scraped via the web browser's JavaScript console, or this example can be used:
# my-hat-types/SixFab/UpsHat.yaml
id: c22b9mqo5ld9h3po1jcg
kind: HatType
manufacturer: Sixfab
model: Power Management & UPS HAT for Raspberry Pi
partNumber: "62915"
url: "https://sixfab.com/power/"
Importing
Leave off the --dry-run
flag to perform an actual import.
$ onprem apply --dry-run ./my-hat-types/
Writing a device driver for fan control
Alongside the HAT definition, you might also want to define lambdas specific to the hardware. This example shows how the On Prem platform defines the lambda that performs fan control for Argon 40 Fan HATs.
The lambda is triggered by the On Prem Service Broker Toolkit trigger event clqr195uc97nh8rtn1d0
, which is
invoked whenever the On Prem Agent needs to drive a fan to reconcile a Fan Profile "desired state"
with a fan speed "actual state". Operators are free to define their own custom Lamba Triggers; this just
happens to be one that is built into the agent and available to all deployments.
Directory structure:
my-hat-types/ ⌞ Argon40/ FanHat.yaml argon40_fan_control.yaml argon40_fan_control.lua
$ onprem generate xid
clqejgco47mll531pr1g
# argon40_fan_control.yaml
id: clqejgco47mll531pr1g
kind: Lambda
triggerTypeId: clqr195uc97nh8rtn1d0
name: argon40_fan_control
description: >
Drive the fan on an Argon Fan HAT.
runAt:
allDevices: true
scriptContentType: text/x-lua
script: "@argon40_fan_control.lua"
-- argon40_fan_control.lua
local I2C = require('periphery.I2C')
local M = {}
function M.handler(event, context)
if event.hatTypeId == 'c5d549vqrh9ga1fc4ddg' then
local i2c = I2C('/dev/i2c-1')
local message = { event.speed }
return i2c:transfer(0x1a, { message })
end
end
return M