关于ESP8266-NodeMCU和onenet通信传输学习总结(三)

关于ESP8266-NodeMCU和onenet通信传输学习总结(三)

一、前篇概述

​ 很久没更新了,原因在于物流快递太慢和重温Android开发知识去了,想着脱离onenet平台 写自己的app使用,这里要先感谢下各位大佬的开发经验和教学分享。前面两节,我用esp8266nodemcu实现了onenet平台的连接和数据点上传下发指令,然后还接入了byj-48电机的操作,实现了一些基础通信控制。

整体构建:

在这里插入图片描述

​ 时隔多日,到今天终于实现了Android app的开发使用和天猫精灵的语音接入控制,其中有很多槽点和想法,文末再提,下面开始正文:

二、基于之前的设计开发Android app

app我采用android studio 进行开发,这里要感谢一下b站博主阿正的教学分享!这里用多线程分别处理界面显示和数据处理,大致过程如下:

Android数据处理:

在这里插入图片描述
在这里插入图片描述

1、xml布局文件
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">
    <LinearLayout
        android:layout_width="match_parent"
        android:orientation="vertical"
        android:layout_height="match_parent">
        <LinearLayout
            android:layout_marginTop="5dp"
            android:layout_width="match_parent"
            android:orientation="vertical"
            android:layout_height="250dp">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_weight="1"
                android:layout_height="match_parent">
                <ImageView
                    android:layout_width="80dp"
                    android:id="@+id/image_temperture"
                    android:layout_gravity="left"
                    android:src="@drawable/temperture"
                    android:layout_height="wrap_content">
                </ImageView>
                <TextView
                    android:id="@+id/text_temperture"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:textSize="60sp"
                    android:text="暂无数据">
                </TextView>
            </LinearLayout>
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_weight="1"
                android:layout_height="match_parent">
                <ImageView
                    android:layout_width="80dp"
                    android:id="@+id/image_5"
                    android:layout_gravity="left"
                    android:src="@drawable/bright"
                    android:layout_height="wrap_content">
                </ImageView>
                <TextView
                    android:id="@+id/text_bright"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:textSize="60sp"
                    android:text="暂无数据">
                </TextView>
            </LinearLayout>
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_weight="1"
                android:layout_height="match_parent">
                <ImageView
                    android:layout_width="80dp"
                    android:id="@+id/image_7"
                    android:layout_gravity="left"
                    android:src="@drawable/door_lock"
                    android:layout_height="wrap_content">
                </ImageView>
                <TextView
                    android:id="@+id/text_doorLock"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:textSize="60sp"
                    android:text="暂无数据">
                </TextView>
            </LinearLayout>
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:orientation="vertical"
            android:layout_marginTop="5dp"
            android:layout_height="wrap_content">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_weight="1"
                    android:orientation="vertical"
                    android:layout_height="wrap_content">
                    <ImageView
                        android:layout_width="80dp"
                        android:id="@+id/light_control"
                    android:layout_gravity="center_horizontal"
                        android:src="@drawable/open"
                        android:layout_height="80dp">
                    </ImageView>
                    <TextView
                        android:layout_width="wrap_content"
                        android:text="灯"
                        android:textSize="20sp"
                    android:layout_gravity="center_horizontal"
                        android:layout_height="wrap_content">
                    </TextView>
                </LinearLayout>
                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_weight="1"
                    android:orientation="vertical"
                    android:layout_height="wrap_content">
                    <ImageView
                        android:layout_width="80dp"
                        android:src="@drawable/lock"
                    android:layout_gravity="center_horizontal"
                        android:id="@+id/door_control"
                        android:layout_height="80dp">
                    </ImageView>
                    <TextView
                        android:layout_width="wrap_content"
                        android:text="门禁"
                        android:textSize="20sp"
                    android:layout_gravity="center_horizontal"
                        android:layout_height="wrap_content">
                    </TextView>
                </LinearLayout>
                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_weight="1"
                    android:orientation="vertical"
                    android:layout_height="wrap_content">
                    <ImageView
                        android:layout_width="80dp"
                    android:layout_gravity="center_horizontal"<
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值