# 设备

# (一)概述

设备数据是登记在门户系统中的物联产品。

# (二)设备集合[DeviceSet]

设备集合是设备要素的集合,用户可按实际需求将不同设备要素划分到不同的设备集合中去。每个设备仅能从属于一个设备集合。其常用属性如下:

属性名 值类型 属性描述
name String 设备集合名称
remark String 备注
icon Icon 图标
symbol PointSymbol 点符号
deviceProduct DeviceProduct 设备产品分类
isPublish Boolean 是否发布

常用方法如下:(get/set方法略)

方法名 返回类型 方法描述
queryDevices Promise< QueryResult > 查询集合下的所有设备要素
createDevice Promise< DeviceFeature > 创建设备
updateDevice void 更新设备信息
deleteDevice void 删除设备
queryMonitorConfig void 获取监控量配置信息

# 1、获取设备集合

初始化成功后,可直接从Cellsys的organization对象中获取到组织下所有的设备集合。

/*执行初始化成功后,可直接获取到设备集合*/
let deviceSets = Cellsys.organization.deviceSets;
if (deviceSets.length > 0) {
    let deviceSet = deviceSets[0];
    let name = deviceSet.name;//集合名称
    let remark = deviceSet.remark;//集合备注信息
    let deviceProduct = deviceSet.deviceProduct;
    let icon = deviceSet.icon;//获取图标对象
    let pointSymbol = deviceSet.symbol;//获取地图符号对象
}
1
2
3
4
5
6
7
8
9
10

# (1)获取监控量配置信息

不同的设备产品有不同的监测功能,提供不同的监控量信息。如 产品-温湿度传感器 会提供“温度”、“湿度”两种监控量。而升级版产品-野外气象站,除了“温度”、“湿度”外,还会提供“光照强度”、“风向”、“风速”等监控量。

而这些配置信息可以从设备集合对象中查询。查询方法如下:

//实例化查询配置,代表当前查询第1页数据,1页10条数据
let queryConfig = new Cellsys.QueryConfig(1, 10); 

//查询配置信息
deviceSet.queryMonitorConfig(queryConfig)
    .then(queryResult => {
        let monitorConfigs = queryResult.data;
        if (monitorConfigs.length > 0) {
            for (let monitorConfig of monitorConfigs) {
                let monitorMetaDatas = monitorConfig.monitorMetaDatas;
                for (let monitorMetaData of monitorMetaDatas) {
                    let name = monitorMetaData.name;//监控值名称,例:温度
                    let key = monitorMetaData.key;//监控值key,例:temperture
                    let unit = monitorMetaData.measureUnit;//监控值单位,可能为null,例:℃
                    if (unit == null) {
                        //没有单位
                    } else {
                        //有单位
                    }
                    let formatType = monitorMetaData.formatType;//数据格式类型,可能为null
                    if (formatType === null) {
                        //常规数据格式(Number型数据)
                    } else if (formatType === "datetime") {
                        //时间类型数据(要求数据类型为时间戳)
                    } else if (formatType === "dict") {
                        //字典类型(要求数据类型为整形的字典ID)
                    } else {
                        //未定义的异常数据
                    }
                }
            }
        }
    })
    .catch(error => {
        console.log(error.code)
        console.log(error.message)
    })

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

# 2、新增设备集合

设备集合通过组织[Organization]对象创建。具体操作见代码示例:

/*使用默认图标创建设备集合*/
let deviceProduct = Cellsys.DeviceProduct.Locator;//要创建的设备集合所属的设备产品
Cellsys.organization.createDeviceSet({
        "name": "集合名称",
        "remark": "集合描述",
        "deviceProduct": deviceProduct
    })
    .then(deviceSet => {
        let newdeviceSet = deviceSet; //创建成功后会返回创建的事件集合对象
    })
    .catch(error => {
        console.log(error.code)
        console.log(error.message)
    })

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

# 3、修改设备集合

设备集合通过组织[Organization]对象修改。具体操作见代码示例:

