当前位置:网站首页>Implementation of smart home project
Implementation of smart home project
2022-07-05 10:01:00 【Sunqk5665】
This project is an embedded course training content
Project source code :https://download.csdn.net/download/weixin_43624626/20368957
among QT The interface is not written by myself , At that time, the training time was limited , The teacher gave a packed one directly Qt Implementation interface , In the practical training, the main thing to complete is the realization of the server .
Catalog
1 Training preparation
1.1 Hardware resources
1.1.1 Smart home terminal
Provided by the FS_11C14 Development board , be based on NXP LPC11C14 Micro controller (ARM Cortex-M0 kernel ), Here's the picture 1.1 Shown . Integrate multiple sensors 、RFID、ZigBee、OLED Display module, etc . The platform has rich hardware resources and experimental procedures related to the Internet of things , It is suitable for Internet of things teaching and engineers as a research and development reference platform . There are also open FS_CoLink Emulator , Users can enter the development without configuring the emulator . It provides users with a simple and convenient development environment that can be quickly started , It can save time for application development , Increase of efficiency .
Analog smart home terminal , Use cortex-M0 processor , With gravity 、 light 、 temperature And a variety of sensors , Responsible for the collection of family environment information .
1.1.2 ZigBee Module introduction
FS_CC2530 ZigBee The module uses Ti company CC2530 modular . with USB To serial chip , It's easy to connect PC Machine or other with USB Host interface device , So as to achieve and FS_11C14 Networking communication .FS_CC2530 The extended resources of the module include potentiometers 、 Key interrupt 、LED Lights and other peripherals .
1.1.3 ZigBee The coordinator
Zigbee The coordinator ( Pictured 1.2), Responsible for acquisition terminal and FS4412 Data transparent transmission , The coordinator uses USB The extension cable is connected to FS4412, The final data passed Zigbee Pass to FS4412.
1.2 Software resources
1.2.1 Linux operating system
This training will have the realization of the server , The server is usually in Linux On the operating system , And deploy on it . For the relative convenience of server code writing and debugging , Here's the choice VMware Under the virtual machine Ubantu operating system .
Ubantu Is a desktop based application Linux operating system , also Ubantu It's open source 、 One of the free system versions . Between servers Linux The utilization rate is very high , Most of the world web The server is based on Linux The system is running . Even though Windows and mac Such an operating system is better than Linux More popular , however Linux The penetration rate is still very high .
Linux The system has the following advantages :
- Cross platform hardware support .
- Rich software support
- Multi user, multi task
- Reliable security
- Good stability
- Perfect network function
1.2.2 Qt Software
The training client needs to be operated in the form of graphical interface , So choose to go through Qt To implement the client interface and related logic .Qt By cross platform C++ GUI application development framework , It can develop GUI Program , It can also be used to develop non GUI Program , For example, console tools and servers .Qt It's an object-oriented framework , Use special code to generate extensions and some macros ,Qt It's easy to expand , And allows true component programming .
2 Training principle
2.1 Overall framework analysis
2.1.1 Overall frame diagram

2.1.2 Project flow chart

