Api introduction
This document will introduce restful api and socket requests.
Domain request model includes Api and socket(include WeChat socket)
Type
URL
RESTful Api (api-host)
Web Socket (skt-host)
WeChat applet socket (skt-host)
wss://ws-toilet.seeed.cc
The introduction of the RESTful, click here
The introduction to requests and responses, click here
The introduction of web socket:
server use socket.io.
socket.io doc-server
socket.io doc-client
The introduction of the API call relationship
Get all WC position data for your organization or company via the API - The list of position
Get all WC cubicles data by the position ID, via the API - The list of cubicles
Keep long connection for real-time data of the cubicles or meeting rooms via the Socket
Api - The list of positions
GET
{api-host}/v1/lists/positions/:bloc
Get a list of all the toilet positions in a company or organization.
Path Parameters
bloc
string
the unique flag for the company or organization. for example: bloc=361832720401
Query Parameters
type
string
type=1 , get positions list of the WC. type=2, get positions list of the meeting rooms.
{
"code": "0",
"data": [
{
"id": "32", // position id, the unique id for the location of a toilet
"company": "Seeed", // the name of company or organization
"position": "国际E城G栋9楼" // the name of the toilet
}
]
}
Api - The list of cubicles
GET
{api-host}/v1/lists/cubicles/:position_id
Get a list of all the toilet cubicles which the position selected.
Path Parameters
position_id
string
the unique id from <The list of positions> api. for example: position_id=1
{
"code": "0",
"data": [
{
"eui": "sd45fe32", // 设备编号
"gender": "1", // 性别:1男,2女,3其它(如残疾等)
"shape": "1", // 隔间马桶形状:1蹲位,2坐型,3其它
"number": "1", // 隔间编号,如1号隔间
"use_time": "91" // 单位秒,大于0表示正在使用多少秒,小于0表示空闲多少秒
}
]
}
Api - The list of meeting rooms
GET
{api-host}/v1/lists/meetingrooms/:position_id
Get a list of all the meeting rooms which the position selected. A meeting room maybe includes more than one sensor.
Path Parameters
position_id
string
the unique id from <The list of positions> api. for example: position_id=2
{
"code": "0",
"data": [
{
"key": "5C8DB3C40626014921540C3581C16306", // 每个会议室有唯一key,该key可能包含多个sensor
"shape": "3", // 会议室形状,1小会议室,2中型会议室,3大型会议室
"number": "B区大会议室",
"eui": [
{
"eui": "6df54c4d",
"use_time": "-54637"
}
]
}
]
}
Socket - Get the real-time status (cubicles or meeting rooms)
GET
{skt-api}/v1
Get real-time status which the position selected.
Path Parameters
rn
string
room name = position_id, for example: the (client demo)
[
{
"key": "5C8DB3C40626014921540C3581C16306", // 当eui属于会议室,会返回该key
"eui": "sd45fe32", // 设备编号
"use_time": "-1" // 时间秒,大于0使用时长,小于0空闲时长
}
]
client demo (nodejs)
const io = require('socket.io-client') // room name // the room name is the position_id, get position_id from the api (https://toilet.doc.seeed.cc/ - The list of positions) let rn = process.argv[2] || 10 // 客户端需要做好重连策略,如服务端重启服务后,需要客户端主动再连接服务端。 const skt = io(`https://ws-toilet.seeed.cc/v1`, { query: { // 参数 token token: 'toilet' } }) /** * @event connect */ skt.on('connect', () => { console.log('connect successfully, ', ' Socket ID: ', skt.id) }) /** * 加入房间,服务端消息是基于房间发送,加入房间后就能收到消息 * @event joinRoom * @param rn: room name * @callback status: err|true */ skt.emit('joinRoom', rn, function (status) { if (status !== true) { return } /** * 离开房间(客户端需要保持长连接的时候,则不需要离开房间) * @event leaveRoom * @param rn: room name * @function status: err|true */ skt.emit('leaveRoom', rn, function (status) { if (status !== true) { return } // 关闭连接 skt.close() skt.disconnect() }) }) /** * 最新的数据 * @event latestCubicle */ skt.on('latestCubicle', (data) => { console.log('latest cubicle:', data) }) /** * 'transport error' * 'server namespace disconnect' */ skt.on('disconnect', (reason) => { skt.close() console.log('disconnect', reason) }) // normal message skt.on('message', (data) => { console.log('message:', data) }) skt.on('close', function (err) { skt.close() console.log('close', err) }) skt.on('error', function (err) { console.log('error', err) })
If you have any questions, Please contact by the email to
[email protected]
Last updated
Was this helpful?