-
Notifications
You must be signed in to change notification settings - Fork 64
API Documentation
There're two kinds of tokens: user token and node token.
The /node/* API calls need node token specified.
- with query string: xxxx/xxxx?access_token=[your token here]
- with "Authorization" header: Authorization: token [your token here]
Arguments in post body must be specified in application/x-www-form-urlencoded format: arg1=xxx&arg2=xxx, application/json and multipart/form-data are not accepted.
Access with User Token
curl -d email=[email here] -d password=[password here] https://iot.yuzhe.me/v1/user/create
response:
{"status": 200, "msg": "User created", "token": "9L0_ofzPHnan91UQbtcCS4KzCI8BGQk6-OgMOtmnI3Q"}
curl -d password=[new password here] https://iot.yuzhe.me/v1/user/changepassword?access_token=9L0_ofzPHnan91UQbtcCS4KzCI8BGQk6-OgMOtmnI3Q
response:
{"status": 200, "msg": "Password changed, new token is given", "token": "aKleqQebIsjmQMSCokemtgNXMD4Y7OTe3uyzEL1iwwA"}
If you forget your password, you can retrieve it by this API. You should specify the right email address, otherwise you will not receive the email with new password attached.
curl -d email=[new email here] https://iot.yuzhe.me/v1/user/retrievepassword
response:
{"status": 200, "msg": "The password has been sent to your email address\n"}
curl -d email=[email here] -d password=[password here] https://iot.yuzhe.me/v1/user/login
response:
{"status": 200, "msg": "Logged in", "token": "aKleqQebIsjmQMSCokemtgNXMD4Y7OTe3uyzEL1iwwA"}
Access with User Token
curl -H "Authorization: token aKleqQebIsjmQMSCokemtgNXMD4Y7OTe3uyzEL1iwwA" -d name=node_1 https://iot.yuzhe.me/v1/nodes/create
response:
{"status": 200, "msg": "Node created", "node_key": "85a7c2b2fd97c357137414733e65d516", "node_sn": "200d8a94ac5f0905e1fbf9acdfcaba78"}
curl -H "Authorization: token aKleqQebIsjmQMSCokemtgNXMD4Y7OTe3uyzEL1iwwA" https://iot.yuzhe.me/v1/nodes/list
response:
{"status": 200, "msg": "", "nodes": [{"node_key": "d6d68b4b6b43f213569f5832dd8277b2", "name": "node_1", "node_sn": "f70fd643b73f0c721b007ce453bafddd"}, {"node_key": "85a7c2b2fd97c357137414733e65d516", "name": "node_2", "node_sn": "200d8a94ac5f0905e1fbf9acdfcaba78"}]}
curl -H "Authorization: token aKleqQebIsjmQMSCokemtgNXMD4Y7OTe3uyzEL1iwwA" -d name=node_2 https://iot.yuzhe.me/v1/nodes/rename
response:
{"status": 200, "msg": "Node renamed", "name": "node_2"}
curl -H "Authorization: token StiLU1g5SNfQYWQLKpB7uMuE4l2uQuamKMBsIW1RGgA" https://iot.yuzhe.me/v1/nodes/delete -d "node_sn=bac0df2d1b01b32c8ad3a0efbfc31c5f"
response:
{"status": 200, "msg": "Node deleted"}
Access with User Token
curl -H "Authorization: token aKleqQebIsjmQMSCokemtgNXMD4Y7OTe3uyzEL1iwwA" https://iot.yuzhe.me/v1/scan/drivers
response:
The contents of database.json as showed
curl -H "Authorization: token aKleqQebIsjmQMSCokemtgNXMD4Y7OTe3uyzEL1iwwA" https://iot.yuzhe.me/v1/scan/status
response:
{"status":"OK", "msg":"scanned 1 grove drivers at 2015-05-30 00:25:30.229032"}
or
{"status":"Failed", "msg":"Fail cause"}
Access with Node Token
".well-known" API prints all the available resources on that node.
curl -H "Authorization: token d6d68b4b6b43f213569f5832dd8277b2" https://iot.yuzhe.me/v1/node/.well-known
response:
{"status": 200, "msg": [
"GET /v1/node/GroveAccMMA7660/accelerometer -> float: ax, float: ay, float: az",
"GET /v1/node/Grove_Example1/with_arg/int_arg -> float: cx, float: cy, float: cz, int: degree",
"POST /v1/node/Grove_Example1/float_value <- float f",
"HasEvent Grove_Button1 button_pressed",
"POST /v1/node/Grove_Gyro_ITG3200/zerocalibrate <- void"]}
The items on the right of the right arrow "->" are the properties that you can read via that API call, while the items on the right of the left arrow "<-" are the values that you can write to that method/action.
"HasEvent" keyword indicates that there's a particular event which will be reported by that grove module, you can receive an explicit semantic event message from the event reporting websocket, e.g. {u'msg': {u'button_pressed': u'0'}} which means the button attached to GPIO0 is pressed.
Read a specified property of a specified grove instance on that node, returns the json expression of the property.
Note: Get to know the type of arguments with .well-known API output
curl -H "Authorization: token d6d68b4b6b43f213569f5832dd8277b2" https://iot.yuzhe.me/v1/node/Grove_Example1/temp
curl -H "Authorization: token d6d68b4b6b43f213569f5832dd8277b2" https://iot.yuzhe.me/v1/node/Grove_Example1/with_arg/90
response:
{"status": 200, "msg": {"temp": 30}}
{"status": 200, "msg": {"cz": 78.0, "cy": 45.6, "cx": 12.3, "degree": 90}}
Write or set the value to a specified property/method/action of a specified grove instance on that node. By writting, you can pass data down to the grove hardware ,or trigger an action, or do some configuration onto the hardware.
Note: Get to know the type of arguments with .well-known API output
Note2: Only this API supports application/json post body.
curl -H "Authorization: token d6d68b4b6b43f213569f5832dd8277b2" -d "{\"f\":10.5}" https://iot.yuzhe.me/v1/node/Grove_Example1/float_value
curl -H "Authorization: token d6d68b4b6b43f213569f5832dd8277b2" -d "a=10&b=10.5&c=445566" https://iot.yuzhe.me/v1/node/Grove_Example1/multi_value
response:
{"status": 200, "msg": "OK"}
{"status": 200, "msg": "Failed"}
This API let user retrieve the last config file which is in the format of yaml.
curl -H "Authorization: token d6d68b4b6b43f213569f5832dd8277b2" https://iot.yuzhe.me/v1/node/config
response:
{"status": 200, "msg": "Grove_Relay:\r\n name: Grove_Relay\r\n construct_arg_list:\r\n pin: 12\r\n"}
If you want to get the node event at any time, you should open a websocket in the client's background. After, send the Node Key to complete the handshake. Like this:
<script>
var ws = new WebSocket'wss://iot.yuzhe.me/v1/node/event');
ws.onopen = function() {
ws.send("d6d68b4b6b43f213569f5832dd8277b2");
};
ws.onmessage = function (evt) {
alert(evt.data);
};
</script>
Then, the onmessage
will get event data when node post it.
The event data format like this:
{'event_name_here': 'event_data_here'}