deviceSet.setName("修改名称");
deviceSet.setRemark("修改备注");
deviceSet.setPublish(true);//修改发布状态
Cellsys.organization.updateDeviceSet(deviceSet)
    .then(() => {
        //修改成功
        let name = deviceSet.name;//修改后的名称
        let remark = deviceSet.remark;//修改后的备注
    })
    .catch(error => {
        console.log(error.code)
        console.log(error.message)
    })

1
2
3
4
5
6
7
8
9
10
11
12
13
14

# 4、删除设备集合

设备集合通过组织[Organization]对象删除。具体操作见代码示例:

Cellsys.organization.deleteDeviceSet(deviceSet)
    .then(() => {
        //删除成功
    })
    .catch(error => {
        console.log(error.code)
        console.log(error.message)
    })

1
2
3
4
5
6
7
8
9

# (三)设备要素[DeviceFeature]

一个实体设备可用一个设备要素对象表示。其常用属性如下:

属性名 值类型 属性描述
name String 设备集合名称
remark String 备注
icon Icon 图标
symbol PointSymbol 点符号
location Location 设备位置
bluetoothMac MacAddress 设备蓝牙Mac地址
bindMember CommonInfo 设备关联人员的简易信息

设备要素的常用方法如下:(get/set方法略)

方法名 返回类型 方法描述
queryMonitorReports Promise< QueryResult > 查询监控量报告
queryBindMember Promise< QueryResult > 查询具体的关联人员信息

# 1、获取设备要素

设备集合[DeviceSet]提供了query方法来查询自身集合中的设备要素。具体操作见代码示例:

//实例化查询配置,代表当前查询第1页数据,1页10条数据
let queryConfig = new Cellsys.QueryConfig(1, 10); 

deviceSet.queryDevices(queryConfig)
    .then((queryResult) => {
        /*分页信息-查询方法特有*/
        let pageInfo = queryResult.pageInfo;//查询接口特有的分页信息
        let totalCount = pageInfo.totalCount;//数据总数
        let totalPage = pageInfo.totalPage;//总页数
        let pageNo = pageInfo.pageNo;//当前页码(从1开始)
        let pageSize = pageInfo.pageSize;//每页查询数量(注意!不一定和当前查询的数据总量匹配)
                     
        /*获取查询结果*/
        let deviceFeatures = queryResult.data;
        if (deviceFeatures.length > 0) {
            for (let deviceFeature of deviceFeatures) {
                /*设备要素基础信息获取示例*/
                let name = deviceFeature.name;//设备要素名称
                let remark = deviceFeature.remark;//备注
                let pointSymbol = deviceFeature.symbol;//路线符号
                let location = deviceFeature.location;//设备位置,可能为null
                let macAddress = deviceFeature.bluetoothMac;
                let mac = macAddress.formatString;//formatString是带冒号的标准格式,如:10:51:1C:65:48:3E
                let bindMemberInfo = deviceFeature.bindMember; //该设备绑定成员的简单信息
                let binderName = bindMemberInfo.name;//绑定人姓名
            }
        }
    })
    .catch(error => {
        console.log(error.code)
        console.log(error.message)
    })

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

# (1)获取监控量报告[MonitorReport]

登记在[Cellsys 时空管理平台](广州空天通讯技术服务有限公司 (airkoon.com) (opens new window))上的物联产品中,有通讯联网(包括互联网、卫星通讯、其他无线通讯技术)能力的设备可将数据回传到云设备上,形成监控报告。目前监控报告主要由传感器产品回传,显示产品监测到的环境数值。

//实例化查询配置,代表当前查询第1页数据,1页10条数据
let queryConfig = new Cellsys.QueryConfig(1, 10); 

deviceFeature.queryMonitorReports(queryConfig)
    .then((queryResult) => {
        let monitorReports = queryResult.data;
        if (monitorReports.length > 0) {
            for (let monitorReport of monitorReports) {
                /*监控报告数据*/
                let dateTime = monitorReport.reportTime;//监控报告汇报时间
                let monitorItems = monitorReport.monitorItems;
                for (let monitorItem of monitorItems) {
                    let formatString = monitorItem.getFormatString();//监控报告项的格式化输出(不同报告项有不同的输出结果)。用于界面显示。例:99.3%
                    let name = monitorItem.name;//监控量名称。例:电量
                    let value = monitorItem.value;//监控量数值。例99.3
                    let unit = monitorItem.measureUnit;//监控量单位。例:%
                }
            }
        }
    })
    .catch(error => {
        console.log(error.code)
        console.log(error.message)
    })
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

