EIS RESTfulAPI ProcWSNData

From ESS-WIKI
Revision as of 07:47, 27 November 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/WSNManage/Connectivity

-> All Capability ( without 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"
    }
 }

'Path: WSNManage/Connectivity/IoTGW/WSN/0000852CF4B7B0E8/Info

Reply: with latest data value

{
    "e": [{"n":"SenHubList","sv":"xxx,0017000E40000001,ooo"},
          {"n":"Neighbor","sv":"0000000EC6F0F830"},                                    
          {"n":"Health","v":80},
          {"n":"Name","sv":"WSN0"},
          {"n":"sw","sv":"1.0.0.1"},
          {"n":"reset","bv":0}],
    "bn":"Info"
}

Put

Path: 'restapi/WSNManage/Connectivity/IoTGW/WSN/0000852CF4B7B0E8/Info/reset

Data: 

{"bv":1}

Reply:

Status Code: 200

Data: 

{"bv":1}

SenHub

Get

1.Path: restapi/WSNManage/SenHub/AllSenHubList

Reply:

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

2. Path: WSNManage/SenHub/<DeviceID>/DevInfo </br>

Reply:

{
   	"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
}


3. Path: restapi/WSNManage/SenHub/<DeviceID>

Reply: Capability ( without 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"
       }
    }    
}

4. Path: restapi/WSNManage/SenHub/<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/WSNManage/SenHub/<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/WSNManage/SenHub/<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}

Socket.io

There are two methods ( 1. request / response, 2. auto push message to client ) to get information by Socket.io. 

Request

Direction: Client -> Socket.io Server

Event: request

Format: {"n":"<Action>", "data":{obj}, "sessionId":<#>}

Action:

  • service: To qurey what services provided by Socket.io server.
  • subscribe: To subscribe service that you interested (ex:WSNManage). Server will auto push event and message after success to joint service.
  • unsubscribe: To unsubscribe service if you don't want to interested it. Server will stop to push event and message to this client.

"data": data of request in JSON object.

"sessionId":  Unique interger number of each request for distinguish. Server would response and fill the same sessionId.

Response

Direction: Server -> Client

Event: response

Format: {"status":<#>, "data":{obj}, "sessionId":<#>}

"status": Refer to HTTP Status Code ( 200 -> OK , 404 -> Not Found )

"data": data of reply information in JSON object

"sessionId": Server need reply the same sessionId with client's request.


Example of Action

service: Client query which event services provided by Socket.io Server

C->S <Request>: {"n":"service", "data":"", "sessionId":8954}

S-> C <Response>: {"status":200,"data":{"service":{ "e":[{"n":"WSNManage"},{"n":"SUSIManage"}]}},"sessionId":8954}


subscribe:Client subscibe in to join to receive which event Socket.io service

C->S <Request>: {"n":"subscribe", "data":"WSNManage", "sessionId":54774}

S-> C <Response>: {"status":200,"data":[{"event":"eConnectivity_Capability"},{"event":"eConnectivity_UpdateData"}, {"event":"eSenHub_Connected"},{"event":"eSenHub_Disconnect"},  

                                                                  {"event":"eSenHub_Capability"}, {"event":"eSenHub_UpdateData"}]"sessionId":8954}


unsubscribe: Clinet unsubscribe to leave which event Socket.io Service

C->S <Request>: {"n":"unsubscribe", "data":"WSNManage", "sessionId":6666}

S-> C <Response>: {"status":200,"sessionId":6666}



Message

Direction: Server -> Client

Event: message

Format: {"n":"<ServiceName>", "event":"<eventType>", "data":{obj})

"ServiceName": Service Name

"event": event type of this push message

"data": push data message in JSON object.


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


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

{
   "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"  
}