Difference between revisions of "EIS RESTfulAPI ProcWSNData"

From ESS-WIKI
Jump to: navigation, search
Line 215: Line 215:
 
There are two methods ( 1. request / response, 2. auto push message to client ) to get information by Socket.io. 
 
There are two methods ( 1. request / response, 2. auto push message to client ) to get information by Socket.io. 
  
=== Request ===
+
=== <span style="color:#FF0000;">'''Request'''</span> ===
  
'''Direction: '''Client -> Socket.io Server
+
'''Direction: '''Client -> Socket.io Serv<span style="background-color:#FFFFFF;"></span>er
  
 
'''Event''': request
 
'''Event''': request
Line 224: Line 224:
  
 
'''Action''':
 
'''Action''':
<pre>            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.
+
*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.</pre>
+
*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.
 
"'''data'''": data of request in JSON object.
Line 234: Line 233:
 
"'''sessionId'''": &nbsp;Unique interger&nbsp;number of&nbsp;each request for&nbsp;distinguish. Server would&nbsp;response and fill the same sessionId.
 
"'''sessionId'''": &nbsp;Unique interger&nbsp;number of&nbsp;each request for&nbsp;distinguish. Server would&nbsp;response and fill the same sessionId.
  
=== Response ===
+
=== <span style="color:#FF0000;">'''Response'''</span> ===
  
 
'''Direction:&nbsp;'''Server -> Client
 
'''Direction:&nbsp;'''Server -> Client
Line 250: Line 249:
  
  
=== Message ===
+
=== <span style="color:#FF0000;">'''Example of Action'''</span> ===
 +
 
 +
==== <span style="color:#0000FF;">'''service:&nbsp;'''</span>Client query which event services provided by Socket.io Server ====
 +
 
 +
==== C->S &lt;Request&gt;: {"n":"service", "data":"", "sessionId":8954} ====
 +
 
 +
S-> C &lt;Response&gt;: {"status":200,"data":{"service":{ "e":[{"n":"WSNManage"},{"n":"SUSIManage"}]}},"sessionId":8954}
 +
 
 +
 
 +
 
 +
'''<span style="color:#0000FF;">subscribe:</span>'''Client subscibe in to join to receive which event Socket.io service
 +
 
 +
==== C->S &lt;Request&gt;: {"n":"subscribe", "data":"WSNManage", "sessionId":54774} ====
 +
 
 +
S-> C &lt;Response&gt;: {"status":200,"data":[{"event":"eConnectivity_Capability"},{"event":"eConnectivity_UpdateData"}, {"event":"eSenHub_Connected"},{"event":"eSenHub_Disconnect"}, &nbsp;
 +
 
 +
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {"event":"eSenHub_Capability"},&nbsp;{"event":"eSenHub_UpdateData"}]"sessionId":8954}
 +
 
 +
 
 +
 
 +
<span style="color:#0000FF;">'''unsubscribe'''</span>: Clinet unsubscribe to leave which event Socket.io Service
 +
 
 +
C->S &lt;Request&gt;: {"n":"unsubscribe", "data":"WSNManage", "sessionId":6666}
 +
 
 +
S-> C &lt;Response&gt;: {"status":200,"sessionId":6666}
 +
<span style="color:#FF0000;"></span>
 +
 
 +
 
 +
 
 +
 
 +
=== '''<span style="color:#FF0000;">Message</span>''' ===
  
 
'''Direction:&nbsp;'''Server -> Client
 
'''Direction:&nbsp;'''Server -> Client

Revision as of 03:38, 25 November 2016

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: 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: 'WSNManage/Connectivity/IoTGW/WSN/0000852CF4B7B0E8/Info/reset

Data: 

{"bv":1}

Reply:

Status Code: 200

Data: 

{"bv":1}

SenHub

Get

1.Path: 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: 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: 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: 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. 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: WSNManage/SenHub/<DeviceID>/SenHub/Info/Name

Data: 

{"sv":"Room"}

Reply:

HTTP Code: 200 OK

Data: 

{"sv":"Room"}

Socket.io

EIS socket.io Protocol

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.

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