Controller 2.0 HTTP/REST/JSONP API
JSONP is a method of padding the JSON output with an API call and using HTML <script> elements to download resources cross-site.
To use JSONP, you should include a 'callback' as request parameter. You do not need to specify Accept HTTP header.
The response will be:
We provide JSON format by converting XML into JSON, some simple rules are used when converting REST XML into JSON objects, see http://www.xml.com/pub/a/2006/05/31/converting-between-xml-and-json.html
Request Panel Identity List
Example Request URL
Example Response
- content-type: application/json
Errors
- Error Code: 426, panel.xml not found Error.
- Error Code: 427, Invalid panel.xml Error.
Request Panel UI Layout by Logical Identity (Name)
- Parameters: panel_logical_identity
Sample Request URL
URL encoded:
Example Response
- content-type: application/json
{
"tabbar": {"item": [
{
"@name": "Livingroom",
"navigate": {"@toGroup": "142"},
"image": {"@src": "light1274952251695.png"}
},
{
"@name": "Aircondition",
"navigate": {
"@toGroup": "142",
"@toScreen": "228"
},
"image": {"@src": "aircondition1274952362228.png"}
},
{
"@name": "TV",
"navigate": {
"@toGroup": "142",
"@toScreen": "237"
},
"image": {"@src": "tvitem1274952294708.png"}
},
{
"@name": "Bedroom",
"navigate": {"@toGroup": "173"},
"image": {"@src": "togroup1274952414154.png"}
},
{
"@name": "Setting",
"navigate": {"@to": "setting"},
"image": {"@src": "setting1274952617279.png"}
},
{
"@name": "Logout",
"navigate": {"@to": "logout"},
"image": {"@src": "logout1274952557426.png"}
},
{
"@name": "Login",
"navigate": {"@to": "login"},
"image": {"@src": "login1274952785498.png"}
},
{
"@name": "Back",
"image": {"@src": "back1274952817159.png"}
}
]},
"screens": {"screen": [
{
"@id": "211",
"@name": "Light",
"@inverseScreenId": "218",
"background": {
"@fillScreen": "true",
"image": {"@src": "lightbackground1274950957643.png"}
},
"absolute": [
{
"@left": "43",
"@top": "108",
"@width": "86",
"@height": "52",
"button": {
"@id": "212",
"@name": "turn on",
"@hasControlCommand": "true"
}
},
{
"@left": "175",
"@top": "108",
"@width": "95",
"@height": "52",
"button": {
"@id": "213",
"@name": "turn off",
"@hasControlCommand": "true"
}
},
{
"@left": "127",
"@top": "174",
"@width": "185",
"@height": "54",
"label": {
"@id": "214",
"@fontSize": "14",
"@color": "#0000FF",
"@text": "light status",
"link": {
"@ref": "570",
"state": [
{
"@name": "off",
"@value": "light is off"
},
{
"@name": "on",
"@value": "light is on"
}
]
}
}
},
{
"@left": "195",
"@top": "240",
"@width": "50",
"@height": "50",
"switch": {
"@id": "215",
"link": {
"@ref": "570",
"state": [
{
"@name": "on",
"@value": "power.png"
},
{
"@name": "off",
"@value": "infrared.png"
}
]
}
}
},
{
"@left": "117",
"@top": "16",
"@width": "66",
"@height": "81",
"image": {
"@id": "216",
"@src": "OpenRemote.Logo.30x32.png",
"link": {
"@ref": "570",
"state": [
{
"@name": "off",
"@value": "lightbulboff1274951408852.png"
},
{
"@name": "on",
"@value": "lightbulb1274951401848.png"
}
]
},
"include": {"@ref": "214"}
}
}
]
},
{
"@id": "218",
"@name": "Light",
"@landscape": "true",
"@inverseScreenId": "211",
"background": {
"@relative": "TOP",
"image": {"@src": "500X3001274943015264.png"}
},
"absolute": [
{
"@left": "184",
"@top": "112",
"@width": "84",
"@height": "82",
"image": {
"@id": "219",
"@src": "OpenRemote.Logo.30x32.png",
"link": {
"@ref": "570",
"state": [
{
"@name": "off",
"@value": "lightbulboff1274951484491.png"
},
{
"@name": "on",
"@value": "lightbulb1274951481080.png"
}
]
}
}
},
{
"@left": "126",
"@top": "22",
"@width": "212",
"@height": "52",
"label": {
"@id": "220",
"@fontSize": "14",
"@color": "#FF6600",
"@text": "light state",
"link": {
"@ref": "570",
"state": [
{
"@name": "off",
"@value": "OFF"
},
{
"@name": "on",
"@value": "ON"
}
]
}
}
},
{
"@left": "143",
"@top": "209",
"@width": "150",
"@height": "50",
"label": {
"@id": "324",
"@fontSize": "14",
"@color": "#FFFFFF",
"@text": "Test gesture"
}
}
],
"gesture": [
{
"@id": "221",
"@hasControlCommand": "true"
},
{
"@id": "222",
"@hasControlCommand": "true"
},
{
"@id": "223",
"@hasControlCommand": "true"
},
{
"@id": "224",
"@hasControlCommand": "true"
}
]
},
{
"@id": "228",
"@name": "Aircondition",
"background": {
"@fillScreen": "true",
"image": {"@src": "air1274951021940.png"}
},
"absolute": [
{
"@left": "139",
"@top": "32",
"@width": "110",
"@height": "52",
"label": {
"@id": "229",
"@fontSize": "14",
"@color": "#3366FF",
"@text": "value",
"link": {"@ref": "568"}
}
},
{
"@left": "59",
"@top": "86",
"@width": "198",
"@height": "44",
"slider": {
"@id": "230",
"@vertical": "false",
"@passive": "false",
"link": {"@ref": "568"},
"min": {"@value": "0"},
"max": {"@value": "100"}
}
},
{
"@left": "267",
"@top": "178",
"@width": "44",
"@height": "198",
"slider": {
"@id": "231",
"@thumbImage": "vthumb1274939161708.png",
"@vertical": "true",
"@passive": "false",
"link": {"@ref": "568"},
"min": {
"@value": "0",
"@image": "vmin1274939127956.png",
"@trackImage": "vminTrack1274939151356.png"
},
"max": {
"@value": "100",
"@image": "vmax1274939183784.png",
"@trackImage": "vmaxTrack1274939173529.png"
}
}
},
{
"@left": "59",
"@top": "130",
"@width": "198",
"@height": "44",
"slider": {
"@id": "232",
"@thumbImage": "thumbImage1274939361119.png",
"@vertical": "false",
"@passive": "false",
"link": {"@ref": "568"},
"min": {
"@value": "0",
"@image": "low1274939314970.png",
"@trackImage": "red1274939338142.png"
},
"max": {
"@value": "100",
"@image": "high1274939397163.png",
"@trackImage": "green1274939382473.png"
}
}
},
{
"@left": "39",
"@top": "31",
"@width": "130",
"@height": "52",
"label": {
"@id": "233",
"@fontSize": "14",
"@color": "#FF6600",
"@text": "temperature:"
}
}
]
},
{
"@id": "237",
"@name": "TV",
"background": {
"@fillScreen": "true",
"image": {"@src": "tvbackground1274951037399.png"}
},
"absolute": {
"@left": "15",
"@top": "10",
"@width": "287",
"@height": "54",
"label": {
"@id": "238",
"@fontSize": "14",
"@color": "#000000",
"@text": "Test grid layout, Not send commnad"
}
},
"grid": {
"@left": "51",
"@top": "65",
"@width": "210",
"@height": "200",
"@rows": "4",
"@cols": "3",
"cell": [
{
"@x": "0",
"@y": "0",
"@rowspan": "1",
"@colspan": "1",
"button": {
"@id": "239",
"@name": "On"
}
},
{
"@x": "2",
"@y": "0",
"@rowspan": "1",
"@colspan": "1",
"button": {
"@id": "240",
"@name": "Off"
}
},
{
"@x": "1",
"@y": "0",
"@rowspan": "1",
"@colspan": "1",
"button": {
"@id": "241",
"@name": "Mute"
}
},
{
"@x": "0",
"@y": "2",
"@rowspan": "1",
"@colspan": "1",
"button": {
"@id": "242",
"@name": "Vol-"
}
},
{
"@x": "2",
"@y": "2",
"@rowspan": "1",
"@colspan": "1",
"button": {
"@id": "243",
"@name": "Vol+"
}
},
{
"@x": "1",
"@y": "1",
"@rowspan": "1",
"@colspan": "1",
"button": {
"@id": "244",
"@name": "Ch+"
}
},
{
"@x": "1",
"@y": "3",
"@rowspan": "1",
"@colspan": "1",
"button": {
"@id": "245",
"@name": "Ch-"
}
},
{
"@x": "1",
"@y": "2",
"@rowspan": "1",
"@colspan": "1",
"button": {
"@id": "246",
"@name": "Menu"
}
}
]
}
},
{
"@id": "250",
"@name": "Navigate_Buttons",
"background": {
"@fillScreen": "true",
"image": {"@src": "yesanpoh1274939752102.jpg"}
},
"absolute": {
"@left": "15",
"@top": "242",
"@width": "26",
"@height": "25",
"image": {
"@id": "251",
"@src": "turtle1274939826027.png"
}
},
"grid": {
"@left": "110",
"@top": "262",
"@width": "200",
"@height": "150",
"@rows": "3",
"@cols": "4",
"cell": [
{
"@x": "0",
"@y": "0",
"@rowspan": "1",
"@colspan": "2",
"button": {
"@id": "252",
"@name": "Login",
"navigate": {"@to": "login"}
}
},
{
"@x": "2",
"@y": "0",
"@rowspan": "1",
"@colspan": "2",
"button": {
"@id": "253",
"@name": "Logout",
"navigate": {"@to": "logout"}
}
},
{
"@x": "0",
"@y": "1",
"@rowspan": "1",
"@colspan": "2",
"button": {
"@id": "254",
"@name": "Setting",
"navigate": {"@to": "setting"}
}
},
{
"@x": "2",
"@y": "1",
"@rowspan": "1",
"@colspan": "2",
"button": {
"@id": "255",
"@name": "Back",
"navigate": {"@to": "back"}
}
}
]
}
}
]},
"groups": {"group": [
{
"@id": "142",
"@name": "Livingroom",
"include": [
{"@ref": "211"},
{"@ref": "218"},
{"@ref": "228"},
{"@ref": "237"}
]
},
{
"@id": "173",
"@name": "Bedroom",
"include": {"@ref": "250"}
}
]}
}
Errors
- Error Code: 426, panel.xml not found Error.
- Error Code: 427, Invalid panel.xml Error.
- Error Code: 428, No such panel identity Error.
Send Write Command
- Parameters:
- control_id : control id
- command_param :
- Switch: ON/OFF
- Slider: some integer or float, e.g. 27
- Button: click
- Gesture: swipe
Example Request URL
Example Response
Errors
- Error Code: 418, Command Build Error. Happens when a Command can't be built from a DOM Element.
- Error Code: 419, No Such Component Error.
- Error Code: 420, No Such Command Builder Error.
- Error Code: 422, controller.xml Not Found Error.
- Error Code: 423, No Such Command Error.
- Error Code: 424, Invalid controller.xml Error.
- Error Code: 429, Invalid XML element Error.
Sensor Status Request
This service will return sensor status from controller's state cache immediately.
- Parameters: sensor_id list
Example Request URL
Example Response
- content-type:application/json:
Errors
- Error Code: 418, Command Build Error. Happens when a Command can't be built from a DOM Element.
- Error Code: 419, No Such Component Error.
- Error Code: 420, No Such Command Builder Error.
- Error Code: 422, controller.xml Not Found Error.
- Error Code: 423, No Such Command Error.
- Error Code: 424, Invalid controller.xml Error.
- Error Code: 429, Invalid XML element Error.
Sensor Polling Request
This service is used a delayed HTTP request on the server side, and will return only when the status of any sensor in sensor_id list is changed, or return 504 response code if no change occurs within 50 seconds. If you need the current status from state cache with immediate HTTP response, use "Sensor Status Request" (above) instead.
- Parameters: device_id (Unique ID of device, used to track session to avoid missing change detection when refreshing polling after timeout), sensor_id list.
Example Request URL
Example Response
If no status change occurs:
Otherwise:
- content-type:application/json:
Errors
- Error Code: 418, Command Build Error. Happens when a Command can't be built from a DOM Element.
- Error Code: 419, No Such Component Error.
- Error Code: 420, No Such Command Builder Error.
- Error Code: 422, controller.xml Not Found Error.
- Error Code: 423, No Such Command Error.
- Error Code: 424, Invalid controller.xml Error.
- Error Code: 429, Invalid XML element Error.
Fail-over (Round-Robin) Group Member Service
This service will return all cluster group members' Controller URLs.
Example Request URL
Example Response
- content-type: application/json
Errors
- Error Code: 450, Failed to start tcp server.
- Error Code: 451, Failed to start udp server.
- Error Code: 452, Failed to establish udp client.
- Error Code: 453, Invalid groupmember service url.
JSON Failure Responses
JSON API doesn't use response code because of JSONP error handling (sometimes ignores a timeout and doesn't fire the error event). So JSON failure HTTP response code is also 200.
From JavaScript, you can check error attribute for failure, and then read the error from error.code and error.message.
Example response
See Also
|
|