콘텐츠로 이동
공식 웹사이트로 돌아가기

트리거 구성

스크립트 문법은 Lua입니다. 트리거 구성의 전체 개념(조건/동작 유형)은 트리거 구성을 먼저 읽으세요. 이 페이지는 EXPRESSION 유형 트리거 동작 스크립트의 쓰기 매개변수, 반환 구조 및 전체 예제를 자세히 설명합니다.

  1. 트리거 로직은 다른 유형의 구성과 같으며 트리거 동작의 스크립트 내용만 다릅니다.
  2. 스크립트 실행이 완료되면 Edge-EMS Builder 백엔드는 반환 결과를 파싱하고 그 내용에 따라 지정 데이터 포인트에 씁니다.

참고: 프로그래밍 기초와 전략 실행 절차에 대한 이해가 필요합니다. 스크립트 문법은 Lua 엔진 규칙을 참조하세요.

매개변수 이름 값 필수 여부 유형 설명
dataType Customization 예 String 작업할 데이터 유형: Customization/Collection/Aggregation/Alarm/Share
deviceCode DeviceA 아니요 String 종속 장치 코드
dataKey 功率 예 String 데이터 고유 dataKey 또는 알람 유형
dataValue 15 예 String 데이터 값 또는 알람 내용
changeMod true 아니요 String 변경 시에만 쓰기 활성화 여부
availableDate 2023-01-15T07:00:00+08:00 아니요 String 유효 시작 날짜(Customization)
expiredDate 2023-01-15T10:00:00+08:00 아니요 String 만료 날짜(Customization)
mqttConnectionConfigId 100101 아니요 String MQTT 연결 설정 ID(Alarm)
topic upload 아니요 String 알람 업로드 Topic(Alarm)
qos 1 아니요 String QOS(Alarm)

시간대별 데이터(Customization)는 매일 반복(DailyRepeat) 일정 유형도 지원합니다. availableDate/expiredDate 대신 availableTime/expiredTime(형식 HH:mm:ss, 자정을 넘을 수 없음)를 사용하여 매일 반복 적용합니다. 축약 함수 buildCustomizationWriteMap(dataKey, dataValue, availableDate, expiredDate)(DailyChange 전용) 또는 buildDailyRepeatWriteMap(dataKey, dataValue, availableTime, expiredTime)(DailyRepeat 전용)를 직접 사용할 수 있습니다. Lua 엔진 규칙을 참조하세요.

스크립트에서 참조한 데이터 포인트의 값을 가져올 수 없으면 __Null__ 센티널 문자열이 주입됩니다. 빈 문자열이나 nil라고 가정하지 말고 ${dataKey} == "__Null__"를 명시적으로 판단하세요.

local resultList = {}
-- 사용자 정의 알람 내용
local errorMap = {}
errorMap.timestamp = OffsetDateTime.now():unixMilli()
errorMap.iotCode = ${数据9}
errorMap.faultCode = ${数据9}
errorMap.faultLevel = ${数据9}
errorMap.faultName = ${数据9}
errorMap.faultBack = ${数据9}
-- 알람 내용을 JSON으로 변환
local errorMessage = toJsonString(errorMap)
table.insert(resultList, buildCommonWriteMap("Customization", "mode", 15, "2023-01-15T07:00:00+08:00", "2023-01-15T10:00:00+08:00", true))
table.insert(resultList, buildCommonAlarmMap("二级告警", "二级告警"))
table.insert(resultList, buildMqttAlarmMap("一级告警", errorMessage, 1, "upload", 1))
table.insert(resultList, buildCommonWriteMap("Collection", "数据10", 200, nil, nil, true))
table.insert(resultList, buildCommonWriteMap("Aggregation", "温度", 20, nil, nil, false))
table.insert(resultList, buildSlaveWriteMap("DeviceB", "Share", "数据3", 888, nil, nil, false))
return resultList

여러 Table을 포함하는 배열을 반환해야 합니다. Edge-EMS Builder는 배열을 파싱하고 객체 내용의 유효성을 검증한 후 구성된 쓰기 객체를 반환합니다.

[
{
"dataType": "",//작업 대상
"deviceCode": "",//슬레이브 장치의 고유 코드(이 값으로 데이터를 쓸 슬레이브 장치를 결정)
"dataKey": "",//작업 대상의 고유 KEY(dataKey 또는 alarmType)
"dataValue": "",//쓸 내용 또는 알람 내용
"changeMod": true,//값이 변경될 때만 쓸지 여부
"availableDate": "",//시간대별 데이터의 적용 시작 시간
"expiredDate": ""//시간대별 데이터의 만료 시간
}
]

실행 결과를 파싱하고 내용의 정확성을 검증한 후 실행 전 구성 객체를 반환합니다.

{
"writeCommBridgeContent": [
{
"dataKey": "数据10",
"dataValue": "200"
}
],
"writeAggregationDataConfigs": [
{
"aggregationDataConfigId": 100004,
"dataKey": "温度",
"dataName": "温度",
"collectionCycle": -1,
"expression": "return 15",
"status": "Valid",
"empty": false,
"hasGroup": false,
"useLatestValue": true,
"note": "",
"createdBy": 100001,
"createdTime": "2025-03-18T15:04:39.503+08:00",
"updatedBy": 100001,
"updatedTime": "2025-03-28T10:21:15.578+08:00"
}
],
"writeAggregationDataValues": [
{
"aggregationDataConfigId": 100004,
"dataValue": "20",
"collectionTime": "2025-04-23T15:30:49.913+08:00"
}
],
"writeCustomizationDataValues": [
{
"customizationDataConfigId": 100003,
"dataValue": "15",
"availableDate": "2023-01-15T07:00:00.000+08:00",
"expiredDate": "2023-01-15T10:00:00.000+08:00",
"createdBy": 100000,
"createdTime": "2025-04-23T15:30:49.912+08:00"
}
],
"writeShareDataValues": [
{
"shareDataConfigId": 3,
"deviceCode": "DeviceB",
"dataKey": "数据3",
"collectionCycle": 3000,
"dataValue": "888",
"collectionTime": "2025-04-23T15:30:49.914+08:00"
}
],
"alarmRecords": [
{
"alarmType": "二级告警",
"alarmContent": "二级告警",
"alarmTime": "2025-04-23T15:30:49.912+08:00",
"mark": "None"
},
{
"alarmType": "一级告警",
"alarmContent": "{\"iotCode\":66.60000000,\"faultCode\":66.60000000,\"faultBack\":66.60000000,\"faultLevel\":66.60000000,\"timestamp\":1745393449910,\"faultName\":66.60000000}",
"alarmTime": "2025-04-23T15:30:49.912+08:00",
"mark": "None",
"mqttConnectionConfigId": 1,
"topic": "upload",
"qos": 1
}
]
}

image-20250415172946412

  • 트리거 구성의 전체 개념(조건 유형, 동작 유형, 동적 장치 검색 예제): 트리거 구성
  • 전체 Lua 내장 함수 및 모듈 참조: Lua 엔진 규칙