EIS RESTfulAPI ESL Solution

From ESS-WIKI
Revision as of 13:23, 7 October 2017 by Eric.liang (talk | contribs)
Jump to: navigation, search

RESTful API Path Rule for WSNManage

 This document is about EIS RESTful API service of Wireless Sensor Manage (WSNManage). There are two major classes in WSNManage service one is "Connectiviy" another is "SenHub". Connectivity is wireless interfaces information in the EIS IoT Gateway solution. "SenHub" is short of sensor hub. 

Connectivity

GET

Path: restapi/ESLManage/Connectivity

-> All Capability ( without data )

{
    "IoTGW": {
        "Zigbee": {
            "0000852CF4B7B0E8": {
                "Info": {
                    "e": [
                        {"n": "DeviceList","sv": ",","asm": "r"},
                        {"n": "premit-tag-list","sv": "","asm": "rw"},
                        {"n": "pan-id","v": 1,"asm": "r"},
                        {"n": "zd-channel","v": 11,"asm": "rw""min":11,"max":26},
                        {"n": "zd-securekey","sv": "","asm": "w","min":32,"max":23},
                        {"n": "zd-fw-version","v": 1,"asm": "r"},                        
                        {"n": "zd-fw-update","sv": "","asm": "w","type":"octe-stream","encode":"base64"},
                        {"n": "all-router-fw-update","sv": "","asm": "w","type":"octe-stream","encode":"base64"},
                        {"n": "all-tag-fw-update","sv": "","asm": "w","type":"octe-stream","encode":"base64"},
                        {"n": "all-tag-image-update","sv": "","asm": "w","type":"octe-stream","encode":"base64"},
                        {"n": "ftp-username","sv": "","asm": "rw"},
                        {"n": "ftp-password","sv": "","asm": "rw"},                            
                        {"n": "reboot","bv": 0,"asm": "rw"}
                    ],
                    "bn": "Info"
                },
                "bn": "0000852CF4B7B0E8",
                "ver": 1
            },
            "bn": "Zigbee"
        },
        "HostGateway": "",
        "ver": 1,
        "bn": "IoTGW"
    }
}

'Path: 'restapi/ESLManage/Connectivity/IoTGW/Zigbee/0000852CF4B7B0E8/Info

Reply: with latest data value

