Use Android studio to complete the production of simple smart home APP (including source code project package)

 (Fill in the hole, and turn out the complete software code I promised you before, for everyone to learn together)

You can see the effect first: 

Smart home APP display video (including source code)_哔哩哔哩_bilibili

Table of contents

project instruction

Features

System Functional Requirements

Realized software functions

 1. Map positioning

2. Bluetooth button

3. Remote control 

Core code display instructions

Bluetooth Control Code Description

1. Bluetooth tools:

 2. Determine whether the Bluetooth is connected

Source code and related Android e-book links: Source code and related Android books


project instruction

This is a complete software project for my graduation project. In fact, it is relatively simple. Readers can develop it again on this basis. It contains three functions, click on the map to locate (set the home address), Bluetooth control (used to control the CC2530 hardware, the essence is just Completed the data upload and transmission of the SPP protocol), remote control (WI-FI) . In general, my graduation project consists of two parts: software and hardware. The software is this smart home APP based on Android. Among them, the function of clicking on the map and its additional functions have been explained in detail in previous articles. The link is as follows :

How does Android implement map positioning? Android studio+Baidu map API+Android6.0 system realizes map display, address setting, click map positioning function (details)

The hardware section is divided into three parts: WI-FI remote control based on C8T6, simple smart home networking based on CC2530, voice recognition control based on LD3320. For the specific operation and implementation steps, you can refer to my previous articles for details, the link is as follows:

STM32F103C8T6+ESP8266+MQTT uses the latest version of oneNet visual View to realize remote control (details)

Realize speech recognition system: teach you how to use STM32C8T6 and LD3320 (SPI communication version) to realize speech recognition

Features

System Functional Requirements

Functional requirements, one of the product's Android mobile phone terminal can realize the click positioning function. When the positioning is near the set home, you can choose to jump to the remote control, turn on the street lights in advance, and switch the air conditioner on and off according to the real-time temperature and humidity data in the home. The second is that after returning home , the voice-activated lights at the door, the smoke alarm in the kitchen, the curtains on the windows, and the fan in the living room are all automatically controlled. The Zigbee technology is used for networking, and the Bluetooth module HC-05 is used as an intermediary for manual control of equipment; the third is to set up a voice control system in the bedroom, which can control both lights and fans and other equipment. 

Realized software functions

 1. Map positioning

A set of application program interfaces based on Android 4.0 and above devices. The functions realized are switching between ordinary maps and satellite maps. You can view traffic maps and heat maps. At the same time, you can display the current area, zoom the current map view, and you can click Map View the latitude and longitude of the current map. Due to the need to cooperate with the remote control system of the smart home, the setting function of the home address is additionally added.

2. Bluetooth button

The essence of the Bluetooth button function program is the Bluetooth serial port communication . The realization of this communication is based on the SPP protocol (Serial Port Profile) , which can establish a function program for serial port data transmission between Bluetooth devices. (Both ends of the communication) There is a problem of a complete communication path between applications. Its specific implementation function is to complete the control of the Bluetooth module HC-05 by the Android mobile phone, and then realize the manual control of the smart home system of the Zigbee network. When it is not connected, A pop-up window will prompt and give back and refresh functions. After the connection is successful, a button interface will appear to control home devices through Bluetooth commands. At the same time, when the Bluetooth device is disconnected, the Bluetooth selection interface will reappear and a prompt will be given.

 

 

3. Remote control 

The remote control function program is an application designed with the visual View of the One Net development platform . It uses the MQTT protocol to upload data and issue commands, and send and upload data in the form of a web page, that is, the functional interface is not designed by Android studio. Yes, the program is opened through the Android terminal.

Core code display instructions

Regarding the two major functions of map positioning and remote control, I will not explain too much, because the remote control is only to open a network-side application through the Android side. The reason why it crashes is because of its The implementation needs to enable the certificate credit while enabling the permission to ensure that the opened HTTPS is safe and reliable, otherwise when the PTZ web application is opened, there will be a flashback phenomenon, and because after Android 5.0, by default, http and A mixture of https, it is necessary to set up the webview so that it can load the content of the mixed network protocol. The code link is as follows:

Solve the flashback problem of the visual view of the OneNet platform opened on the Android side

Bluetooth Control Code Description

 Then our difficulty comes to the Bluetooth control function. First of all, we need to understand that it is a Bluetooth communication app, and there is no difference in the core of those SPP software that you download in the app store. All in all, the essence is the same. And all I did was create an ugly interface that only works on my system . Among them, the difficulties I have solved include the realization of Bluetooth data upload and mobile phone data transmission, how to appear a pop-up window to re-search and connect after Bluetooth disconnection , the realization of log sliding up and down , and so on.

 There is one more thing that needs to be stated. What I call is a bluetooth tool written by a big guy. This is very helpful to me. I forget who it is, but anyway, thank you! ! !

1. Bluetooth tools:

The BLESPPUtils.java file, the code is as follows, which includes, search for Bluetooth sources, enable Bluetooth, keep logs, receive and send byte data, and so on. I will not post the code, you can see the source code for details

 2. Determine whether the Bluetooth is connected

    /**
     * 判断蓝牙是否断开连接
     */
    //The BroadcastReceiver that listens for bluetooth broadcasts
    private final BroadcastReceiver BTReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (BluetoothDevice.ACTION_ACL_DISCONNECTED.equals(action) && menu_flag==0) {
                Intent intent_context = getIntent();
                finish();
                startActivity(intent_context);
                //Do something if disconnected
                Toast.makeText(getApplicationContext(), "不好意思,检测到设备已经断开连接,正在重启", Toast.LENGTH_SHORT).show();
            }
        }
    };

3. Realization of sliding up and down of logs ( TextView )

 This is because of my food, so I have been struggling for a long time. In fact, I only need to set the following in the layout. The specific location is as shown in the figure:


 To sum up: As far as my smart home software is concerned, I actually realized it through the integration and modification of network resources, so I think it is derived from this, and I give back to it. I want to send out this small project I have done. It can also help some people. Although the interface of this software is ugly, and many functions may not be perfect, but it has indeed devoted a lot of effort, and I have only learned some superficial aspects of Android, so I will also put some Android e-books I have read here. In the link of the source code, I hope to learn and progress together with everyone. If you find it helpful, you can pay attention to a wave and encourage each other!

Oh, by the way, I plan to talk about cc2530 and its related protocol stacks later. Regarding wireless sensor networks, I have learned this stuff most of the time in my undergraduate course. I plan to summarize the knowledge I have learned to avoid forgetting. above

Source code and related Android e-book links: Source code and related Android books

Guess you like

Origin blog.csdn.net/Uncoverlove/article/details/131409220