# (2)查询绑定的成员

注意:一个设备只能与一个成员进行关联绑定。当有其他成员绑定设备时,会自动与之前的成员解绑。

deviceFeature.queryBindMember()
    .then(queryResult => {
        let memberFeature = object.data[0];//绑定人信息
    })
    .catch(error => {
        console.log(error.code)
        console.log(error.message)
    })
1
2
3
4
5
6
7
8

# (3)设备Mac

let bluetoothMac = deviceFeature.bluetoothMac;//设备Mac信息
let formatStringMac = bluetoothMac.formatString;//带冒号的标准格式,例:AA:BB:CC:DD:EE:FF
let valueMac = bluetoothMac.value;//不带冒号,例:AABBCCDDEEFF
1
2
3

设备的Mac地址使用MacAddress类,可避免设备Mac字符串格式不统一问题。

# (4)设备定位

let location = deviceFeature.location;//设备定位信息
let mapPoint = location.mapPoint;//定位坐标
let coordinateSystem = mapPoint.coordinateSystem;//定位坐标系
let latitude = mapPoint.latitude;//纬度
let longitude = mapPoint.longitude;//经度

let dateTime = location.time;//定位时间
let timeStamp = dateTime.value;//定位时间的时间戳格式(毫秒级)
let timeFormat = dateTime.toFormatString();//定位时间,"yyyy-MM-dd HH:mm:ss"格式
1
2
3
4
5
6
7
8
9

Location定位类,同时包含定位坐标、定位时间两样数据。

# 2、新增设备要素

设备集合[DeviceSet]提供了create方法来新增自身集合中的设备要素。具体代码示例如下:

let mac = new Cellsys.MacAddress("10521C635214");//以Mac地址10:52:1C:63:52:14为例
deviceSet.createDevice({
        "name": "设备名称",
        "remark""设备描述",
        "mac": mac
    })
    .then(deviceFeature => {
        //创建成功,返回创建的设备对象
        let name = deviceFeature.name;
        let remark = deviceFeature.remark;
    })
    .catch(error => {
        console.log(error.code)
        console.log(error.message)
    })
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

# 3、修改设备要素

设备集合[DeviceSet]提供了update方法来修改自身集合中的设备要素。具体代码示例如下:

deviceFeature.setName("修改后名称");
deviceFeature.setRemark("修改后备注");
deviceSet.updateDevice(deviceFeature)
    .then(deviceFeature => {
       //修改成功,相应修改已同步到eventFeature对象
    })
    .catch(error => {
        console.log(error.code)
        console.log(error.message)
    })
1
2
3
4
5
6
7
8
9
10

# 4、删除设备要素

设备集合[DeviceSet]提供了delete方法来修改自身集合中的设备要素。具体代码示例如下:

deviceSet.deleteDevice(deviceFeature)
    .then(deviceFeature => {
        //删除成功
    })
    .catch(error => {
        console.log(error.code)
        console.log(error.message)
    })

1
2
3
4
5
6
7
8
9

# 5、设备的绑定与解绑

设备与成员的绑定、解绑操作有成员要素[MemberFeature]发起,具体操作参考07-成员与群组成员操作部分

/*首先需要获取到设备绑定的成员要素*/
let memberFeature;
deviceFeature.queryBindMember()
    .then(queryResult => {
        memberFeature = object.data[0];//绑定人信息
    })
    .catch(error => {
        console.log(error.code)
        console.log(error.message)
    })
    
/*设备绑定*/
memberFeature.bindDevice(deviceFeature)
    .then(() => {
        //绑定成功
    })
    .catch(error => {
        console.log(error.code)
        console.log(error.message)
    })

/*设备解绑*/
memberFeature.unbindDevice(deviceFeature)
    .then(() => {
       //解绑成功
    })
    .catch(error => {
        console.log(error.code)
        console.log(error.message)
    })
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30