前面的叨叨:由于阿里云的飞燕平台刚推出不久所以很多问题网上都没解决方案,所以只能通过发送工单去解决,譬如说想创立一个自己品牌的App在导入代码这一步就出现了问题,由于某些原因我们并不能fq,但在导入sdk的同时报错了google的错误,本来以为是缺了jar,但咨询后发现sdk加上的那两句代码其实是无用的。注释掉

/* implementation 'com.google.android.gms:play-services-auth:15.0.1'*/就可以了。

不知是不是安卓系统的原因还是网络原因这个sdk的demo不太稳定,亲测在安卓低版本下会出现登录不成功的原因和闪退情况。

sdk里提供了一个入口的例子操作可借鉴。

package com.aliyun.iot.ilop.demo.page.ilopmain;import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;import com.aliyun.alink.linksdk.tmp.TmpSdk;
import com.aliyun.alink.linksdk.tmp.api.OutputParams;
import com.aliyun.alink.linksdk.tmp.device.panel.PanelDevice;
import com.aliyun.alink.linksdk.tmp.device.panel.listener.IPanelCallback;
import com.aliyun.alink.linksdk.tmp.device.panel.listener.IPanelEventCallback;
import com.aliyun.alink.linksdk.tmp.listener.IDevListener;
import com.aliyun.alink.linksdk.tmp.utils.ErrorInfo;
import com.aliyun.iot.aep.sdk.framework.AActivity;
import com.aliyun.iot.demo.R;
import com.aliyun.iot.ilop.demo.dialog.HSVDialog;
import com.aliyun.iot.ilop.demo.page.bean.EventCallbackbean;
import com.aliyun.iot.ilop.demo.page.bean.PalettesDialogBean;
import com.aliyun.iot.ilop.demo.page.bean.RequestInvokeServiceBean;
import com.aliyun.iot.ilop.demo.page.bean.RequestPropertiesBean;
import com.aliyun.iot.ilop.demo.page.bean.ResponsePropertiesBean;
import com.aliyun.iot.ilop.demo.page.bean.StatusBean;
import com.aliyun.iot.ilop.demo.utils.ColorTools;
import com.aliyun.iot.ilop.demo.view.CircleView;
import com.aliyun.iot.ilop.demo.view.LampsSwitchView;
import com.aliyun.iot.ilop.demo.view.SimpleToolBar;
import com.google.gson.Gson;
import com.taobao.accs.utl.ALog;import java.util.List;public class LampsActivity extends AActivity {private static final String TAG = "LampsActivity";private static final String OFF_LINE_HINT = "设备离线,无法操作";private SimpleToolBar simpleToolBar;private LinearLayout palettesLl;private CircleView hsvCircleView;private String iotId;private PanelDevice panelDevice;private LampsSwitchView leftLampsSwitchView, rigthLampsSwitchView;private TextView statusTv;private Gson gson;private ResponsePropertiesBean responsePropertiesBean;private RequestPropertiesBean requestPropertiesBean = new RequestPropertiesBean();private boolean rightOnLineFlag;private boolean leftOnLineFlag;private static int requestCode = 96;public static int finishResultCode = 97;public static int titleResultCode = 98;private String title;private int status = 0;private boolean firstPropertiesFlag = false;@Overrideprotected void onCreate(Bundle bundle) {super.onCreate(bundle);setContentView(R.layout.lamps_activity);initView();initData();initToolBar();initSdk();}@Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent data) {super.onActivityResult(requestCode, resultCode, data);if (requestCode == this.requestCode && resultCode == this.finishResultCode) {finish();}if (requestCode == this.requestCode && resultCode == this.titleResultCode) {title = data.getStringExtra("title");simpleToolBar.setTitle(title);}}/*** initView**/private void initView() {simpleToolBar = findViewById(R.id.lamps_toolbar);palettesLl = findViewById(R.id.lamps_palettes_ll);palettesLl.setOnClickListener(onPalettesClick);hsvCircleView = findViewById(R.id.lamps_palettes_circle);leftLampsSwitchView = findViewById(R.id.lamps_lamps_left_lsv);rigthLampsSwitchView = findViewById(R.id.lamps_lamps_right_lsv);statusTv = findViewById(R.id.lamps_lamps_status_tv);gson = new Gson();leftLampsSwitchView.setOnClickListener(v -> {if (status == 0) {Toast.makeText(this, OFF_LINE_HINT, Toast.LENGTH_SHORT).show();return;}requestPropertiesBean.getItems().setLightSwitch(switchOpposite(requestPropertiesBean.getItems().getLightSwitch()));setProperties(requestPropertiesBean);});rigthLampsSwitchView.setOnClickListener(v -> {if (status == 0) {Toast.makeText(this, OFF_LINE_HINT, Toast.LENGTH_SHORT).show();return;}//翻转开关RequestInvokeServiceBean bean = new RequestInvokeServiceBean(iotId, "reverseSwitch",new RequestInvokeServiceBean.Args(1));invokeService(gson.toJson(bean));});}public int switchOpposite(int statues) {if (statues == 0) return 1;return 0;}/*** toolbar**/private void initToolBar() {simpleToolBar.setTitle(title).setTitleColor(Color.WHITE).setBack(true).setMenu(true).isShowBottomLine(false).setBackGround(Color.TRANSPARENT).setOnToolBarClickListener(new SimpleToolBar.OnToolBarClickListener() {@Overridepublic void onBackClick(View var1) {finish();}@Overridepublic void onTitleClick(View var1) {}@Overridepublic void onMenuClick(View var1) {Intent intent = new Intent(LampsActivity.this, EquipmentSettingActivity.class);intent.putExtra("iotId", iotId);intent.putExtra("title", title);startActivityForResult(intent, requestCode);}});leftLampsSwitchView.setTitle("主灯开关");rigthLampsSwitchView.setTitle("翻转开关");}private void initData() {iotId = getIntent().getStringExtra("iotId");title = !TextUtils.isEmpty(getIntent().getStringExtra("title")) ?getIntent().getStringExtra("title") :"智能灯";requestPropertiesBean.setIotId(iotId);firstPropertiesFlag = false;}private void initSdk() {
//        设备创建panelDevice = new PanelDevice(iotId);
//        初始化panelDevice.init(this, initCallback);TmpSdk.getDeviceManager().discoverDevices(null, false, 5000, new IDevListener() {@Overridepublic void onSuccess(Object o, OutputParams outputParams) {}@Overridepublic void onFail(Object o, ErrorInfo errorInfo) {}});}/*** 上报 (第一次给虚拟设备设置相关属性)*/private void setFirstProperties() {firstPropertiesFlag = true;RequestPropertiesBean.Items.HSVColor color = new RequestPropertiesBean.Items.HSVColor(0.0948, 1.0000, 1.0000);RequestPropertiesBean bean = new RequestPropertiesBean(iotId, new RequestPropertiesBean.Items(0, 0, color));setProperties(bean);}/*** 获取状态*/public void getEqStatus() {panelDevice.getStatus(statusCallback);}/*** 获取设备属性*/public void getProperties() {ALog.d(TAG, "getProperties");panelDevice.getProperties(getEqPropsCallBack);}/*** 设置设备属性*/public void setProperties(RequestPropertiesBean bean) {String params = gson.toJson(bean, RequestPropertiesBean.class);ALog.d(TAG, "==params==" + params);panelDevice.setProperties(params, setEqPropsCallBack);}/*** 调用服务*/public void invokeService(String params) {panelDevice.invokeService(params, invokeServiceCallBack);}/*** 订阅所有事件*/public void subAllEvents() {ALog.d(TAG, "subAllEvents");panelDevice.subAllEvents(eventCallback, (b, o) -> ALog.d(TAG, b + "subAllEvents==" + String.valueOf(o)));}/*** 调色板LinearLayout点击事件**/private View.OnClickListener onPalettesClick = v -> {if (status == 0) {Toast.makeText(this, OFF_LINE_HINT, Toast.LENGTH_SHORT).show();return;}HSVDialog.getInstance().showMenuDialog(this, queryColor(responsePropertiesBean), ((arr, position) -> {//设置颜色hsvCircleView.setColor(arr.get(position).getColor());// 发给服务端HSV颜色float[] hsv = arr.get(position).getHsv();requestPropertiesBean.getItems().setHSVColor(new RequestPropertiesBean.Items.HSVColor(hsv));setProperties(requestPropertiesBean);}));};/*** 更新ui** @param responsePropertiesBean*/private void refreshUi(ResponsePropertiesBean responsePropertiesBean) {leftOnLineFlag = false;if (responsePropertiesBean.getData().getLightSwitch().getValue() == 1) {leftOnLineFlag = true;}leftLampsSwitchView.setOnline(leftOnLineFlag);rigthLampsSwitchView.setOnline(false);/**** 设置颜色*/new Handler(getMainLooper()).post(() -> {hsvCircleView.setColor(queryColor(responsePropertiesBean));});}/*** 根据HSV查找16进制颜色*/public String queryColor(ResponsePropertiesBean responsePropertiesBean) {if (null == responsePropertiesBean) {return "";}List<PalettesDialogBean> arr = ColorTools.getColorData(this);for (int i = 0; i < arr.size(); i++) {if ((int) (arr.get(i).getHsv()[0] * 100) == responsePropertiesBean.getData().getHSVColor().getValue().getHue()) {return arr.get(i).getColor();}}return "";}//=========================== 回调==================================/*** 初始化* 成功后获取设备状态 和 设备属性*/private IPanelCallback initCallback = (initFlag, o) -> {if (initFlag) {getEqStatus();getProperties();subAllEvents();}if (!initFlag) ALog.e(TAG, "initSdk fail");if (TextUtils.isEmpty(String.valueOf(o))) ALog.e(TAG, "initCallback Object is null");};/*** 获取设备状态*/private IPanelCallback statusCallback = (bSuc, o) -> {StatusBean bean = gson.fromJson(String.valueOf(o), StatusBean.class);status = bean.getData().getStatus();if (bean.getData() != null && bean.getData().getStatus() == 1) {statusTv.post(() -> statusTv.setText("设备在线"));} else {statusTv.post(() -> statusTv.setText("设备离线"));}};/*** 获取设备属性*/private IPanelCallback getEqPropsCallBack = (bSuc, o) -> {firstPropertiesFlag = false;ALog.d(TAG, "getEqPropsCallBack" + String.valueOf(o));//解析responsePropertiesBean = gson.fromJson(String.valueOf(o), ResponsePropertiesBean.class);//如果没有属性 需要进行设置属性if (null == responsePropertiesBean.getData().getLightSwitch()) {setFirstProperties();return;}/*** 订阅mqtt*///设置请求实体类requestPropertiesBean.setItems(new RequestPropertiesBean.Items(responsePropertiesBean.getData().getLightSwitch().getValue(),0));refreshUi(responsePropertiesBean);};/*** 设置设备属性*/private IPanelCallback setEqPropsCallBack = (bSuc, o) -> {if (!TextUtils.isEmpty(String.valueOf(o))) {ALog.d(TAG, "setEqPropsCallBack" + String.valueOf(o));}if (bSuc && firstPropertiesFlag) {getProperties();}};/*** 调用服务*/private IPanelCallback invokeServiceCallBack = (bSuc, o) -> {ALog.d(TAG, bSuc + "invokeServiceCallBack" + String.valueOf(o));if (bSuc) {rigthLampsSwitchView.post(() -> {Toast.makeText(this, "请求成功", Toast.LENGTH_SHORT).show();});}};/*** 订阅事件回调** @iotid 参数是设备iotid* @topic 参数是回调的事件主题字符串* @Object data 是触发事件的内容*/private IPanelEventCallback eventCallback = (iotid, topic, data) -> {ALog.d(TAG, "eventCallback_data:" + data);if (iotid.equals(iotId)) {EventCallbackbean bean = gson.fromJson(String.valueOf(data), EventCallbackbean.class);if (null == responsePropertiesBean || null == responsePropertiesBean.getData().getLightSwitch())return;if (TextUtils.isEmpty(String.valueOf(bean.getItems().getLightSwitch().getTime()))) {return;}if (null != bean.getItems().getLightSwitch() || !TextUtils.isEmpty(String.valueOf(bean.getItems().getLightSwitch().getTime()))) {responsePropertiesBean.getData().setLightSwitch(new ResponsePropertiesBean.DataBean.LightSwitchBean(bean.getItems().getLightSwitch().getValue()));}if (null != bean.getItems().getHSVColor() && bean.getItems().getHSVColor().getValue().getHue() != 999) {responsePropertiesBean.getData().getHSVColor().getValue().setHue(bean.getItems().getHSVColor().getValue().getHue());responsePropertiesBean.getData().getHSVColor().getValue().setSaturation(bean.getItems().getHSVColor().getValue().getSaturation());responsePropertiesBean.getData().getHSVColor().getValue().setValue(bean.getItems().getHSVColor().getValue().getValue());}refreshUi(responsePropertiesBean);}};
}可根据例子写自己产品所需要和对应的功能。

阿里IOT云飞燕平台的使用和感悟。相关推荐

  1. 从零开始,打造基于阿里IoT云平台的LoRa解决方案(3)_配置产品功能,将上传数据解析为阿里云平台数据格式

    本篇是 <从零开始,打造基于阿里IoT云平台的LoRa解决方案>系列教程的第3 篇,将为大家讲解:1-如何配置产品功能?2-如何将产品的上传数据解析为阿里云平台数据格式? 查看阿里物联网平 ...

  2. 阿里IOT云平台(二)---10分钟物联网设备接入阿里云IoT平台

    本文转载自:https://www.geek-workshop.com/thread-37883-1-1.html.基于VS Code和Node.js 我替换了原文中的温度.湿度属性图(主要是修正了标 ...

  3. 【微信小程序控制硬件⑧ 】微信小程序以 websocket 连接阿里云IOT物联网平台mqtt服务器,封装起来使用就是这么简单!(附带Demo)

    [微信小程序控制硬件第1篇 ] 全网首发,借助 emq 消息服务器带你如何搭建微信小程序的mqtt服务器,轻松控制智能硬件! [微信小程序控制硬件第2篇 ] 开始微信小程序之旅,导入小程序Mqtt客户 ...

  4. STM32G0+EMW3080+阿里云飞燕平台实现单片机WiFi智能联网功能(三)EMW3080完成配网,EMW3080连接到阿里云飞平台

    项目描述:该系列记录了STM32G0+EMW3080实现单片机智能联网功能项目的从零开始一步步的实现过程: 硬件环境:单片机为STM32G030C8T6:物联网模块为EMW3080V2-P:网联网模块 ...

  5. 【小程序案例】支付宝小程序-MQTT模器,IoT设备通过WSS接入阿里云IoT物联网平台...

    支付宝小程序-MQTT模拟器通过WSS接入阿里云IoT物联网平台 准备工作 1.1 注册阿里云账号 开通阿里云账号,并通过支付宝实名认证 https://www.aliyun.com 1.2 免费开通 ...

  6. 阿里云IOT设备数据接入 (从阿里云IOT云平台获取设备数据)

               从阿里云IOT云平台获取设备数据 前言: 这篇文档主要讲述的就是当设备的数据发送到物联网套件之后,用户的服务端如何获取设备 的数据. 通过阅读阿里云IoT文档,我们了解到队列中消 ...

  7. 以阿里IoT开发物联网和应用平台

    1. 链接物联网的概念 物联网(The Internet of Things,简称IOT)是指通过 各种信息传感器.射频识别技术.全球定位系统.红外感应器.激光扫描器等各种装置与技术,实时采集任何需要 ...

  8. 阿里云 IoT 物联网平台 MQTT 通讯模式

    阿里云 IoT企业物联网平台为不同场景的硬件提供了多种通信模式,例如设备到云,云到设备,设备到设备之间的通信.尽管不同业务场景设备和交互行为差异很大,但是大多数底层数据流通信模型都可以归类为三种MQT ...

  9. 解密阿里云IoT物联网平台MQTT Access Server核心架构

    MQTT是基于TCP/IP协议栈构建的异步通信消息协议,是一种轻量级的发布.订阅信息传输协议.MQTT已逐渐成为IoT领域最热门的协议,也是国内外各大物联网平台最主流的传输协议,阿里云IoT物联网平台 ...

最新文章

  1. 谷歌某程序员抱怨“招人难”:招了小半年,8个岗位才招到1个,现在又空出6个岗位!...
  2. MySQL设计之三范式
  3. HACMP 认证学习系列,第 2 部分:计划与设计
  4. boost::iostreams::example::container_sink用法的测试程序
  5. android 开发卫星菜单,android之类似卫星菜单,来自定义ViewGroup。。。。。
  6. 小毛驴走呀走的openeim001
  7. 阿里云支持超级账本最新版 其区块链解决方案进入商用阶段
  8. OPPO或将于本月推出Find X2 英雄联盟 S10 限定版
  9. windows登录linux免密码,Windows使用SSH Secure Shell实现免密码登录Linux的方法以及使用scp2命令免密码下载文件...
  10. 我们应该如何写好HTMLCSS
  11. 谈谈Java的try..catch...
  12. python有关urllib,urllib2和requests应用记录
  13. 系统建模与计算机仿真内容,系统建模与计算机仿真
  14. 如何使用SpanReporter接口生成链路数据
  15. ORCAD16.6禁止start page启动的两种方式
  16. 计算机英语 复习资料
  17. 只需3步把VSCode打造成Markdown编辑器
  18. android 读写文件 简书,Android 读取asset文件
  19. Java类与面向对象(创建对象 成员方法 形参实参 递归 重载 可变参数 作用域 构造方法 this)
  20. python分析出nba球员的位置_虎扑热帖|Python数据分析|NBA的球星们喜欢在哪个位置出手...

热门文章

  1. 【第 001 期 · 文献领读】——MRI专题
  2. php段错误coredumped,段错误 (core dumped)
  3. 关于BUCK降压的一些学习笔记2-->滞回比较器产生三角波
  4. nltk,wordnet安装时出现问题关于omw-1.4
  5. 【引用】pygame菜鸟入门指南
  6. 数据预处理部分的思维导图
  7. 机器人聊天软件c#_聊天机器人_c#应用
  8. C# ABP WebApi与Swagger UI的集成
  9. 上传word文档显示服务器出错,打开office出错的几种解决方法
  10. 显卡内存和计算机内存,512M和1GB显卡显示内存大小有什么区别