@cpzxrobot/sdk
v1.0.56
Published
提供给上海正芯数智APP第三方H5应用使用的SDK
Downloads
1,196
Readme
正芯数智SDK
这是提供给上海正芯数智APP第三方H5应用使用的SDK模块,包含相关物联网设备的获取方式和接口功能
1、使用方式
npm i @cpzxrobot/sdk
2、开发指南
2.1、引入包
import cpzxrobot from "@cpzxrobot/sdk"
2.2、配置开发信息
cpzxrobot({
devAuth: "从上海正芯获得的开发临时token",
appCode: "上海正芯分配的App Code",
selectedFarm: {
code: "xxxx",
company_code: "xxxx",
id: 123456,
name: "自定义用户测试的工厂,请从后台根据业务选择合适的工厂",
},
selectedUnit: {
id: 123456,
name: "自定义用户测试的单元,请从后台根据业务选择合适的单元",
workshopName: 'A栋'
},
});
使用上述模板进行sdk初始化
2.2.1、开发时的CORS问题
如果上述配置后,出现调用接口CORS问题,请在初始化增加参数:
baseURL: "/"
并在vite.config.js等开发环境配置文件中配置:
server: {
proxy: {
"/api": {
target: "https://www.cpzxrobot.com/",
changeOrigin: true,
},
},
},
2.3、使用方法
2.3.1、Vue使用方法
在App.vue中调用2.1所示初始化程序,即可完成SDK初始化。
在其他文件中需要使用sdk时,需要
- 引用库
import cpzxrobot from "@cpzxrobot/sdk"
- 调用对应的接口方法,例如
cpzxrobot().factory.workshops(factory_id)
调用接口
主要包入口:
| 调用入口 | 功能说明 | | ----------------------- | -------------------- | | cpzxrobot().factory.xxx | 获得工厂的相关信息 | | cpzxrobot().device.list | 获得常见设备的列表(当没有特殊类型需求时调用),列表接口提供data参数,可以同步获得多个设备的数据,尽量使用该接口获得设备数据 | | cpzxrobot().device.data | 获得设备的数据,该接口用于获取单个设备的详细数据 | | cpzxrobot().device.feedTower.list | 获得料塔设备的列表 | | cpzxrobot().device.xxx | 获得设备的相关信息 | | cpzxrobot().camera.xxx | 获得摄像头的相关信息 | | cpzxrobot().factory.entry| 获得工厂的可显示动态信息 | | cpzxrobot().transport.fodder.getDeviceByFodderld | 获得料单对应的设备 | | cpzxrobot().pigfarm.heatlamp.xxx | 操作保温灯 | | cpzxrobot().device.feedTower.stat | 获得料塔设备的料耗,饲料重量 | | cpzxrobot().pigfarm.unitStat | 获得单元的统计信息,包括每日料耗,饲料消耗,日龄,存栏量等 | | cpzxrobot().pigfarm.heatlamp.set | 设置保温灯的当前工作日龄,调用时,action传"dayage",argc传天数 | | cpzxrobot().pigfarm.heatlamp.switch | 设置保温灯的当前工作日龄,调用时,action"on"或"off" | | cpzxrobot().pigfarm.heatlamp.iotFields | 获取保温灯用于获取iot的字段列表 |
工厂信息接口
cpzxrobot().factory.workshops(factory_id)
获得工厂的所有车间
入参:
factory_id: 工厂id
cpzxrobot().factory.units(factory_id)
获得工厂的所有单元
入参:
factory_id: 工厂id
摄像头相关
cpzxrobot().camera.search(args)
搜索摄像头
入参:
入参为json object,可接受多种参数中的一个
如果入参为:{unit_id:xxx}则按单元搜索
如果入参为:{factory_id:xxx}则按工厂搜索
如果入参为:{workshop_id:xxx}则按车间搜索
如果入参为Unit对象,则按Unit对象的id进行搜索
app功能相关
cpzxrobot().saveBlob(blob,filname)
保存blob为文件
cpzxrobot().saveBase64(base64,filename)
保存Base64内容为文件
保温灯相关接口
heatlamp 属性提供了一组方法,用于管理猪场的热灯配置。它包含以下方法:
cpzxrobot().pigfarm.heatlamp.add(unit, data):添加新的热灯配置。 cpzxrobot().pigfarm.heatlamp.list(unit):列出指定单元的所有热灯配置。 cpzxrobot().pigfarm.heatlamp.get(id):获取指定 ID 的热灯配置。 cpzxrobot().pigfarm.heatlamp.update(lamp):更新热灯配置。