api | 说明 |
---|---|
AI | 全局挂靠对象 |
AI.devId | 设备id, 从url上获取 |
AI.productKey | 项目key, 从url上获取 |
创建设备轮询实例
轮询getDeviceStatus (获取设备状态)
参数 | 说明 | 类型 |
---|---|---|
callback | 成功回调 | function |
errorCallback | 异常回调 | function |
// 在页面中调用 this.$store.dispatch('deviceStatusPolling') // 停止页面轮询 AI.polling.stop() // 唤醒停止的页面轮询 AI.polling.continue() /** vuex 方法 state.publicInfo * 获取设备状态 */ deviceStatusPolling({ commit }) { AI.deviceStatusPolling((resp) => { // 更新设备状态 commit('updateDeviceStatus', { data: resp.model }) }, (error) => { console.log('[deviceStatusPolling error]', error) }) }, // 返回结果 { "result": { "attributes": [ { "BatteryPercentage": "10", "voltage": "40" } ], "events": [ { "eventName": "lowPower", "param": { } } ], "services": [ "serviceName": "lowPower", "param": { } ] }, "statusCode": 200, "success": true } // 使用 computed 属性实时获取 存在 vuex 中的 设备状态 ...mapState({ // 设备status deviceStatus: state => { return state.publicInfo.attr; }, }),
获取设备状态
// 调用示例 AI.getDeviceStatus().then((resp) => { console.log(resp); // 返回获取的设备状态 }).catch((res) => { console.log('获取设备状态失败返回', res); });
{ "type": "succeed", "code": "SUCCEED", "msg": "调用成功", "model": { "attr": { "mode": 19, "targetHumidity": 0, "angleLR": 0, "angleAutoLROnOff": 0, "humidity": 100, "windspeed": 7, "onlinestate": "online", "humanDetectOnOff": 0, "angleUD": 0, "powerstate": 1, "direction": 0 }, "errorInfo": { }, "scheduleInfo": { } } }
设置设备状态
参数 | 说明 | 类型 |
---|---|---|
devId | 设备id | string |
params | 控制参数 | Object |
// 打开灯 this.$store.dispatch('setDeviceStatus', { powerstate: 'on' })
{ "success": "true", "model": true,//操作是否成功,true为成功,false为失败 "msgInfo": "调用成功", "msgCode": "SUCCESS" }
获取设备完整信息
参数 | 说明 | 类型 |
---|---|---|
devId | 设备id | string |
{ "productInfo":{ "productKey":"887", "devType":"体脂秤" }, "attributes":[ { "attributeEn":"BatteryPercentage", "dataType":{ "specs":{ "unit":"%", "min":"0", "unitName":"百分比", "max":"100" }, "type":"double" }, "attributeCn":"电池电量", "actions":[ "get" ], "required":false }, { "attributeEn":"mode", "dataType":{ "specs":{ "0":"自动模式", "1":"睡眠模式", "2":"制热模式", "3":"制冷模式", "4":"除湿模式" }, "type":"enum" }, "attributeCn":"模式", "actions":[ "get", "set" ], "required":false } ], "events":[ { "outputData":[ { "attributeEn":"BatteryPercentage", "dataType":{ "specs":{ "unit":"%", "min":"0", "unitName":"百分比", "max":"100" }, "type":"double" }, "attributeCn":"电池电量" } ], "eventNameEn":"lowBatteryEvent", "eventNameCn":"低电量事件" } ], "services":[ { "outputData":[ { "attributeEn":"BMI", "dataType":{ "specs":{ "min":"0", "unitName":"无", "max":"500" }, "type":"double" }, "attributeCn":"BMI" }, ], "serviceNameEn":"MeasureBodyFat", "inputData":[ { "attributeEn":"UserAge", "dataType":{ "specs":{ "min":"0", "unitName":"无", "max":"100" }, "type":"int" }, "attributeCn":"用户年龄" }, ], "method":"thing.service.MeasureBodyFat", "serviceNameCn":"测量体脂", "required":false } ] }
获取语料接口
AI.getProductFunctionCorpus().then((resp) => { console.log(resp); // 返回语料信息 }).catch((res) => { console.log('失败返回', res); });
获取产品配置信息 // genie-sdk 1.2.7 以后支持
// ****** 使用接口获取产品信息 AI.getProductInfo().then((resp) => { console.log(resp); // 返回产品配置信息 // resp.model.productIcon // 产品配置图 open平台 -> 人机交互 -> 产品展示图 中配置的 设备图片 // resp.model.name // 设备名称 }).catch((res) => { console.log('失败返回', res); }); // 使用 mapState 从vuex 中获取 (sdk初始化会自动调用) // 产品信息详情 ...mapState({ // 产品信息详情 productInfo: state => { return state.base.productInfo; }, }) // ****** 在 vuex 使用 title 和 img 获取 会有默认图片 <div>{{productInfo.title}}</div> // 设备名称 <img :src="productInfo.img" /> // open平台 -> 人机交互 -> 产品展示图 中配置的 设备图片
获取最近一条定时数据的剩余时间 // genie-sdk 1.2.22 以后支持
// ****** 获取定时数据 AI.getRecentStatusByTimers().then((resp) => { console.log(resp); // 返回定时数据信息 /* { "type": "succeed", "code": "SUCCEED", "msg": "调用成功", "model": { "timerId": "37eb2c4844944fd29ab7bd256f19fb52", "timerType": 2, "timeStamp": 1558029600000, "remainTime": 987, "startAttr": { "powerstate": "on" } } } */ }).catch((res) => { if (res.msgInfo === '查找不到定时数据') { return console.log('查找不到定时数据') } console.log('失败返回', res); });AI.goTiming 前往定时页面
获取设备详情的接口
AI.getDeviceDetail().then((resp) => { console.log(resp); // 返回设备详情信息 }).catch((res) => { console.log('失败返回', res); });
请求mtop接口
参数 | 说明 | 类型 |
---|---|---|
options | 接口选项 | object |
options.api | mtop接口名称 | string |
options.data | 接口参数 | object |
// 调用示例 AI.aiRequestMtopProxy({ api: 'mtop.api....', data: { devId: AI.devId, // 参数示例 productKey: AI.productKey // 参数示例 } }).then((res) => { console.log('返回信息', res); }).catch((res) => { console.log('失败返回', res); });