Difference between revisions of "IoTGateway/RESTful API"
Chinchen.lin (talk | contribs) (→WSN Management) |
Chinchen.lin (talk | contribs) |
||
Line 470: | Line 470: | ||
} | } | ||
− | * <big>/ | + | * <big>/SystemMgmt/SystemInfo</big> |
<big>GET</big> | <big>GET</big> | ||
Line 526: | Line 526: | ||
} | } | ||
− | * <big>/ | + | * <big>/SystemMgmt/NetworkConfig</big> |
<big>PUT</big> | <big>PUT</big> | ||
Latest revision as of 09:43, 23 May 2016
Contents
Introduction
The WISE3310 exposes a comprehensive set of Web Service APIs for application integration purposes. The WISE3310 REST API allows you to build applications that use Representational State Transfer HTTP calls to retrieve, modify, or publish platform data. For example through the APIs, you are able to access all the functionality of the Server or to control a device from your application built on top of the WISE3310.
The WISE3310 platform conforms to standard REpresentational State Transfer (REST) protocol to expose its Application Programming Interfaces (API). REST has emerged over the past few years as a predominant Web service design model. REST-style architectures consist of clients and servers. Clients initiate requests to servers, while servers process requests and return appropriate responses. Requests and responses are built around the transfer of representations of resources. A resource can be essentially any coherent and meaningful concept that may be addressed. A representation of a resource is typically a document that captures the current or intended state of a resource.
WISE3310 RESTful APIs expose the standard action types (Create, Read, Update, and Delete) over the platform objects. They are capable of retrieving a resource representation in JSON format. You can use the REST HTTP Accept Header to specify the representation requested using the "application/json" Media Types.
Writing Web Services Client Applications
The WISE3310 provides a REST-style API over HTTP (or HTTPS). Users can write HTTP clients in their preferred programming language that get data/services from the WISE3310 and use or display the data in the way that they desire. Examples of such clients include Web pages and programs written in a language such as Python or Java. These clients send requests to the server using standard HTTP requests. The HTTP requests that WISE3310 supports are GET, PUT, POST, and DELETE. The server supports basic HTTP authentication and only valid users can access the database. To reduce the authentication overhead of multiple requests, either use an HTTP library that caches cookies, or cache the cookies JSESSIONID and SID yourself.
In a Web Browser
Any GET request can be typed into the URL field of a web browser. Some browser plug-ins (chrome plugin, DHC - REST/HTTP API Client) also allow other HTTP methods to be called.
Python
Python scripts can be written to send standard HTTP requests to the server. These scripts use Python libraries to handle connecting to the server, sending the request, and getting the reply. Use urllib2 to send request
Example:
GET:
import urllib2 import base64 username = 'NAME' password = 'PWD' url = 'http://localhost/restapi/AccountMgmt' base64string = base64.encodestring('%s:%s' % (username, password))[:-1] req = urllib2.Request(url) req.add_header("Authorization", "Basic %s" % base64string) req.add_header('Content-type', 'application/json') response = urllib2.urlopen(req).read() print(response)
PUT:
import urllib2 import base64 username = 'NAME' password = 'PWD' url = 'http://localhost/restapi/AccountMgmt/Login' data = '{"username":"admin","password":"1234"}' base64string = base64.encodestring('%s:%s' % (username, password))[:-1] req = urllib2.Request(url) req.get_method = lambda: 'PUT' req.add_header("Authorization", "Basic %s" % base64string) req.add_header('Content-Type', 'application/json') response = urllib2.urlopen(req, data).read() print(response)
C#
HTTP requests can be sent to the server through a Java program. The key classes are HttpWebRequest and HttpWebResponse from System.Net.
Example:
GET:
static string HttpGet(string url) { HttpWebRequest req = WebRequest.Create(url) as HttpWebRequest; req.Credentials = new System.Net.NetworkCredential("NAME", "PWD"); string privilege = string.Format("{0}:{1}", acut, pwd); byte[] bytes = System.Text.Encoding.GetEncoding("utf-8").GetBytes(privilege); req.Headers.Add("Authorization", Convert.ToBase64String(bytes)); req.Accept = "application/json"; string result = null; using (HttpWebResponse resp = req.GetResponse() as HttpWebResponse) { StreamReader reader = new StreamReader(resp.GetResponseStream()); result = reader.ReadToEnd(); } return result; }
PUT:
static string HttpPost(string url) { HttpWebRequest req = WebRequest.Create(new Uri(url)) as HttpWebRequest; req.Credentials = new System.Net.NetworkCredential("NAME", "PWD"); req.Method = "PUT"; req.ContentType = "application/json"; req.Accept = "application/json"; string privilege = string.Format("{0}:{1}", acut, pwd); byte[] bytes = System.Text.Encoding.GetEncoding("utf-8").GetBytes(privilege); req.Headers.Add("Authorization", Convert.ToBase64String(bytes)); StringBuilder paramz = new StringBuilder(); paramz.Append("{\"username\":\"admin\",\"password\":\"1234\"}"); byte[] formData = UTF8Encoding.UTF8.GetBytes(paramz.ToString()); req.ContentLength = formData.Length; // Send Request: using (Stream post = req.GetRequestStream()) { post.Write(formData, 0, formData.Length); } // Response: string result = null; using (HttpWebResponse resp = req.GetResponse() as HttpWebResponse) { StreamReader reader = new StreamReader(resp.GetResponseStream()); result = reader.ReadToEnd(); } return result; }
Java
HTTP requests can be sent to the server through a Java program. use java.net.URL and java.net.HttpURLConnection to send request.
Example:
GET:
private static void HttpGet(String urlstr) { String username = "NAME", password = "PWD"; HttpURLConnection conn = null; String userPassword = username + ":" + password; String encoding = new sun.misc.BASE64Encoder().encode(userPassword.getBytes()); try{ URL url = new URL(urlstr); conn = (HttpURLConnection)url.openConnection(); conn.setRequestMethod("GET"); conn.setRequestProperty("Accept", "application/json"); conn.setRequestProperty("Authorization", "Basic " + encoding); if (conn.getResponseCode() != 200) { throw new RuntimeException("Failed : HTTP error code : "+ conn.getResponseCode()); } BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream()))); String output; System.out.println("Output from Server .... \n"); while ((output = br.readLine()) != null) { System.out.println(output); } conn.disconnect(); } catch(Exception e) {} }
PUT:
private static void HttpPOST(String urlstr) { String username = "NAME", password = "PWD"; HttpURLConnection conn = null; String userPassword = username + ":" + password; String encoding = new sun.misc.BASE64Encoder().encode(userPassword.getBytes()); try{ URL url = new URL(urlstr); conn = (HttpURLConnection)url.openConnection(); conn.setDoOutput(true); conn.setRequestMethod("PUT"); conn.setRequestProperty("Content-Type", "application/json"); conn.setRequestProperty("Accept", "application/json"); conn.setRequestProperty("Authorization", "Basic " + encoding); String input = "{\"username\":\"admin\",\"password\":\"1234\"}"; OutputStream outputStream = conn.getOutputStream(); outputStream.write(input.getBytes()); outputStream.flush(); if (conn.getResponseCode() != 200) { throw new RuntimeException("Failed : HTTP error code : "+ conn.getResponseCode()); } BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream()))); String output; System.out.println("Output from Server .... \n"); while ((output = br.readLine()) != null) { System.out.println(output); } conn.disconnect(); } catch(Exception e){} }
Javascript
use jQuery's $.ajax() to send request
Example:
$.ajax( { type: put, url: 'http://localhost/restapi/AccountMgmt', data: '{"username":"admin","password":"1234"}', contentType: 'application/json', dataType: 'text', error: function(xhr, exception) { //TODO }, beforeSend: function(xhr) { xhr.setRequestHeader("Authorization", "Basic " + $.base64.encode(user + ":" + password)); }, success: function(response) { } });
Web Services
URL Specification
WISE3310 Web Services APIs are RESTful in nature. Every URL relates to a specific resource or list of resources.
URI: http://<ip address>/restapi/<resource path> All REST APIs use CRUD Conventions as follows:
Action | Create | Read | Update | Delete |
---|---|---|---|---|
HTTP VERB | POST/PUT* | GET | PUT | DELETE |
Return Error Code
Catalog | Error Code | Description |
---|---|---|
Server Status | 1001 | Internal Sever Error |
Input Argument and Data | 1051 | Input Invalid JSON |
Input Argument and Data | 1052 | Input Argument Error |
Output Data | 1101 | Output Invalid JSON |
Service Access | 1151 | Invalid URL |
Service Access | 1152 | Invalid Method |
Service Access | 1153 | Read Only |
Example:
{ "result": { "ErrorCode": "1051", "Description": "Input Invalid JSON" } }
REST Resource
- API Information
The following resources are applicable:
- /APIInfoMgmt
/APIInfoMgmt GET
Retrieve all API resources, and API version.
Request :
Ex:
curl -H "Content-Type: application/json" -X GET http://username:password@172.22.12.34/restapi/APIInfoMgmt
Response Body: (media type: application/json)
{ "result" : { "Mgmt" : { "item" : [ "AccountMgmt", "SystemMgmt", "ProcessMgmt", "WSNMgmt" ] }, "totalsize" : 4, "version" : 1.0.0" } }
Account Management
Accounts
The following resources are applicable:
- /AccountMgmt
- /AccountMgmt/acuntName/<name>
Item | Description |
---|---|
totalsize | Number of items in the result. |
username | Account name. |
password | Account password, but will not show real password. |
lastchange | Account last change time. |
Table 4.1.1 (a)
- /AccountMgmt
GET
Retrieve all accounts information.
Request :
Ex:
curl -H "Content-Type: application/json" -X GET http://username:password@172.22.12.34/restapi/AccountMgmt
Response Body: (media type: application/json)
{ "result" : { "item" : [ { "password" : "$1$44809109$pK1LHNBwMNRL1T5OHTLl3.", "lastchange" : "1444809109", "username" : "admin" } ], "totalsize" : 1 } }
PUT
Change account password.
Required fields: username, password Request Body: (media type: application/json)
{ "username":"admin", "password":"1234" }
Ex:
curl -H "Content-Type: application/json" -X PUT -d '{ "username":"admin", "password":"1234"}' http://username:password@172.22.12.34/restapi/AccountMgmt
Response Body: (media type: application/json)
{ "result" : "true" }
- /AccountMgmt/acuntName/<name>
GET
Retrieve specific account information by account name.
Request :
Ex:
curl -H "Content-Type: application/json" -X GET http://username:password@172.22.12.34/restapi/AccountMgmt/acuntName/admin
Response Body: (media type: application/json)
{ "result" : { "item" : { "username" : "admin", "password" : "$1$44613844$SHHhya9WJ72FSD17OG6SE/", "lastchange" : "1443662918" } } }
PUT
Change specific account password.
Required fields: password
Request Body: (media type: application/json)
{ "password":"1234" }
Ex:
curl -H "Content-Type: application/json" -X PUT -d '{ "password":"1234"}' http://username:password@172.22.12.34/restapi/AccountMgmt/acuntName/admin
Response Body: (media type: application/json)
{ "result" : "true" }
System Management
Management
The following resources are applicable:
- /SystemMgmt
- /SystemMgmt/SystemInfo
- /SystemMgmt/NetworkInfo
- /SystemMgmt/NetworkConfig
- /SystemMgmt/Action
Item | Description |
---|---|
ipaddr | Device IP address. |
netmask | Device Netmask. |
iface | Device Network Interface name. |
gateway | Device Default Gateway. |
hostname | Device Hostname. |
dns | Name server setting. |
hwaddr | Device MAC address. |
os | Device OS version. |
systemtime | Device System time. |
cpuusage | Device CPU usage. |
cputype | Device CPU type. |
memusage | Device memory usage. |
memsize | Device memory size. |
diskusage | Device disk usage. |
disksize | Device disk size. |
swapusage | Device swap usage. |
swapsize | Device swap size. |
arch | Device architecture. |
uptime | Device uptime. |
webmin | Webmin version. |
action | Determine action command. |
value | Determine action parameter. |
Table 4.2.1 (a)
- /SystemMgmt
GET
Retrieve all system information.
Request :
Ex:
curl -H "Content-Type: application/json" -X GET http://username:password@172.22.12.34/restapi/SystemMgmt
Response Body: (media type: application/json)
{ "result" : { "SystemInfo" : { "cputype" : "Intel(R) Core(TM) i3-4030U CPU @ 1.90GHz", "swapsize" : "1.50 GB", "cpuusage" : 0, "swapusage" : 0, "systemtime" : "Mon Oct 5 14:09:14 2015", "memsize" : "1.95 GB", "webmin" : "1.740", "os" : "Linux 3.13.0-43-generic", "memusage" : 53, "uptime" : "0 days, 4 hours, 49 minutes", "disksize" : "234.50 GB", "arch" : "x86_64", "diskusage" : 60 }, "NetworkInfo" : { "dns" : "172.22.2.100", "gateway" : "172.22.15.254", "netmask" : "255.255.252.0", "ipaddr" : "172.22.12.52", "hostname" : "imx6-vm", "hwaddr" : "00:0c:29:22:93:e1", "iface" : "eth0" } } }
- /SystemMgmt/SystemInfo
GET
Retrieve system information.
Request :
Ex:
curl -H "Content-Type: application/json" -X GET http://username:password@172.22.12.34/restapi/SystemMgmt/SystemInfo
Response Body: (media type: application/json)
{ "result" : { "SystemInfo" : { "cpuusage" : 0, "swapsize" : "1.50 GB", "cputype" : "Intel(R) Core(TM) i3-4030U CPU @ 1.90GHz", "webmin" : "1.740", "memsize" : "1.95 GB", "os" : "Linux 3.13.0-43-generic", "systemtime" : "Mon Oct 5 14:09:09 2015", "swapusage" : 0, "memusage" : 53, "uptime" : "0 days, 4 hours, 49 minutes", "arch" : "x86_64", "disksize" : "234.50 GB", "diskusage" : 60 } } }
- /SystemMgmt/NetworkInfo
GET
Retrieve network information.
Request :
Ex:
curl -H "Content-Type: application/json" -X GET http://username:password@172.22.12.34/restapi/SystemMgmt/NetworkInfo
Response Body: (media type: application/json)
{ "result" : { "NetworkInfo" : { "netmask" : "255.255.252.0", "ipaddr" : "172.22.12.52", "hostname" : "imx6-vm", "hwaddr" : "00:0c:29:22:93:e1", "iface" : "eth0", "dns" : "172.22.2.100", "gateway" : "172.22.15.254" } } }
- /SystemMgmt/NetworkConfig
PUT
Edit network settings.
Required fields: iface, method
Request Body: (media type: application/json)
Set static ip for eth0
{ "ipaddr" : "192.168.0.1", "netmask" : "255.255.255.0", "gateway" : "192.168.0.254", "method" : "static", "iface" : "eth0" }
Ex:
curl -H "Content-Type: application/json" -X PUT -d '{"ipaddr":"192.168.0.1","netmask":"255.255.255.0","method":"static","iface":"eth0",”gateway”:”192.168.0.254” }' http://username:password@172.22.12.34/restapi/SystemMgmt/NetworkConfig
Set dynamic ip for eth0
{ "method" : "dhcp", "iface" : "eth0" }
Ex:
curl -H "Content-Type: application/json" -X PUT -d '{"method":"dhcp","iface":"eth0"}' http://username:password@172.22.12.34/restapi/SystemMgmt/NetworkConfig
Set hostname
{ "hostname" : "imx6-dev", }
Ex:
curl -H "Content-Type: application/json" -X PUT -d '{"hostname":"imx6-dev"}' http://username:password@172.22.12.34/restapi/SystemMgmt/NetworkConfig
Response Body: (media type: application/json)
{ "result" : "true" }
- /SystemMgmt/Action
POST
Set device "reboot" by action.
Required fields: action, value
Request Body: (media type: application/json)
{ "action" : "reboot", "value" : 1 }
Ex:
curl -H "Content-Type: application/json" -X POST -d '{ "action":"reboot", "value":1}' http://username:password@172.22.12.34/restapi/SystemMgmt/Action
Response Body: (media type: application/json)
{ "result" : "true" }
Process Management
Processes
The following resources are applicable:
- /ProcessMgmt/Service
- /ProcessMgmt/Service/<name>
Item | Description |
---|---|
total | Number of services in the result. |
name | Service name. |
order | Service startup order. |
onboot | Service on boot or not. |
Table 4.3.1 (a)
- /ProcessMgmt/Service
GET
Retrieve all services information.
Request :
Ex:
curl -H "Content-Type: application/json" -X GET http://username:password@172.22.12.34/restapi/ProcessMgmt/Service
Response Body: (media type: application/json)
{ "result" : { "total" : 19, "service" : [ { "onboot" : 0, "order" : 0, "name" : "alljoyn" }, { "onboot" : 1, "order" : 20, "name" : "apmd" }, { "onboot" : 1, "order" : 21, "name" : "avahi-daemon" }, { "onboot" : 1, "order" : 5, "name" : "connman" }, { "onboot" : 1, "order" : 90, "name" : "crond" }, { "onboot" : 1, "order" : 2, "name" : "dbus-1" }, { "onboot" : 0, "order" : 0, "name" : "dustlink" }, { "onboot" : 1, "order" : 64, "name" : "neard" }, { "onboot" : 1, "order" : 20, "name" : "nfsserver" }, { "onboot" : 1, "order" : 20, "name" : "ntpd" }, { "onboot" : 1, "order" : 22, "name" : "ofono" }, { "onboot" : 1, "order" : 99, "name" : "oprofileui-server" }, { "onboot" : 1, "order" : 99, "name" : "rc.local" }, { "onboot" : 0, "order" : 0, "name" : "rpcbind" }, { "onboot" : 0, "order" : 0, "name" : "saagent" }, { "onboot" : 0, "order" : 0, "name" : "serialmux" }, { "onboot" : 1, "order" : 9, "name" : "sshd" }, { "onboot" : 1, "order" : 99, "name" : "tcf-agent" }, { "onboot" : 1, "order" : 20, "name" : "xinetd" } ] } }
PUT
Edit service settings.
Ex:Set xinetd onboot and order is 20.
Required fields: name, onboot, order.
Request Body: (media type: application/json)
{ "name" : "xinetd", "order" : 20, "onboot" : 1 }
Ex:
curl -H "Content-Type: application/json" -X PUT –d ‘{“name”:”xinetd”,”onboot”:1,”order”:20}’ http://username:password@172.22.12.34/restapi/ProcessMgmt/Service
Ex:Disable xinetd onboot
Required fields: name, onboot.
Request Body: (media type: application/json)
{ "name" : "xinetd", "onboot" : 0 }
Ex:
curl -H "Content-Type: application/json" -X PUT –d ‘{“name”:”xinetd”,”onboot”: 0}’ http://username:password@172.22.12.34/restapi/ProcessMgmt/Service
Response Body: (media type: application/json)
Set xinetd onboot and order is 20
{ "result" : { "order" : 20, "onboot" : 1, "name" : "xinetd" } }
Disable xinetd onboot
{ "result" : { "order" : 0, "onboot" : 0, "name" : "xinetd" } }
POST
Start and Stop service.
Required fields: name, action(start/stop/restart).
Request Body: (media type: application/json)
{ "name" : "xinetd", "action" :”start” }
Ex:
curl -H "Content-Type: application/json" -X POST –d ‘{”name”:”xinetd”,”action”:”start”}’ http://username:password@172.22.12.34/restapi/ProcessMgmt/Service
Response Body: (media type: application/json)
{ "result" : "true" }
- /ProcessMgmt/Service/<name>
GET
Retrieve specific service information by service name.
Request :
Ex:
curl -H "Content-Type: application/json" -X GET http://username:password@172.22.12.34/restapi/ProcessMgmt/Service/xinetd
Response Body: (media type: application/json)
{ "result" : { "onboot" : 1, "order" : 20, "name" : "xinetd" } }
PUT
Edit specific service settings by service name.
Ex: Set xinetd onboot and order is 20.
Required fields: onboot, order
Request Body: (media type: application/json)
{ "order" : 20, "onboot" : 1, }
Ex:
curl -H "Content-Type: application/json" -X PUT –d ‘{”onboot”:1,”order”:20}’ http://username:password@172.22.12.34/restapi/ProcessMgmt/Service/xinetd
Ex:Disable xinetd onboot
Required fields: onboot.
Request Body: (media type: application/json)
{ "name" : "xinetd", "onboot" : 0 }
Ex:
curl -H "Content-Type: application/json" -X PUT –d ‘{”onboot”: 0}’ http://username:password@172.22.12.34/restapi/ProcessMgmt/Service/xinetd
Response Body: (media type: application/json)
Set xinetd onboot and order is 20
{ "result" : { "order" : 20, "onboot" : 1, "name" : "xinetd" } }
Disable xinetd onboot
{ "result" : { "order" : 0, "onboot" : 0, "name" : "xinetd" } }
POST
Start or Stop specific service by service name.
Required fields: action(start/stop/restart).
Request Body: (media type: application/json)
{ "action" :”start” }
Ex:
curl -H "Content-Type: application/json" -X POST –d ‘{”action”:”start”}’ http://username:password@172.22.12.34/restapi/ProcessMgmt/Service/xinetd
Response Body: (media type: application/json)
{ "result" : "true" }
WSN Management
The following resources are applicable:
- /WSNMgmt/Setting
- /WSNMgmt/IoTGW
- /WSNMgmt/IoTGW/WSN
- /WSNMgmt/IoTGW/WSN/<mac addr>
- /WSNMgmt/IoTGW/WSN/<mac addr>/Info
- /WSNMgmt/IoTGW/WSN/<mac addr>/Info/Name
- /WSNMgmt/IoTGW/WSN/<mac addr>/Info/Health
- /WSNMgmt/IoTGW/WSN/<mac addr>/Info/Neighbor
- /WSNMgmt/IoTGW/WSN/<mac addr>/Info/SenHubList
- /WSNMgmt/IoTGW/WSN/<mac addr>/Info/sw
- /WSNMgmt/IoTGW/WSN/<mac addr>/Info/reset
- /WSNMgmt/<mac addr>/SenHub
- /WSNMgmt/<mac addr>/SenHub/Action
- /WSNMgmt/<mac addr>/SenHub/Action/AutoReport
- /WSNMgmt/<mac addr>/SenHub/SenData
- /WSNMgmt/<mac addr>/SenHub/SenData/<sensor name>
- /WSNMgmt/<mac addr>/SenHub/Net
- /WSNMgmt/<mac addr>/SenHub/Net/Health
- /WSNMgmt/<mac addr>/SenHub/Net/Neighbor
- /WSNMgmt/<mac addr>/SenHub/Net/sw
- /WSNMgmt/<mac addr>/SenHub/Info
- /WSNMgmt/<mac addr>/SenHub/Info/Name
- /WSNMgmt/<mac addr>/SenHub/Info/reset
- /WSNMgmt/<mac addr>/SenHub/Info/sw
- /WSNMgmt/Setting
GET
Retrieve the WSN manager setting information.
Request :
Ex:
curl -H "Content-Type: application/json" -X GET http://username:password@172.22.12.34/restapi/WSNMgmt/Setting
Response Body: (media type: application/json)
{ "result" : { "totalsize" : 2, "item" : [ { "JoinKey" : "JOINADVANTECHIOT", "NetID" : "2001", "Interface" : 1 }, { "JoinKey" : "JOINADVANTECHIOT", "NetID" : "2002", "Interface" : 2 } ] } }
- /WSNMgmt/IoTGW
GET
Retrieve all network information.
Request :
Ex:
curl -H "Content-Type: application/json" -X GET http://username:password@172.22.12.34/restapi/WSNMgmt/IoTGW
Response Body: (media type: application/json)
{ "result" : { "WSN" : { "bn" : "WSN", "ver" : 1, "WSN0" : { "bn" : "00170d00006035dd", "Info" : { "e" : [ { "sv" : "00170d00006035dd", "n" : "SenHubList", "asm" : "r" }, { "sv" : "", "n" : "Neighbor", "asm" : "r" }, { "n" : "Health", "v" : 0, "asm" : "r" }, { "sv" : "WSN0", "n" : "Name", "asm" : "r" }, { "sv" : "1.2.1.12", "n" : "sw", "asm" : "r" }, { "bv" : 0, "n" : "reset", "asm" : "rw" } ], "bn" : "Info" }, "ver" : 1 } }, "ver" : 1 } }
- /WSNMgmt/IoTGW/WSN
GET
Retrieve all WSN information.
Request :
Ex:
curl -H "Content-Type: application/json" -X GET http://username:password@172.22.12.34/restapi/WSNMgmt/IoTGW/WSN
Response Body: (media type: application/json)
{ "result" : { "bn" : "WSN", "ver" : 1, "WSN0" : { "bn" : "00170d00006035dd", "Info" : { "e" : [ { "sv" : "00170d00006035dd,00170d0000306265", "n" : "SenHubList", "asm" : "r" }, { "sv" : "00170d0000306265", "n" : "Neighbor", "asm" : "r" }, { "n" : "Health", "v" : 0, "asm" : "r" }, { "sv" : "WSN0", "n" : "Name", "asm" : "r" }, { "sv" : "1.2.1.12", "n" : "sw", "asm" : "r" }, { "bv" : 0, "n" : "reset", "asm" : "rw" } ], "bn" : "Info" }, "ver" : 1 } } }
- /WSNMgmt/IoTGW/WSN/<mac addr>
GET
Retrieve the WSN manager information.
Request :
Ex:
curl -H "Content-Type: application/json" -X GET http://username:password@172.22.12.34/restapi/WSNMgmt/IoTGW/WSN/00170d00006035dd
Response Body: (media type: application/json)
{ "result" : { "bn" : "00170d00006035dd", "Info" : { "e" : [ { "sv" : "00170d00006035dd,00170d0000306265", "n" : "SenHubList", "asm" : "r" }, { "sv" : "00170d0000306265", "n" : "Neighbor", "asm" : "r" }, { "n" : "Health", "v" : 0, "asm" : "r" }, { "sv" : "WSN0", "n" : "Name", "asm" : "r" }, { "sv" : "1.2.1.12", "n" : "sw", "asm" : "r" }, { "bv" : 0, "n" : "reset", "asm" : "rw" } ], "bn" : "Info" }, "ver" : 1 } }
- /WSNMgmt/IoTGW/WSN/<mac addr>/Info
GET
Retrieve the WSN manager information.
Request :
Ex:
curl -H "Content-Type: application/json" -X GET http://username:password@172.22.12.34/restapi/WSNMgmt/IoTGW/WSN/00170d00006035dd/Info
Response Body: (media type: application/json)
{ "result" : { "e" : [ { "sv" : "00170d00006035dd,00170d0000306265", "n" : "SenHubList", "asm" : "r" }, { "sv" : "00170d0000306265", "n" : "Neighbor", "asm" : "r" }, { "n" : "Health", "v" : 0, "asm" : "r" }, { "sv" : "WSN0", "n" : "Name", "asm" : "r" }, { "sv" : "1.2.1.12", "n" : "sw", "asm" : "r" }, { "bv" : 0, "n" : "reset", "asm" : "rw" } ], "bn" : "Info" } }
- /WSNMgmt/IoTGW/WSN/<mac addr>/Info/Name
GET
Retrieve the WSN manager name.
Request :
Ex:
curl -H "Content-Type: application/json" -X GET http://username:password@172.22.12.34/restapi/WSNMgmt/IoTGW/WSN/00170d00006035dd/Info/Name
Response Body: (media type: application/json)
{ "result" : { "sv" : "WSN0", "n" : "Name", "asm" : "r" } }
- /WSNMgmt/IoTGW/WSN/<mac addr>/Info/Health
GET
Retrieve the WSN manager health.
Request :
Ex:
curl -H "Content-Type: application/json" -X GET http://username:password@172.22.12.34/restapi/WSNMgmt/IoTGW/WSN/00170d00006035dd/Info/Health
Response Body: (media type: application/json)
{ "result" : { "n" : "Health", "v" : 100, "asm" : "r" } }
- /WSNMgmt/IoTGW/WSN/<mac addr>/Info/Neighbor
GET
Retrieve the WSN manager neighbors.
Request :
Ex:
curl -H "Content-Type: application/json" -X GET http://username:password@172.22.12.34/restapi/WSNMgmt/IoTGW/WSN/00170d00006035dd/Info/Neighbor
Response Body: (media type: application/json)
{ "result" : { "sv" : "00170d0000306265", "n" : "Neighbor", "asm" : "r" } }
- /WSNMgmt/IoTGW/WSN/<mac addr>/Info/SenHubList
GET
Retrieve the WSN Sensor Hub list.
Request :
Ex:
curl -H "Content-Type: application/json" -X GET http://username:password@172.22.12.34/restapi/WSNMgmt/IoTGW/WSN/00170d00006035dd/Info/SenHubList
Response Body: (media type: application/json)
{ "result" : { "sv" : "00170d00006035dd,00170d0000306265", "n" : "SenHubList", "asm" : "r" } }
- /WSNMgmt/IoTGW/WSN/<mac addr>/Info/sw
GET
Retrieve the WSN manager software information.
Request :
Ex:
curl -H "Content-Type: application/json" -X GET http://username:password@172.22.12.34/restapi/WSNMgmt/IoTGW/WSN/00170d00006035dd/Info/sw
Response Body: (media type: application/json)
{ "result" : { "sv" : "1.2.1.12", "n" : "sw", "asm" : "r" } }
- /WSNMgmt/IoTGW/WSN/<mac addr>/Info/reset
GET
Retrieve the WSN manager reset status.
Request :
Ex:
curl -H "Content-Type: application/json" -X GET http://username:password@172.22.12.34/restapi/WSNMgmt/IoTGW/WSN/00170d00006035dd/Info/reset
Response Body: (media type: application/json)
{ "result" : { "bv" : 0, "n" : "reset", "asm" : "rw" } }
POST
Reset the WSN manager.
Required fields: value
Request Body: (media type: application/json)
{ "bv" : 1 }
Ex:
curl -H "Content-Type: application/json" -X POST -d '{ "bv":1}' http://username:password@172.22.12.34/restapi/WSNMgmt/IoTGW/WSN/00170d00006035dd/Info/reset
Response Body: (media type: application/json)
{ "result" : "true" }
- /WSNMgmt/<mac addr>/SenHub
GET
Retrieve the Sensor Hub information.
Request :
Ex:
curl -H "Content-Type: application/json" -X GET http://username:password@172.22.12.34/restapi/WSNMgmt/00170d0000306265/SenHub
Response Body: (media type: application/json)
{ "result" : { "Net" : { "e" : [ { "n" : "Health", "v" : "100", "asm" : "r" }, { "sv" : "00170d00006035dd", "n" : "Neighbor", "asm" : "r" }, { "sv" : "1.0.00", "n" : "sw", "asm" : "r" } ], "bn" : "Net" }, "Action" : { "e" : [ { "bv" : 0, "n" : "AutoReport", "asm" : "rw" } ], "bn" : "Action" }, "Info" : { "e" : [ { "sv" : "Motion", "n" : "Name", "asm" : "rw" }, { "sv" : "1.0.00", "n" : "sw", "asm" : "r" }, { "bv" : 1, "n" : "reset", "asm" : "rw" } ], "bn" : "Info" }, "ver" : 1, "SenData" : { "e" : [ { "n" : "Ultrasonic", "min" : 15, "exten" : "", "max" : 645, "st" : "ipso", "v" : 0, "asm" : "r", "u" : "cm", "type" : "d", "rt" : "ucum.cm" } ], "bn" : "SenData" } } }
- /WSNMgmt/<mac addr>/SenHub/Action
GET
Retrieve the Sensor Hub available action.
Request :
Ex:
curl -H "Content-Type: application/json" -X GET http://username:password@172.22.12.34/restapi/WSNMgmt/00170d0000306265/SenHub/Action
Response Body: (media type: application/json)
{ "result" : { "e" : [ { "bv" : 0, "n" : "AutoReport", "asm" : "rw" } ], "bn" : "Action" } }
- /WSNMgmt/<mac addr>/SenHub/Action/AutoReport
GET
Retrieve the Sensor Hub AutoReport status.
Request :
Ex:
curl -H "Content-Type: application/json" -X GET http://username:password@172.22.12.34/restapi/WSNMgmt/00170d0000306265/SenHub/Action/AutoReport
Response Body: (media type: application/json)
{ "result" : { "bv" : 0, "n" : "AutoReport", "asm" : "rw" } }
POST
Set the Sensor Hub to AutoReport.
Required fields: value
Request Body: (media type: application/json)
{ "bv" : 1 }
Ex:
curl -H "Content-Type: application/json" -X POST -d '{ "bv":1}' http://username:password@172.22.12.34/restapi/WSNMgmt/00170d0000306265/SenHub/Action/AutoReport
Response Body: (media type: application/json)
{ "result" : "true" }
- /WSNMgmt /<mac addr>/SenHub/SenData
GET
Retrieve the Sensor Hub all sensor data.
Request :
Ex:
curl -H "Content-Type: application/json" -X GET http://username:password@172.22.12.34/restapi/WSNMgmt/00170d0000306265/SenHub/SenData
Response Body: (media type: application/json)
{ "result" : { "e" : [ { "n" : "Ultrasonic", "min" : 15, "exten" : "", "max" : 645, "st" : "ipso", "v" : 0, "asm" : "r", "u" : "cm", "type" : "d", "rt" : "ucum.cm" } ], "bn" : "SenData" } }
- /WSNMgmt /<mac addr>/SenHub/SenData/<sensor name>
GET
Retrieve the Sensor Hub specific sensor data.
Request :
Ex:
curl -H "Content-Type: application/json" -X GET http://username:password@172.22.12.34/restapi/WSNMgmt/00170d0000306265/SenHub/SenData/Ultrasonic
Response Body: (media type: application/json)
{ "result" : { "n" : "Ultrasonic", "min" : 15, "exten" : "", "max" : 645, "st" : "ipso", "v" : 0, "asm" : "r", "u" : "cm", "type" : "d", "rt" : "ucum.cm" } }
- /WSNMgmt/ <mac addr>/SenHub/Net
GET
Retrieve the Sensor Hub network information.
Request :
Ex:
curl -H "Content-Type: application/json" -X GET http://username:password@172.22.12.34/restapi/WSNMgmt/00170d0000306265/SenHub/Net
Response Body: (media type: application/json)
{ "result" : { "e" : [ { "n" : "Health", "v" : "100", "asm" : "r" }, { "sv" : "00170d00006035dd", "n" : "Neighbor", "asm" : "r" }, { "sv" : "1.0.00", "n" : "sw", "asm" : "r" } ], "bn" : "Net" } }
- /WSNMgmt/ <mac addr>/SenHub/Net/Health
GET
Retrieve the Sensor Hub network health.
Request :
Ex:
curl -H "Content-Type: application/json" -X GET http://username:password@172.22.12.34/restapi/WSNMgmt/00170d0000306265/SenHub/Net/Health
Response Body: (media type: application/json)
{ "result" : { "n" : "Health", "v" : "100", "asm" : "r" } }
- /WSNMgmt/ <mac addr>/SenHub/Net/Neighbor
GET
Retrieve the Sensor Hub neighbors.
Request :
Ex:
curl -H "Content-Type: application/json" -X GET http://username:password@172.22.12.34/restapi/WSNMgmt/00170d0000306265/SenHub/Net/Neighbor
Response Body: (media type: application/json)
{ "result" : { "sv" : "00170d00006035dd", "n" : "Neighbor", "asm" : "r" } }
- /WSNMgmt/ <mac addr>/SenHub/Net/sw
GET
Retrieve the Sensor Hub software information about network.
Request :
Ex:
curl -H "Content-Type: application/json" -X GET http://username:password@172.22.12.34/restapi/WSNMgmt/00170d0000306265/SenHub/Net/sw
Response Body: (media type: application/json)
{ "result" : { "sv" : "1.0.00", "n" : "sw", "asm" : "r" } }
- /WSNMgmt/<mac addr>/SenHub/Info
GET
Retrieve the Sensor Hub information.
Request :
Ex:
curl -H "Content-Type: application/json" -X GET http://username:password@172.22.12.34/restapi/WSNMgmt/00170d0000306265/SenHub/Info
Response Body: (media type: application/json)
{ "result" : { "e" : [ { "sv" : "Motion", "n" : "Name", "asm" : "rw" }, { "sv" : "1.0.00", "n" : "sw", "asm" : "r" }, { "bv" : 1, "n" : "reset", "asm" : "rw" } ], "bn" : "Info" } }
- /WSNMgmt/<mac addr>/SenHub/Info/Name
GET
Retrieve the Sensor Hub name.
Request :
Ex:
curl -H "Content-Type: application/json" -X GET http://username:password@172.22.12.34/restapi/WSNMgmt/00170d0000306265/SenHub/Info/Name
Response Body: (media type: application/json)
{ "result" : { "sv" : "Motion", "n" : "Name", "asm" : "rw" } }
POST
Set the Sensor Hub name.
Required fields: value
Request Body: (media type: application/json)
{ "sv" : “MotionNew” }
Ex:
curl -H "Content-Type: application/json" -X POST -d '{ "sv":”MotionNew”}' http://username:password@172.22.12.34/restapi/WSNMgmt/00170d0000306265/SenHub/Info/Name
Response Body: (media type: application/json)
{ "result" : "true" }
- /WSNMgmt/<mac addr>/SenHub/Info/reset
GET
Retrieve the Sensor Hub reset status.
Request :
Ex:
curl -H "Content-Type: application/json" -X GET http://username:password@172.22.12.34/restapi/WSNMgmt/00170d0000306265/SenHub/Info/reset
Response Body: (media type: application/json)
{ "result" : { "bv" : 1, "n" : "reset", "asm" : "rw" } }
POST
Reset the Sensor Hub.
Required fields: value
Request Body: (media type: application/json)
{ "bv" : 1 }
Ex:
curl -H "Content-Type: application/json" -X POST -d '{ "bv":1}' http://username:password@172.22.12.34/restapi/WSNMgmt/00170d0000306265/SenHub/Info/reset
Response Body: (media type: application/json)
{ "result" : "true" }
- /WSNMgmt/<mac addr>/SenHub/Info/sw
GET
Retrieve the Sensor Hub software information about MCU.
Request :
Ex:
curl -H "Content-Type: application/json" -X GET http://username:password@172.22.12.34/restapi/WSNMgmt/00170d0000306265/SenHub/Info/sw
Response Body: (media type: application/json)
{ "result" : { "sv" : "1.0.00", "n" : "sw", "asm" : "r" } }
Use Node-RED to grab information
Check out the following examples.
Retrieve all API resources and API version
- Add a function node
Add a Function node with the following code:
msg.headers = { "Content-type" : "application/json", "Connection" : "close", "Authorization" : "Basic YWRtaW46YWRtaW4=" } return msg;
- Add an HttpRequest node
After adding one to the workspace, edit it to set the URL property to:
http://your_wise3310_ip/restapi/APIInfoMgmt
Retrieve all WSN network information
- Add a function node
Add a Function node with the following code:
msg.headers = { "Content-type" : "application/json", "Connection" : "close" } return msg;
- Add an HttpRequest node
After adding one to the workspace, edit it to set the URL property to:
http://admin:admin@your_wise3310_ip/restapi/WSNMgmt/IoTGW
Use freeboard to grab information
Check out the following examples.
- Add Datasource
http://your_wise3310_ip/restapi/WSNMgmt/00170d0000306265/SenHub/SenData
- Add Pane and Widget
After adding one, edit value from datasource
datasources["WSN"]["result"]["e"][0]["v"]