Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(blueprint): add generic DIO/relay for Welotec Arrakis #312

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions generic_io/dio/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Generic DIO/relay for Welotec Arrakis MK series

This [Enapter Device Blueprint](https://go.enapter.com/marketplace-readme) implements generic functions of digital input/output interface on industrial computer Arrakis MK series.

## Connect to Enapter

- Sign up to the Enapter Cloud using the [Web](https://cloud.enapter.com/) or mobile app ([iOS](https://apps.apple.com/app/id1388329910), [Android](https://play.google.com/store/apps/details?id=com.enapter&hl=en)).
- Use [Enapter Gateway](https://go.enapter.com/handbook-gateway-setup) to run Virtual UCM.
- Create [Enapter Virtual UCM](https://go.enapter.com/handbook-vucm).
- [Upload](https://go.enapter.com/developers-upload-blueprint) this blueprint to Enapter Virtual UCM.

## References

- [Arrakis MK4 IPC](https://www.welotec.com/product/fanless-industrial-computer-arrakis-mk4-series/)

- [DIO Enapter Lua API](https://go.enapter.com/dio-lua-api)
65 changes: 65 additions & 0 deletions generic_io/dio/firmware.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
-- Lua script implements device interface declared in the manifest file
-- using Lua programming language.
--
-- See https://developers.enapter.com/docs/reference/vucm/enapter

local arg_required_number_err_msg = 'arg is required and must be a number'

function main()
enapter.register_command_handler('close', command_close)
enapter.register_command_handler('open', command_open)

scheduler.add(30000, send_properties)
scheduler.add(1000, send_telemetry)
end

function send_properties()
enapter.send_properties({ vendor = 'Welotec', model = 'Arrakis MK series' })
end

function send_telemetry()
local telemetry = {}
local status = 'ok'

for input = 1, 4 do
local state, res = dio.input(input)
if res and res ~= 0 then
status = 'error'
enapter.log(
'failed to get state for input' .. input .. ' ' .. dio.err_to_str(res),
'error'
)
else
telemetry['di' .. input ] = (state == dio.HIGH)
end
end

telemetry['status'] = status
enapter.send_telemetry(telemetry)
end

function command_open(ctx, args)
if not args.output or type(args.output) ~= 'number' then
ctx.error('output ' .. arg_required_number_err_msg)
end

local state, res = dio.output(math.tointeger(args.output), dio.LOW)
if res and res ~= 0 then
ctx.error(dio.err_to_str(res))
end
return { level = state }
end

function command_close(ctx, args)
if not args.output or type(args.output) ~= 'number' then
ctx.error('output ' .. arg_required_number_err_msg)
end

local state, res = dio.output(math.tointeger(args.output), dio.HIGH)
if res and res ~= 0 then
ctx.error(dio.err_to_str(res))
end
return { level = state }
end

main()
83 changes: 83 additions & 0 deletions generic_io/dio/manifest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
blueprint_spec: device/1.0

display_name: Generic DIO for Arrakis MK4
description: Generic digital DIO/relay for controlling Arrakis MK4 DIOs.
icon: enapter-module-din-2
vendor: enapter
author: enapter
contributors:
- anataty
support:
url: https://go.enapter.com/enapter-blueprint-support
email: [email protected]
license: MIT

communication_module:
product: ENP-VIRTUAL
lua_file: firmware.lua

properties:
vendor:
type: string
display_name: Vendor
model:
type: string
display_name: Model

telemetry:
status:
display_name: Status
type: string
enum:
- error
- ok
di1:
display_name: DI1 is closed
type: boolean
di2:
display_name: DI2 is closed
type: boolean
di3:
display_name: DI3 is closed
type: boolean
di4:
display_name: DI4 is closed
type: boolean

command_groups:
control:
display_name: Control

commands:
close:
display_name: Close relay
group: control
ui:
icon: clock-in
arguments:
output:
display_name: Output Number
type: integer
enum:
- 1
- 2
- 3
- 4
open:
display_name: Open relay
group: control
ui:
icon: clock-out
arguments:
output:
display_name: Output Number
type: integer
enum:
- 1
- 2
- 3
- 4

.cloud:
category: communication_modules
mqtt_channel_id: gio
Loading