3 Purpose of training
In this training, we need to design and implement a smart home control system , It mainly includes the design of server and client . After the user connects the client and the server , The user can receive the approval in the client interface M0 The real-time data from the on-board sensor , Have temperature 、 humidity 、 And the light ; Users can also click the corresponding home control button on the client interface to control the corresponding home device , Of course, in practice “ Home equipment ” yes M0 Some lights on the board 、 Buzzer 、 Fans and other electronic components .
4 Training program
For the whole training , Server using Linux Under the C Language writing , Client side adoption Qt Realize the graphic interface . Smart home through STM32f051arm processor (arm processor ) Of M0 The board collects environmental parameters in real time , Such as temperature 、 humidity 、 Light sense and other data ; Re pass ZigBee Wireless communication sends the collected environmental parameters or object information to ZigBee The coordinator , Then the data is transmitted to linux Server side , from M0 The thread is responsible for receiving environmental parameters or item information , Activate the database thread to process the database accordingly , adopt socket Communication further transmits data to the client , The collected real-time data is displayed on the client with a graphical interface .M0 The fan on the board 、LED etc. “ Home equipment ” You can send control commands through the client , Encapsulate the command , Then pass the encapsulated command socket Transfer to the server , Through... On the server side ZigBee Wireless communication is transmitted to M0 plate , And then M0 The fan on the board 、LED etc. “ Home equipment ” Carry out remote intelligent control .
5 Training content
5.1 Based on learning
The teacher first led us to learn some basic knowledge necessary to complete the project .
5.1.1 System calls and library functions
1、 A system call is an interface to the operating system itself , It is oriented to the underlying hardware . By system call , Processes and hardware devices that can run in user mode ( Such as CPU、 disk 、 Printers, etc ) Interact , It is an interface left by the operating system to the application . When a user process needs a system call , The kernel will call kernel related functions to implement . User programs cannot call these functions directly , These functions run in kernel mode ,CPU Switch to kernel state through soft interrupt and start executing kernel system call function .
2、 Library functions can be understood as a layer of encapsulation of system calls , It is encapsulated to realize a certain function API aggregate , Provide unified programming interface , Easy for application migration . The system call is the interface provided by the kernel to the user program , Its execution efficiency is relatively efficient and streamlined , But sometimes we need to deal with the acquired information more complicated , Or more humanized needs , We encapsulate these processes into a function and provide it to programmers , It is more convenient for programmers to code .
The relationship between library functions and system calls is shown in the following figure 5.1 Shown :
5.1.2 file I/O
file I/O Based on system calls , from posix( Portable operating system interface ) A set of interfaces provided for input and output , The core of the operation is the file descriptor . Each open file in Chinese has a corresponding file descriptor , The file descriptor is a non negative integer , File descriptor from 0 Assigned starting , In turn, increasing , Three descriptors are opened by default , Namely 0、1、2, They correspond to standard inputs 、 Standard output and standard error .
The corresponding functions are open()、close()、read()、write() etc. .
5.1.3 standard IO
standard IO By C A set of functions provided in the library for input and output . The core of the operation is FILE( File stream pointer ), Each used file opens an area in memory , It is used to store information about files .
The related functions are fopen()、flose()、fgetc()、fputc()、fgets()、fputs()、fread()、fwrite()、fseek()、fftell() etc. .
standard IO The cache mode has full buffer 、 Line buffering and unbuffered . There are three refresh conditions , Respectively, the program exits normally , The cache is full , Encountered a newline ‘\n’.
practice 1, Calculate the size of the row buffer , The code screenshot is shown below 5.2 Shown :
By running the code and observing the output, we can conclude that the size of the cache is 1024 byte .
practice 2, use fgetc() and fputc() Realization linux in cat Command functionality , The code is as follows 5.3 Shown :
practice 3, use fgets() Realization wc -l The function of , The code is as follows 5.4 Shown :
practice 4: use fgets and fputs Realization cp The function of , The code is as follows 5.5 Shown :
5.1.4 TCP Establishment process
First Client The end sends the connection request message ,Server Segment accepts the connection and replies ACK message , And allocate resources for this connection .Client Termination received ACK The message also goes to Server Segment occurs ACK message , And allocate resources , such TCP The connection is established .
TCP Three handshakes , Pictured 5.6 Shown :
- client–>server: The first handshake , When establishing a connection , The client sends syn package (seq=j) To the server , And enter SYN_SENT state , Wait for server to confirm ;SYN: Sync sequence number .
- server–>client: The second handshake , Server received syn package , Must confirm the client's SYN(ack=j+1) At the same time, I also send a SYN package (seq=k), namely SYN+ACK package , At this time, the server enters SYN_RECV state .
- client–>server: The third handshake , Client receives server's SYN+ACK package , Send confirmation package to server ACK (ack=k+1), This package has been sent , Client and server access ESTABLISHED(TCP Successful connection ) state , Complete three handshakes .

