API-介绍
在进行云平台操作之前需要开启网络权限
1
| <uses-permission android:name="android.permission.INTERNET">
|
登录云平台
基本API
1 2 3 4 5 6 7 8 9 10 11
| private final String baseUrl = "http://api.nlecloud.com";
public NetWorkBusiness netWorkBusiness; netWorkBusiness = new NetWorkBusiness(暂时填写空字符串,新大陆网址); netWorkBusiness.signIn(new SignIn(用户名, 用户密码), new NCallBack<BaseResponseEntity<User>>(获取自己的Context) { @Override protected void onResponse(BaseResponseEntity<User> userBaseResponseEntity) { } });
|
例子
1 2 3 4 5 6 7 8 9 10
| private final String baseUrl = "http://api.nlecloud.com"; netWorkBusiness = new NetWorkBusiness("",baseUrl); netWorkBusiness.signIn(new SignIn(user, pwd), new NCallBack<BaseResponseEntity<User>>(getApplicationContext()) { @Override protected void onResponse(BaseResponseEntity<User> response) {
} });
|
获取Token
1
| response.getResultObj().getAccessToken() 返回一个字符串
|
1 2 3 4 5 6 7 8
| private final String baseUrl = "http://api.nlecloud.com"; netWorkBusiness = new NetWorkBusiness("",baseUrl); netWorkBusiness.signIn(new SignIn(user, pwd), new NCallBack<BaseResponseEntity<User>>(getApplicationContext()) { @Override protected void onResponse(BaseResponseEntity<User> response) { toKen = response.getResultObj().getAccessToken(); } });
|
数据返回实例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| { "ResultObj":{ "UserID":120315, "UserName":"", "Email":"", "Telphone":"15304785660", "Gender":true, "CollegeID":381, "CollegeName":"内蒙古电子信息职业技术学院", "RoleName":"学生", "RoleID":9, "AccessToken":"23327429937D57CD81D8CEBA80CE7770030EC259A26B0FA765E8B191736F9BA8E04A4A7E8EB80C470F7C91281A4440658570B640F709326F3600238571E9781CE2939B873AC3141EB73ADC982FB660AF0D95C82A07DB2C15E637F1B02AA19738E62F18DCF3EC335C98E0073A973FA82F68977E316E379FB3ED94F3F80B638A5A50D740FBE8893E47680A817E4AD792E9698275B692C9D410144592C0D7BC5BB38FC713DC76A6B6EFDF3F7435F6221DE49337A796B4EA67A6E6A3D033E63E35C4D08C05CE2B4F035260D1C751BD31D165EE21164E33F1378648F3FFFE163CB23B", "AccessTokenErrCode":0, "ReturnUrl":null, "DataToken":"8e05d0696611cb7d" }, "Status":0, "StatusCode":0, "Msg":null, "ErrorObj":null }
|
response.getStatus(); 获取状态 1 失败 0 成功 response.getmsg();
获取错误信息 具体的错误 网络问题还是 账户问题
将数据转为Json
输出到TextVime
1 2 3 4 5 6
| Gson gson = new Gson(); Tools.printJson(Text控件名字, gson.toJson(userbaseResponseEntity类型的数据),false);
或 Tools.printJson(Text控件名字, gson.toJson(userbaseResponseEntity类型的数据)); 加false 的话 文本框的数据不会清空 累加
|
查看项目
在具体登录完成后 会返回用户的AccessToken这个很重要
后面都会用到 在做任何操作 查询传感器 查询设备 查询传感器等操作的时候
需要提前做绑定AccessToken 与Url的操作
如下
1 2 3
| NetWorkBusiness netWorkBusiness = new NetWorkBusiness(token,baseUrl); token == 用户的AccessToken baseUrl == 新大陆的云平台api地址
|
API
1 2 3 4 5 6 7 8 9 10
| netWorkBusiness.getProject(项目ID,写 new 会自动生成 监听器); 项目ID图片见下面的图片
netWorkBusiness.getProject("439927", new NCallBack<BaseResponseEntity<ProjectInfo>>(this.getApplicationContext()) { @Override protected void onResponse(BaseResponseEntity<ProjectInfo> projectInfoBaseResponseEntity) { Tools.printJson(dataView,gson.toJson(projectInfoBaseResponseEntity),false); } });
|
项目ID
请求结果
查询单个传感器
netWorkBusiness.getSensor(设备ID,传感器表示符)
1 2 3 4 5 6 7 8
| netWorkBusiness.getSensor("475945", "z_temperature", new NCallBack<BaseResponseEntity<SensorInfo>>(getApplicationContext()) { @Override protected void onResponse(BaseResponseEntity<SensorInfo> sensorInfoBaseResponseEntity) { Tools.printJson(dataView,gson.toJson(sensorInfoBaseResponseEntity));
} });
|
获取名字API
sensorInfoBaseResponseEntity.getResultObj().getApiTag())
获取单位API
sensorInfoBaseResponseEntity.getResultObj().getUnit()
获取传感器数值
sensorInfoBaseResponseEntity.getResultObj().getValue()
1 2 3 4 5 6 7 8 9
| netWorkBusiness.getSensor("475945", "z_temperature", new NCallBack<BaseResponseEntity<SensorInfo>>(getApplicationContext()) { @Override protected void onResponse(BaseResponseEntity<SensorInfo> sensorInfoBaseResponseEntity) { Tools.printJson(dataView,gson.toJson(sensorInfoBaseResponseEntity.getResultObj().getApiTag()),false); Tools.printJson(dataView,gson.toJson(sensorInfoBaseResponseEntity.getResultObj().getUnit()),false); Tools.printJson(dataView,gson.toJson(sensorInfoBaseResponseEntity.getResultObj().getValue()),false);
} });
|
运行效果
查询多个传感器
getDevicesDatas(设备ID,new 自动生成)
1 2 3 4 5 6
| netWorkBusiness.getDevicesDatas("475945", new NCallBack<BaseResponseEntity<List<DeviceDatas>>>(getApplicationContext()) { @Override protected void onResponse(BaseResponseEntity<List<DeviceDatas>> listBaseResponseEntity) { Tools.printJson(dataView,gson.toJson(listBaseResponseEntity)); } });
|