IOTOWN은 타 시스템에서 연동하기 위하여 RESTful API를 제공합니다.
API를 사용하려면 토큰이 필요하며 IOTOWN에 로그인 후 Open API 토큰 메뉴에서 얻을 수 있습니다.
Admin계정의 토큰을 사용하면 API를 사용할 때 모든 그룹에 대한 접근이 가능합니다. Admin계정으로 로그인하면 Open API 토큰 메뉴에서 토큰을 얻을 수 있습니다.
Admin토큰을 사용하려면 API호출시 header에 접근하고자 하는 그룹의 ID(grpid)를 넣어야 합니다.
| key | value |
|---|---|
| Content-Type | application/json |
| Accept | application/json |
| Token | {your_own_token} |
| grpid (Admin token only) | {group_id_to_access} |
HTTP request에 대한 response code가 200인 경우 성공을 의미합니다.
반면, 200이 아닌 경우 오류로 인해 정상 처리되지 않았음을 의미합니다.
Status code와 더불어 모든 response는 JSON 포맷의 payload가 반환되며,
여기에는
{
"errorCode": 200,
"errorMsg": "OK"
}
| Response code | Description |
|---|---|
| 200 | 성공 |
| 400 | Bad Request |
| 401 | Invalid Token |
| 500 | 서버에 문제가 발생했거나 처리가 불가능한 요청인 경우 |
이 API를 통해서 IOTOWN과 연동된 게이트웨이 목록을 가져올 수 있습니다.
curl -X GET --header 'Accept: application/json' --header 'Token: your_own_token' 'https://town.coxlab.kr/api/v1.0/gateways'
Invoke-WebRequest -Method 'GET' -Headers @{'Accept'='application/json';'Token'='your_own_token'} -Uri https://town.coxlab.kr/api/v1.0/gateways
{
"gateways":[
{
"created_at":"2016-05-30T05:54:59.995Z",
"gateway_id":"GW002",
...
},
{
"created_at":"2016-05-30T05:27:14.808Z",
"gateway_id":"GW001",
...
}
...
],
"errorCode":200,
"errorMsg":"Success"
}
이 API를 통해서 IOTOWN과 연동된 특정 게이트웨이의 정보를 가져올 수 있습니다.
curl -X GET --header 'Accept: application/json' --header 'Token: your_own_token' 'https://town.coxlab.kr/api/v1.0/gateway/GW001'
Invoke-WebRequest Method 'GET' -Headers @{'Accept'='application/json';'Token'='your_own_token'} -Uri https://town.coxlab.kr/api/v1.0/gateway/GW001
{
"gateway":{
"bootup_time":"2016-06-01T07:03:21.445Z",
"created_at":"2016-05-30T05:27:14.808Z",
"gateway_desc":"GW001설명",
"gateway_id":"GW001"
"gateway_type":"GW001종류",
"gateway_eui":"AA555A0000000101",
"recent_act":"2016-06-04T02:11:16.902Z",
"latitude":"36.49197",
"longitude":"127.25633",
"altitude":"10.5"
},
"errorCode":200,
"errorMsg":"Success"
}
이 API를 통해서 IOTOWN에 게이트웨이를 등록할 수 있습니다.
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'Token: your_own_token' -d '{"gid":"G001","eui":"1111222233334444","type":"gateway type","desc":"gateway desc","lora":"KR920"}' 'https://town.coxlab.kr/api/v1.0/gateway'
Invoke-WebRequest -Method 'POST' -Headers @{'Content-Type'='application/json'; 'Accept'='application/json'; 'Token'='your_own_token'} -Body '{"gid":"G001","eui":"1111222233334444","type":"gateway type","desc":"gateway desc","lora":"KR920"}' -Uri https://town.coxlab.kr/api/v1.0/gateway
{
"errorCode":200,
"errorMsg":"Success"
}
이 API를 통해서 게이트웨이의 정보를 수정할 수 있습니다.
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'Token: your_own_token' -d '{"type":"gateway type","desc":"gateway desc"}' 'https://town.coxlab.kr/api/v1.0/gateway/G001'
Invoke-WebRequest -Method 'POST' -Headers @{'Content-Type'='application/json'; 'Accept'='application/json'; 'Token'='your_own_token'} -Body '{"type":"gateway type","desc":"gateway desc"}' -Uri https://town.coxlab.kr/api/v1.0/gateway/G001
{
"errorCode":200,
"errorMsg":"Success"
}
이 API를 통해서 IOTOWN에 등록된 게이트웨이를 삭제할 수 있습니다.
curl -X DELETE --header 'Content-Type: application/json' --header 'Accept: application/json' --header 'Token: your_own_token' -d '{"gid":"G001"}' 'https://town.coxlab.kr/api/v1.0/gateway'
Invoke-WebRequest -Method 'DELETE' -Headers @{'Content-Type'='application/json'; 'Accept'='application/json'; 'Token'='your_own_token'} -Body '{"gid":"G001"}' 'https://town.coxlab.kr/api/v1.0/gateway'
{
"errorCode":200,
"errorMsg":"Success"
}
이 API를 통해서 IOTOWN과 연동된 특정 게이트웨이의 하위 장치 목록을 가져올 수 있습니다.
curl -X GET --header 'Accept: application/json' --header 'Token: your_own_token' 'https://town.coxlab.kr/api/v1.0/gateway/G001/connected-nodes'
Invoke-WebRequest -Method 'GET' -Header @{'Accept'='application/json'; 'Token'='your_own_token'} -Uri 'https://town.coxlab.kr/api/v1.0/gateway/G001/connected-nodes'
{
"nodes" : [
{"node_id" : "N001"},
{"node_id" : "N002"},
...
],
"errorCode":200,
"errorMsg":"Success"
}
이 API를 통해서 IOTOWN과 연동된 특정 게이트웨이의 통계 정보를 가져올 수 있습니다.
curl -X GET --header 'Accept: application/json' --header 'Token: your_own_token' 'https://town.coxlab.kr/api/v1.0/gateway/G001/stats'
Invoke-WebRequest -Method 'GET' -Headers @{'Accept'='application/json'; 'Token'='your_own_token'} -Uri 'https://town.coxlab.kr/api/v1.0/gateway/G001/stats'
{
"stats" : [
{
"timestamp": "2019-01-01T12:00:00Z",
"rxPacketsReceived": 103,
"rxPacketsReceivedOK": 23,
"txPacketsReceived": 0,
"txPacketsEmitted": 0
}
...
],
"errorCode":200,
"errorMsg":"Success"
}
이 API를 통해서 IOTOWN에 등록된 장치 목록을 가져올 수 있습니다.
curl -X GET\ --header 'Accept: application/json'\ --header 'Token: your_own_token'\ 'https://town.coxlab.kr/api/v1.0/nodes'
{
"nodes" : [
{
"node_id":"N001",
"node_type":"N001종류",
"node_desc":"N001설명",
"created_at":"2016-05-27T08:13:31.633Z"
},
{
"node_id":"N002",
"node_type":"N002종류",
"node_desc":"N002설령",
"bootup_time":"2016-05-26T08:07:05.893Z",
"connected_gw_id":"GW001",
"created_at":"2016-05-27T08:13:31.633Z",
"last_data":{"CC":"33","BB":"11","AA":"00"},
"last_timestamp":"2016-05-30T07:50:10.848Z"
},
...
}
],
"errorCode":200,
"errorMsg":"Success"
}
이 API를 통해서 IOTOWN에 등록된 장치 정보를 가져올 수 있습니다.
curl -X GET\ --header 'Accept: application/json'\ --header 'Token: your_own_token'\ 'https://town.coxlab.kr/api/v1.0/node/N001'
{
"node": {
"node_id":"N001",
"node_type":"N001종류",
"node_desc":"N001설명",
"created_at":"2016-05-27T08:13:31.633Z",
"last_data":{
"A":"0",
"B":"1"
},
"last_timestamp":"2016-05-30T07:50:52.033Z"
},
"errorCode":200,
"errorMsg":"Success"
}
이 API를 통해서 IOTOWN에 장치를 등록할 수 있습니다.
curl -X POST\
--header 'Content-Type: application/json'\
--header 'Accept: application/json'\
--header 'Token: your_own_token'\
-d '{\
"nid":"LW1111222233334444",\
"type":"node type",\
"desc":"node desc",\
"lorawan": {\
"profile" : "KR920 1.0.2 A",\
"appKey" : "11112222333344445555666677778888"\
}\
}'\
'https://town.coxlab.kr/api/v1.0/node'
{
"errorCode":200,
"errorMsg":"Success"
}
이 API를 통해서 IOTOWN에 등록된 장치를 삭제할 수 있습니다.
curl -X DELETE\
--header 'Content-Type: application/json'\
--header 'Accept: application/json'\
--header 'Token: your_own_token'\
-d '{\
"nid":"LW1111222233334444"\
}'\
'https://town.coxlab.kr/api/v1.0/node'
{
"errorCode":200,
"errorMsg":"Success"
}
이 API를 통해서 IOTOWN에 저장된 데이터를 가져올 수 있습니다.
curl -X POST\
--header 'Content-Type: application/json'\
--header 'Accept: application/json'\
--header 'Token: your_own_token'\
-d '{\
"nid" : "N001",\
"from" : "2016-02-01T13:45+09:00",\
"to" : "2016-05-30T13:55+09:00"\
}'\
'https://town.coxlab.kr/api/v1.0/storage/search'
{
"data":[
{
"node_id":"N001",
"name":"B",
"value":"1",
"timestamp":"2016-02-30T07:50:52.033Z"
},
...
{
"node_id":"N001",
"name":"B",
"value":"1",
"timestamp":"2016-05-30T09:50:21.748Z"
}
],
"lastKey":"574bf0dbabe178ec1f776758",
"errorCode":200,
"errorMsg":"Success"
}
위의 예제처럼
{
"nid" : "001",
"from" : "2016-02-01T13:45+09:00",
"to" : "2016-05-30T13:55+09:00",
"lastKey" : "574bf0dbabe178ec1f776758"
}
이 API를 통해서 IOTOWN에 저장된 데이터를 가져올 수 있습니다.
{
"data":[
{
...
"_id":"64d9c56ec772dd00156d5cf1"
"node_id":"N001",
"value": { a : "1" },
"timestamp":"2018-11-01T07:50:52.033Z"
...
},
...
{
...
"_id":"574bf0dbabe178ec1f776758"
"node_id":"N001",
"value": { a : "2" },
"timestamp":"2018-11-01T09:50:21.748Z"
...
}
],
"lastKey":"574bf0dbabe178ec1f776758",
"errorCode":200,
"errorMsg":"Success"
}
위의 예제처럼
curl -X GET\ --header 'Accept: application/json'\ --header 'Token: your_own_token'\ 'https://town.coxlab.kr/api/v1.0/storage?nid=N001&from=2018-11-01T13:00:00Z&to=2018-11-02T13:00:00Z&lastKey=574bf0dbabe178ec1f776758'
이 API를 통해서 IOTOWN으로 데이터가 들어올 때마다 특정 URL로 POST 하도록 설정할 수 있습니다. 자세한 내용은 How to use callback을 참고하시기 바랍니다.
(Admin계정의 토큰 사용 불가능)
curl -X PUT\
--header 'Content-Type: application/json'\
--header 'Accept: application/json'\
--header 'Token: your_own_token'\
-d '{\
"url": "http://your.server.url"\
}'\
'https://town.coxlab.kr/api/v1.0/callback'
{
"errorCode":200,
"errorMsg":"Success"
}
이 API를 통해서 [PUT] callback으로 지정한 콜백 URL을 확인할 수 있습니다.
(Admin계정의 토큰 사용 불가능)
curl -X GET\ --header 'Accept: application/json'\ --header 'Token: your_own_token'\ 'https://town.coxlab.kr/api/v1.0/callback'
{
"callbackUrl":"http://your.server.url",
"callbackStatus":"1",
"errorCode":200,
"errorMsg":"Success"
}
이 API를 통해서 [PUT] callback으로 지정한 콜백 URL을 삭제할 수 있습니다.
(Admin계정의 토큰 사용 불가능)
curl -X DELETE\ --header 'Accept: application/json'\ --header 'Token: your_own_token'\ 'https://town.coxlab.kr/api/v1.0/callback'
{
"errorCode":200,
"errorMsg":"Success"
}
이 API를 통해서 장치의 커맨드 Queue를 확인할 수 있습니다.
curl -X POST\ --header 'Content-Type: application/json'\ --header 'Accept: application/json'\ --header 'Token: your_own_token'\ 'https://town.coxlab.kr/api/v1.0/command/LW1111222233334444'
{
"errorCode":200,
"errorMsg":"Success",
"command":[{"fCnt":11,"fPort":67,"data":"AxMA","confirmed":true}]
}
이 API를 통해서 HTTP를 지원하는 IoT 장치로 명령을 전송할 수 있습니다.
curl -X POST\
--header 'Content-Type: application/json'\
--header 'Accept: application/json'\
--header 'Token: your_own_token'\
-d '{\
"nid":"LW1111222233334444",\
"type":"string",\
"command":"command_string_here"\
}'\
'https://town.coxlab.kr/api/v1.0/command'
curl -X POST\
--header 'Content-Type: application/json'\
--header 'Accept: application/json'\
--header 'Token: your_own_token'\
-d '{\
"nid":"LW1111222233334444",\
"type":"hex",\
"command":"FF1234"\
}'\
'https://town.coxlab.kr/api/v1.0/command'
{
"errorCode":200,
"errorMsg":"Success"
}
이 API를 통해서 LoRa서버에 쌓여있는 command queue를 비울 수 있습니다.
curl -X DELETE\
--header 'Content-Type: application/json'\
--header 'Accept: application/json'\
--header 'Token: your_own_token'\
-d '{\
"nid":"LW1111222233334444",\
}'\
'https://town.coxlab.kr/api/v1.0/command'
{
"errorCode":200,
"errorMsg":"Success"
}
이 API를 통해서 HTTP를 지원하는 IoT 장치에서 IOTOWN으로 데이터를 전송할 수 있습니다.
curl -X POST\
--header 'Content-Type: application/json'\
--header 'Accept: application/json'\
--header 'Token: your_own_token'\
-d '{\
"type" : "2",\
"nid" : "N001",\
"data" : {\
"temperature":26.1,\
"humidity":43\
}\
}'\
'https://town.coxlab.kr/api/v1.0/data'
{
"errorCode":200,
"errorMsg":"Success"
}
이 API를 통해서 IOTOWN에 저장된 데이터를 삭제할 수 있습니다.
curl -X DELETE\
--header 'Content-Type: application/json'\
--header 'Accept: application/json'\
--header 'Token: your_own_token'\
-d '{\
"_id":"64d9c56ec772dd00156d5cf1",\
}'\
'https://town.coxlab.kr/api/v1.0/data'
curl -X DELETE\
--header 'Content-Type: application/json'\
--header 'Accept: application/json'\
--header 'Token: your_own_token'\
-d '{\
"nid":"LW1111222233334444",\
"from":"2023-08-14T05:59:12.317Z",\
"to":"2023-08-14T06:59:12.317Z",\
}'\
'https://town.coxlab.kr/api/v1.0/data'
{
"errorCode":200,
"errorMsg":"Success"
}