5.1.5 TCP Of C/S framework
1、Server End configuration :
socket() Generate sockets for establishing connections –>bind(): binding IP And port –>listen() monitor , Turn initiative into passivity –>accept(): Accept client connection request , Generate sockets for communication –>recv()/send(): Data transmission –>close(): Close socket .
2、client End configuration :
socket(): Generate a socket for connection and communication –>connect(): Send a connection request to the server , Establishing a connection –>recv()/send(): Data transmission –>close(): Close the file descriptor .
5.1.6 Server model
The server model can be divided into circular server and concurrent server . Circular server : When a client exits, the server can continue to receive the connection of the next client ; Concurrent servers : A server can send and receive data with multiple clients at the same time .
The concurrent server can be divided into multi process concurrency 、 Multithreading concurrency and IO Multiplexing .
5.2 Project implementation process
In this training, I am mainly responsible for the final step of the whole project —— Debugging and testing . Due to the limitation of training time ,Qt The client has no time to complete , Use one provided by the teacher Qt Implemented client , The part we completed is the server except the client . First, take a look at the server code structure of the whole project , Here's the picture 5.7 Shown :
Among them Makefile File is the compilation link rule of the whole project file , After writing this file and adding it to the project folder, you only need to enter one in the terminal make Command can compile the entire project file and generate an executable file .Makefile The contents of the document are as follows 5.8 Shown :
compile main.c, Pictured 5.9 Shown :
function main.c, Pictured 5.10 Shown , Show connections without clients , Next, wait for the client's link :
Open client , Pictured 5.11 and 5.12 Set as shown in IP And port after , Return to the login interface to set the account and password , Pictured 5.14 Click on “ Sign in ”:
After clicking the login button , Pictured 5.13 Shown , You can immediately see the prompt of successful connection on the terminal :
stay “ Home page ” You can see M0 Real time data returned by the board , The data is displayed in line chart in real time , The returned data includes temperature 、 Humidity and light , Pictured 5.15、5.16、5.17 Shown :
Next, enter the console interface , Test whether the corresponding button is effective . Here is the test of the two buttons , Pictured 5.18 Click on “ The bedroom light is on ” Button , chart 5.20 Displays the control commands received by the terminal ; Pictured 5.19 Click on “ The bedroom light is on ” Button , chart 5.21 Displays the control commands received by the terminal .

GitHub resources :https://github.com/Sunqk5665/LinuxC-Learning/tree/main/%E5%AE%9E%E8%AE%AD
边栏推荐
- [NTIRE 2022]Residual Local Feature Network for Efficient Super-Resolution
- How to choose the right chain management software?
- 【sourceTree配置SSH及使用】
- Apache DolphinScheduler 系统架构设计
- TDengine 已经支持工业英特尔 边缘洞见软件包
- Data visualization platform based on template configuration
- Those who are good at using soldiers, hide in the invisible, and explain the best promotional value works in depth in 90 minutes
- The king of pirated Dall · e? 50000 images per day, crowded hugging face server, and openai ordered to change its name
- Cut off 20% of Imagenet data volume, and the performance of the model will not decline! Meta Stanford et al. Proposed a new method, using knowledge distillation to slim down the data set
- Flutter development: use safearea
猜你喜欢

MySQL installation configuration and creation of databases and tables

Node の MongoDB Driver

Analysis on the wallet system architecture of Baidu trading platform

百度交易中台之钱包系统架构浅析

oracle 多行数据合并成一行数据

How to empty uploaded attachments with components encapsulated by El upload

H. 265 introduction to coding principles
![[NTIRE 2022]Residual Local Feature Network for Efficient Super-Resolution](/img/f3/782246100bca3517d95869be80d9c5.png)
[NTIRE 2022]Residual Local Feature Network for Efficient Super-Resolution

Roll up, break through 35 year old anxiety, and animate the CPU to record the function call process

能源势动:电力行业的碳中和该如何实现?
随机推荐
E-commerce apps are becoming more and more popular. What are the advantages of being an app?
Openes version query
mysql80服务不启动
Flutter development: a way to solve the problem of blank space on the top of listview
Coordinate system of view
TDengine × Intel edge insight software package accelerates the digital transformation of traditional industries
Node red series (29): use slider and chart nodes to realize double broken line time series diagram
Apache DolphinScheduler 入门(一篇就够了)
Analysis on the wallet system architecture of Baidu trading platform
How to correctly evaluate video image quality
How to empty uploaded attachments with components encapsulated by El upload
【sourceTree配置SSH及使用】
How to choose the right chain management software?
Flutter development: use safearea
View Slide
[sourcetree configure SSH and use]
How to improve the operation efficiency of intra city distribution
如何正确的评测视频画质
Observation cloud and tdengine have reached in-depth cooperation to optimize the cloud experience of enterprises
Node-RED系列(二九):使用slider与chart节点来实现双折线时间序列图