当前位置:网站首页>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
边栏推荐
- On July 2, I invite you to TD Hero online press conference
- . Net delay queue
- Understand the window query function of tdengine in one article
- 硬核,你见过机器人玩“密室逃脱”吗?(附代码)
- 能源势动:电力行业的碳中和该如何实现?
- Windows uses commands to run kotlin
- MySQL数字类型学习笔记
- Three-level distribution is becoming more and more popular. How should businesses choose the appropriate three-level distribution system?
- TDengine 连接器上线 Google Data Studio 应用商店
- Idea debugs com intellij. rt.debugger. agent. Captureagent, which makes debugging impossible
猜你喜欢
Application of data modeling based on wide table
Roll up, break through 35 year old anxiety, and animate the CPU to record the function call process
[technical live broadcast] how to rewrite tdengine code from 0 to 1 with vscode
Cross process communication Aidl
Tdengine already supports the industrial Intel edge insight package
Oracle combines multiple rows of data into one row of data
Idea debugs com intellij. rt.debugger. agent. Captureagent, which makes debugging impossible
Small program startup performance optimization practice
Go 语言使用 MySQL 的常见故障分析和应对方法
Online chain offline integrated chain store e-commerce solution
随机推荐
【系统设计】指标监控和告警系统
Tdengine can read and write through dataX, a data synchronization tool
Comment obtenir le temps STW du GC (collecteur d'ordures)?
cent7安装Oracle数据库报错
Community group buying has triggered heated discussion. How does this model work?
Develop and implement movie recommendation applet based on wechat cloud
7 月 2 日邀你来TD Hero 线上发布会
剪掉ImageNet 20%数据量,模型性能不下降!Meta斯坦福等提出新方法,用知识蒸馏给数据集瘦身...
Oracle combines multiple rows of data into one row of data
正式上架!TDengine 插件入驻 Grafana 官网
Charm of code language
MySQL installation configuration and creation of databases and tables
What about wechat mall? 5 tips to clear your mind
Wechat applet - simple diet recommendation (3)
高级 OpenCV:BGR 像素强度图
[how to disable El table]
How to use sqlcipher tool to decrypt encrypted database under Windows system
Generics, generic defects and application scenarios that 90% of people don't understand
Resolve the horizontal (vertical) sliding conflict between viewpager and WebView
What should we pay attention to when developing B2C websites?