{
    "e": [
          {"n": "DeviceList","sv": "0000852CF4BE33BC"},
          {"n": "pan-id","v": 6},
          {"n": "zd-channel","v": 11},
          {"n": "zd-securekey","sv": ""},
          {"n": "premit-tag-list","sv": "0000852CF4BE36558"},
          {"n": "zd-fw-version","v": 1},
          {"n": "zd-fw-update","sv": ""},
          {"n": "all-router-fw-update","sv": ""},
          {"n": "all-tag-fw-update","sv": ""},
          {"n": "all-tag-image-update","sv": """},
          {"n": "ftp-username","sv": ""},
          {"n": "ftp-password","sv": ""},
          {"n": "reboot","bv": 0}
          ],
     "bn": "Info"
}

Put

Path: restapi/ESLManager/Connectivity/IoTGW/Zigbee/'0000852CF4B7B0E8/Info/reset

Data: 

{"bv":1}

Reply:

Status Code: 200

Data: 

{"bv":1}

Device

Get

1.Path: restapi/ESLManager/Device/AllDeviceList

Reply:

{"n":"AllDeviceList","sv":"xxxxxx,0017000E40000001,xxxxx"}

2. Path: restapi/ESLManager/Device/<DeviceID>/DevInfo

Reply by Router:

{
   	"devID":"0022000E40000022",
   	"hostname":"AAA",
   	"sn":"0017000E40000001",
   	"mac":"0017000E40000001",
   	"version":"3.1.23",
   	"type":"IoTGW",
   	"product":"WISE-20xx",
   	"manufacture":"",
   	"status":"1",
   	"commCmd":1,
   	"requestID":30002,
   	"agentID":"0022000E40000022",
   	"handlerName":"general",
   	"sendTS":160081026
}

Reply by Tag ( SenHub )

{
   	"devID":"0033000E40000033",
   	"hostname":"AAA",
   	"sn":"0017000E40000001",
   	"mac":"0017000E40000001",
   	"version":"3.1.23",
   	"type":"SenHub",
   	"product":"WISE-10xx",
   	"manufacture":"",
   	"status":"1",
   	"commCmd":1,
   	"requestID":30002,
   	"agentID":"0033000E40000033",
   	"handlerName":"general",
   	"sendTS":160081026
}


3. Path: restapi/ESLManager/Device/<DeviceID>

Reply: Capability ( without data ) by Tag

{  
  "SenHub": {
        "SenData": {"e":[ {"n":"image-crc","sv":"0xC6EB8EA8","asm":"r"}
                        ],
        "bn":"SenData"
        },
        "Info": {"e":[{"n":"update-period","v":60,"asm":"rw","min":30, "max":3600},
                      {"n":"timeout","v":30,"asm":"rw","min":1, "max":60}
                     ],
        "bn":"Info"
       },
       "Net": {"e":[{"n":"tx-level","v":1,"asm":"rw"},
                    {"n":"rssi","v":36,"asm":"r"},
                    {"n":"channel","v":11,"asm":"r", "min":11, "max":36},
                    {"n":"fw-version","v":1,"asm":"r"}
                   ],
        "bn":"Net"
       },
       "Action": {"e":[{"n":"image-update","sv":"","asm":"w", "encode":"base64","type":"octe-stream"}, 
                       {"n":"refresh-image","bv":0,"asm":"rw"}, 
                       {"n":"reboot","bv":0,"asm":"rw"},
                       {"n":"reset-to-default","bv":0,"asm":"rw"},
                       {"n":"fw-update","sv":"","asm":"w", "encode":"base64","type":"octe-stream"}], 
      "bn":"Action"
      }
    "bn":"SenHub"     
    }  
}

Reply: Capability ( without data ) by Router


{
    "IoTGW": {
        "Zigbee": {
            "0000852CF4BE33BC/0000852CF4BE66OD": {
                "Info": {
                    "e": [
                        {"n": "DeviceList","sv": "","asm": "r"},
                        {"n": "zd-tx-power","v": 10,"asm": "w","min":1,"max":20 },
                        {"n": "zd-fw-version","v":1, "asm": "r"},
                        {"n": "zd-fw-update","sv": "","asm": "w","type":"octe-stream","encode":"base64"},
                        {"n": "all-tag-fw-update","sv": "","asm": "w","type":"octe-stream","encode":"base64"},
                        {"n": "all-tag-image-update","sv": "","asm": "w","type":"octe-stream","encode":"base64"},
                        {"n": "ftp-username","sv": "","asm": "rw",},
                        {"n": "ftp-password","sv": "","asm": "rw",},                            
                        {"n": "reboot","bv": 0,"asm": "rw"}
                    ],
                    "bn": "Info"
                },
                "bn": "0000852CF4BE33BC/0000852CF4BE66OD",
                "ver": 1
            },
            "bn": "Zigbee"
        },
        "HostGateway": "0000852CF4B7B0E8",
        "ver": 1,
        "bn": "IoTGW"
    }
}


4. Path: restapi/ESLManager/Device/<DeviceID>/SenHub

Reply: with latest data value 

{        
    "SenData": {"e":[ {"n":"Temperature","v":26},
                      {"n":"Humidity","v":80},
                      {"n":"GPIO1","u":"","bv":0},
                      {"n":"GPIO2","u":"","bv":1}                      
                    ],
    "bn":"SenData"
    },
    "Info": {"e":[{"n":"Name","sv":"SenHub1"},
                  {"n":"sw","sv":"1.0.00"}
                 ],
    "bn":"Info"
   },
   "Net": {"e":[{"n":"sw","sv":"1.0.00"},
                {"n":"Neighbor","sv":"00017b8965"},
                {"n":"Health","v":"100.000000"}
               ],
    "bn":"Net"
   },
   "bn":"SenHub"    
}

5. Path:restapi/ESLManager/Device/<DeviceID>/SenHub/SenData

Reply: with latest data

{
    "SenData": {"e":[ {"n":"Temperature","v":26},
                      {"n":"Humidity","v":80},
                      {"n":"GPIO1","u":"","bv":0},
                      {"n":"GPIO2","u":"","bv":1}                        
                    ]
    },
    "bn":"SenData"
}

6. restapi/ESLManager/Device/<DeviceID>/SenHub/SenData/Temperature

Reply: with latest data

{"v":26}

Put

EIS RESTful only supports change one resource in each request.

Ex: To chagne SenHub's Name by 'PUT' RESTful method

Path: restapi/WSNManage/SenHub/<DeviceID>/SenHub/SenData/GPI01

Data: 

{"bv":1}

Reply:

HTTP Code: 200 OK

Data: 

{"bv":1}

WebSocket Service

WebSocket is a computer communications protocol, providing full-duplex communication channels over a single TCP connection. The WebSocket protocol was standardized by the IETF as RFC 6455 in 2011, and the WebSocket API in Web IDL is being standardized by the W3C.

WebSocket is designed to be implemented in web browsers and web servers, but it can be used by any client or server application. The WebSocket Protocol is an independent TCP-based protocol. Its only relationship to HTTP is that its handshake is interpreted by HTTP servers as an Upgrade request.[1] The WebSocket protocol makes more interaction between a browser and a web server possible, facilitating the real-time data transfer from and to the server. This is made possible by providing a standardized way for the server to send content to the browser without being solicited by the client, and allowing for messages to be passed back and forth while keeping the connection open. In this way, a two-way (bi-directional) ongoing conversation can take place between a browser and the server. The communications are done over TCP port number 80, which is of benefit for those environments which block non-web Internet connections using a firewall. Similar two-way browser-server communications have been achieved in non-standardized ways using stopgap technologies such as Comet.


API-Manage Websocket JSON Data Format

{"n":"<GroupName>","event":"event Type","data":{JSON Obj}}


Websocket of WSNManage 

Endpoint: ws://ServerIP:Port/WSNManage

Client request Server by this Endpoint to require "WSNManage" service. Server will auto push WSNManage event to client.

Please refer to "WSNManage evnent message" for WSNManage's event and data format.

WSNManage evnent message

events:[
     {"event":"eConnectivity_Capability"}, // => Update Connectivity Capability ( Without data )
     {"event":"eConnectivity_UpdateData"}, // => Update Connectivity's Data
     {"event":"eSenHub_Connected"},        // => A new SenHub connected
     {"event":"eSenHub_Disconnect"},       // => A SenHub is disconnected
     {"event":"eSenHub_Capability"},       // => Update a SenHub's Capability ( Without Data )
     {"event":"eSenHub_UpdateData"}]       // => Update SenHub's Data

Updtae Connectivity's Capability

event: eConnectivity_Capability

data:

{
 "IoTGW": {
          "WSN": { 
             "WSN0": { 
                  "Info": { 
                            "e": [{"n":"SenHubList","sv":",","asm":"r"},
                                  {"n":"Neighbor","sv":"","asm":"r"},
                                  {"n":"Health","v":80,"asm":"r"},
                                  {"n":"Name","sv":"WSN0","asm":"r"},
                                  {"n":"sw","sv":"1.0.0.1","asm":"r"},
                                  {"n":"reset","bv":0,"asm":"rw"}], 
                  "bn":"Info" 
                  }, 
              "bn":"0000852CF4B7B0E8", "ver":1 
            }, 
            "WSN1": { 
                  "Info": { 
                           "e": [{"n":"SenHubList","sv":"","asm":"r"}, 
                                 {"n":"Neighbor","sv":"","asm":"r"}, 
                                 {"n":"Health","v":50,"asm":"r"}, 
                                 {"n":"Name","sv":"WSN1","asm":"r"}, 
                                 {"n":"sw","sv":"1.0.0.1","asm":"r"}, 
                                 {"n":"reset","bv":0,"asm":"rw"}], 
                   "bn":"Info" 
                   }, 
            "bn":"0000852CF4B7B0E7", 
            "ver":1 
            }, 
         "bn":"WSN" 
       }, 
       "Bt": { 
             "Bt0": { 
                    "Info": { 
                             "e": [{"n":"SenHubList","sv":"","asm":"r"}, 
                                   {"n":"Health","v":90,"asm":"r"}, 
                                   {"n":"Name","sv":"Bt0","asm":"r"}, 
                                   {"n":"sw","sv":"3.0.0.1","asm":"r"}, 
                                   {"n":"reset","bv":0,"asm":"rw"}], 
                    "bn":"Info" 
                    }, 
               "bn":"0000802CF4B7B028", 
               "ver":1 
               }, 
         "bn":"Bt" 
        },   
     "ver": 1,
     "bn":"IoTGW"
    }
 }

Updtae data value of connectivity

event Type: eConnectivity_UpdateData

data:Update Health

{
    "data":{
       "IoTGW": {
           "WSN": {
            "0000852CF4B7B0E8"{            
                "Info": {
                        "e": [{"n":"Health","v":30}],
                        "bn":"Info"
                }                
              "bn":"0000852CF4B7B0E8",
              "ver":1
            },            
            "bn":"WSN" 
        },
    "ver": 1        
    }
}


A new SenHub connected

event Type: eSenHub_Connected

data:

{
  "susiCommData": {
        "devID":"0017000E40000001",
        "hostname":"AAA",
        "sn":"0017000E40000001",
        "mac":"0017000E40000001",
        "version":"3.1.23",
        "type":"SenHub",
        "product":"WISE-1020",
        "manufacture":"",
        "status":"1",
        "commCmd":1,
        "requestID":30002,
        "agentID":"0017000E40000001",
        "handlerName":"general",
        "sendTS":160081026
   }
}


A SenHub disconnected

event Type: eSenHub_Disconnect

data:

{
  "susiCommData": {
        "devID":"0017000E40000001",
        "hostname":"AAA",
        "sn":"0017000E40000001",
        "mac":"0017000E40000001",
        "version":"3.1.23",
        "type":"SenHub",
        "product":"WISE-1020",
        "manufacture":"",
        "status":"0",
        "commCmd":1,
        "requestID":30002,
        "agentID":"0017000E40000001",
        "handlerName":"general",
        "sendTS":160081026
   }
}


Update capbaility of a SenHub

event Type: eSenHub_Capability

data:

{
    "SenHub": {
        "SenData": {"e":[ {"n":"Temperature","u":"Cel","v":0.000000,"min":-100.000000,"max":200.000000,"asm":"r","type":"d","rt":"ucum.Cel","st":"ipso","exten":""},
                          {"n":"Humidity","u":"%","v":0.000000,"min":0.000000,"max":100.000000,"asm":"r","type":"d","rt":"ucum.%","st":"ipso","exten":""},
                          {"n":"GPIO1","u":"","bv":0,"min":0.000000,"max":1.000000,"asm":"r","type":"b","rt":"","st":"ipso","exten":""},
                          {"n":"GPIO2","u":"","bv":0,"min":0.000000,"max":1.000000,"asm":"r","type":"b","rt":"","st":"ipso","exten":""}
                        ],
        "bn":"SenData"
        },
        "Info": {"e":[{"n":"Name","sv":"SenHub1","asm":"rw"},
                      {"n":"sw","sv":"1.0.00","asm":"r"}
                     ],
        "bn":"Info"
       },
       "Net": {"e":[{"n":"sw","sv":"1.0.00","asm":"r"},
                    {"n":"Neighbor","sv":"","asm":"r"},
                    {"n":"Health","v":"100.000000","asm":"r"}
                   ],
        "bn":"Net"
       },
    },
   "agentID":"0017000E40000001"
}


Update data value of a SenHub

event Type: eSenHub_UpdateData

data:

{  
    "SenHub":{  
       "SenData":{  
          "e":[ {"n":"Temperature","v":18.6},
                {"n":"Humidity","v":57},
                {"n":"GPIO1","bv":0},
                {"n":"GPIO2","bv":0}],
          "bn":"SenData"
       },
       "ver":1
   },
   "agentID":"0017000E40000001"  
}