Api 介绍
该文档主要介绍RESTful Api和Socket的调用,文档内容会持续改进完善。
域名host介绍
类型
地址
RESTful Api(api-host)
https://api-toilet.seeed.cc
Web Socket(skt-host)
https://ws-toilet.seeed.cc
WeChat applet Socket (skt-host)
wss://ws-toilet.seeed.cc
RESTful Api的介绍请参考这里
RESTful Api的入参及返回结构请参考这里
Web Socket的介绍:
服务端采用socket.io构建
socket.io doc-server
socket.io doc-client
Api及Socket的调用关系介绍
获取某一个公司或者组织的区域列表,得到区域id(position_id)
通过区域id(position_id)获取该区域下的所有会议室or卫生间列表
通过区域id(position_id)建立以区域id为房间(socket.io room)的长连接
Api - 获取区域列表
GET
{api-host}/v1/lists/positions/:bloc
Path Parameters
bloc
string
代表公司or组织的唯一flag 如某组织A bloc=361832720401
Query Parameters
type
string
type=1,获取卫生间的区域列表 type=2,获取会议室的区域列表
{
"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 - 获取卫生间列表
GET
{api-host}/v1/lists/cubicles/:position_id
获取某一个区域下的卫生间列表
Path Parameters
position_id
string
通过调用区域列表获取的唯一id 如 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 - 获取会议室列表
GET
{api-host}/v1/lists/meetingrooms/:position_id
获取某一区域下的会议室列表
Path Parameters
position_id
string
通过区域列表获取的唯一id 如 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 - 获取实时数据(会议室or卫生间)
GET
{skt-api}/v1
通过socket长连接,获取传感器的实时数据推送
Path Parameters
rn
string
room name,房间号 服务端以一个区域为一个房间单位 rn等值于position_id,如获取到的区域id=3,则rn=3
client demo (nodejs)
示例中为目前全部方法,部分方法包含callback,调用时需要额外注意,否则会请求失败。
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 to
[email protected]
Last updated
Was this helpful?