EdgeRSU 상태정보 (수집)
EdgeRSU 장비에서 상태정보를 수집하여 플랫폼 내에 적재하는 기능을 제공합니다.
1. EdgeRSU 상태정보 수집 (PostEdgeRSUStatusInfo)
요청 URL
https://service.mqnicrnd5.com/api/v1/esi/collect/pesi
연계 주기
일정 주기 마다 (추후 안내 예정), 변경 발생 시
프로토콜
HTTPS
HTTP 메서드
POST
데이터 포맷
참고사항
API를 요청할 때 다음 예와 같이 HTTP 요청 헤더에 접근 토큰(Access Token) 을 추가해야 합니다. 접근 토큰 앞에 "Bearer " 문자열을 추가해야 한다는 점에 주의하세요.
> POST /api/v1/esi/collect/pesi
> Host: service.mqnicrnd5.com
> User-Agent: curl/7.64.1
> Accept: */*
> Authorization: Bearer <접근 토큰>
요청 예시
curl --location 'https://service.mqnicrnd5.com/api/v1/esi/collect/pesi' \
--header 'Authorization: Bearer <접근 토큰>' \
--header 'Content-Type: application/json' \
--data '[
{
"edgeRsuId": "RSU00001",
"csn": {
"sensorType": "AL",
"sensorNo": "01"
},
"opCode": "test",
"data": [
{
"timestamp": 0,
"powerCtrlPortStat": "1",
"fanCtrlPortStat": "1",
"heaterCtrlPortStat": "1",
"doorStat": "0",
"sensorStat": "1",
"tp": "",
"hd": "",
"cds": "",
"vsbl": "",
"cntlrResetBttonCtrlCnt": "",
"cntlrPowerBttonCtrlCnt": "",
"extrlADCMeas": ""
}
]
}
]'
응답 파라미터
수집 API의 경우 별도 응답 파라미터가 아닌 HTTP Status Code로 성공 여부를 구분합니다.
Status Code
설명
200
성공
400
요청 파라미터 검증 실패
401
인증 실패
500
서버 오류
{
id: '7a02096f-5d6c-4057-8cc7-1f0b2e8eaaa1',
status: 'OK',
code: 200,
header:
[ { key: 'Date', value: 'Tue, 26 Mar 2024 07:49:01 GMT' },
{ key: 'Content-Type', value: 'text/plain;charset=ISO-8859-1' },
{ key: 'Content-Length', value: '2' },
{ key: 'Connection', value: 'keep-alive' },
{ key: 'x-envoy-upstream-service-time', value: '15' },
{ key: 'server', value: 'istio-envoy' },
{ key: 'cache-control',
value: 'no-cache, no-store, max-age=0, must-revalidate' },
{ key: 'pragma', value: 'no-cache' },
{ key: 'expires', value: '0' },
{ key: 'x-content-type-options', value: 'nosniff' },
{ key: 'x-frame-options', value: 'DENY' },
{ key: 'x-xss-protection', value: '0' },
{ key: 'referrer-policy', value: 'no-referrer' } ],
stream: { type: 'Buffer', data: [ 79, 75 ] },
cookie: [],
responseTime: 26,
responseSize: 2
}
2. EdgeRSU 상태정보 수집 API 구현 예제
다음은 각 언어별 EdgeRSU 상태정보 수집 API 구현 예제입니다.
EdgeRSU 상태정보 수집 (PostEdgeRSUStatusInfo)
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import org.json.JSONObject; // JSON 라이브러리 추가 필요
public class CallAPI {
public static void main(String[] args) {
String accessToken = "Bearer <접근 토큰>"; // 실제 접근 토큰으로 교체 필요
// 최상위 JSONArray 생성
JSONArray jsonArray = new JSONArray();
// JSON 객체 생성
JSONObject jsonObject = new JSONObject();
jsonObject.put("edgeRsuId", "RSU00006");
// 'csn' JSON 객체 생성 및 삽입
JSONObject csn = new JSONObject();
csn.put("sensorType", "AC");
csn.put("sensorNo", "SN-246");
jsonObject.put("csn", csn);
// 'opCode' 삽입
jsonObject.put("opCode", "OP-50");
// 'data' JSONArray 생성 및 삽입
JSONArray data = new JSONArray();
// 데이터 샘플들을 JSONArray 'data'에 삽입
data.put(new JSONObject()
.put("timestamp", 1710915990965L)
.put("powerCtrlPortStat", "1")
.put("fanCtrlPortStat", "1")
.put("heaterCtrlPortStat", "1")
.put("doorStat", "1")
.put("sensorStat", "1")
.put("tp", 8.902050926905144)
.put("hd", 7.865384655529095)
.put("cds", JSONObject.NULL)
.put("vsbl", JSONObject.NULL)
.put("cntlrResetBttonCtrlCnt", JSONObject.NULL)
.put("cntlrPowerBttonCtrlCnt", JSONObject.NULL)
.put("extrlADCMeas", JSONObject.NULL));
// 위와 같이 data JSONArray에 다른 데이터 객체들도 추가
jsonObject.put("data", data);
jsonArray.put(jsonObject);
String apiURL = "https://service.mqnicrnd5.com/api/v1/esi/collect/pesi"; // POST 요청 URL
String responseBody = post(apiURL, jsonArray.toString(), accessToken);
System.out.println(responseBody);
}
private static String post(String apiUrl, String jsonInputString, String accessToken) {
HttpURLConnection con = connect(apiUrl);
try {
con.setRequestMethod("POST");
con.setRequestProperty("Authorization", accessToken);
con.setRequestProperty("Content-Type", "application/json; utf-8");
con.setRequestProperty("Accept", "application/json");
con.setDoOutput(true);
try(OutputStream os = con.getOutputStream()) {
byte[] input = jsonInputString.getBytes(StandardCharsets.UTF_8);
os.write(input, 0, input.length);
}
int responseCode = con.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) { // 정상 호출
return readBody(con.getInputStream());
} else { // 오류 발생
return readBody(con.getErrorStream());
}
} catch (IOException e) {
throw new RuntimeException("API 호출 중 오류 발생: ", e);
} finally {
con.disconnect();
}
}
private static HttpURLConnection connect(String apiUrl) {
try {
URL url = new URL(apiUrl);
return (HttpURLConnection) url.openConnection();
} catch (MalformedURLException e) {
throw new RuntimeException("API URL이 잘못되었습니다. : " + apiUrl, e);
} catch (IOException e) {
throw new RuntimeException("연결이 실패했습니다. : " + apiUrl, e);
}
}
private static String readBody(InputStream body) {
InputStreamReader streamReader = new InputStreamReader(body);
try (BufferedReader lineReader = new BufferedReader(streamReader)) {
StringBuilder responseBody = new StringBuilder();
String line;
while ((line = lineReader.readLine()) != null) {
responseBody.append(line);
}
return responseBody.toString();
} catch (IOException e) {
throw new RuntimeException("API 응답을 읽는 데 실패했습니다.", e);
}
}
}
Last updated