With the rapid development of modern 4C technology (computer technology, control technology, communication technology and graphic display technology) and the continuous improvement of people's living standards, smart home has become an important branch of intelligent buildings. This paper aims to design a low-cost smart home controller for ordinary families that integrates local control and remote control to control the operating status of indoor appliances and the collection of environmental parameters. In the design, local control uses infrared technology, and remote control realizes embedded Web server by developing a streamlined TCP/IP protocol and combining HTTP protocol, so that users can control and monitor the devices and environment in the home through any browser. 2 Hardware Design of Ethernet Smart Home Controller
The smart home controller uses the 8-bit single-chip microcomputer W78E58B as the core processing unit of the system. The system hardware block diagram is shown in Figure 1.
The local end is based on infrared communication technology. The transmitting end uses the NB9148 infrared encoding module, and the receiving end uses the SJ1838 for receiving and demodulating, and transmits the control signal to the W78E58B. The external expansion RAM 62256 is used to increase the data transmission speed of the microcontroller and the processing of complex TCP/IP protocols. The RS232 serial port communication is mainly used for program downloading and debugging, as well as the communication conversion interface. The GAL device ATF16V8B is used for chip selection to save system space resources.
DS18B20 is used to collect ambient temperature.
The hardware platform of remote control is composed of W78E58B and Ethernet controller RTL8019AS. RTL8019AS is a dedicated Ethernet control chip designed for ISA bus and used to implement the physical layer protocol of the network. RTL8019AS has a built-in 10BASE-T transceiver, which is connected to RJ-45 by jumper mode through the network filter 20F-01 that can improve the anti-interference ability of network communication. E2PROM AT24C512 is used to store web page files accessed by embedded Web server, and is also used to store some user settings, such as IP address, gateway, and network card chip MAC address and other parameters.
3 Software Design of Ethernet Smart Home Controller
The software implementation of the Ethernet smart home controller is completed on the single-chip microcomputer, which mainly includes the virtual I2C bus reading and writing program, infrared receiving and control program, temperature acquisition program, network card chip RTL8019AS driver, embedded Web server implementation and other processing programs. This article only discusses the implementation of the network card chip driver and embedded Web server.
3.1 Driver for Ethernet controller RTL8019AS
The driver of RTL8019AS is the program interface between TCP/IP protocol and underlying physical devices. It shields the details of underlying hardware processing and provides an interface independent of hardware to upper-level software. TCP/IP protocol can complete the reception and transmission of Ethernet data by calling the Ethernet driver. The driver of network card chip RTL8019AS includes RTL8019AS initialization program, data packet receiving program and data packet sending program.
3.1.1 RTL8019AS initialization
RTL8019AS performs reset operation through RSTDRV pin. After reset, RTL8019AS is initialized first. The initialization operation includes setting PSTART=0x4c, PSTOP=0x80, making 0x40~0x4b the sending buffer of the network card, and 0x4c~0x7f the receiving buffer of the network card; setting RCR=0xcc, only receiving data packets, broadcast address data packets and multicast address packets whose target physical address is consistent with the set physical address; setting TCR=0xe0, working in normal mode; setting DCR=0xc8, using FIFO buffer and 8-bit data DMA; setting IMR=0x00, masking all interrupts; multicast address registers MAR0~MAR7, all set to 0x00; setting network card physical address registers PAR0~PAR5; setting CR=0x22, selecting the register of page 0, entering normal working state; setting ISR=0xff, clearing all interrupt flags.
3.1.2 RTL8019AS data transmission
First, encapsulate the data to be sent according to the Ethernet data frame format, then set the CR register to 12H, start the remote write DMA, and RTL8019AS will automatically send this frame of data to the data send buffer of RTL8019AS and write the result to the status register. Finally, set CR to 3EH, start the local write DMA, send the data to the FIFO register, and send it to the Ethernet. The program flow chart is shown in Figure 2.
When receiving data, the receiving buffer forms a circular FIFO queue. The two registers PSTART and PSTOP define the start and end pages of the circular queue; CURR is the write pointer, which is controlled by the chip; BNRY is the read pointer, which is controlled by the host program. The program determines whether a frame of data is received by querying the values of the two registers CURR and BNRY. The program flow is shown in Figure 3. [page]
3.2 Implementation of Embedded Web Server
The design uses the W78E58B 8-bit single-chip microcomputer. Due to the limited storage space and relatively slow processing speed of the single-chip microcomputer, and the need to implement the complete TCP/IP protocol in the entire remote control, the simplified TCP/IP protocol can be used in the network connection and access technology of the remote control. To achieve the interactive function, it is necessary to implement the HTTP protocol on the basis of the simplified TCP/IP protocol and build an embedded Web server. The simplified TCP/IP protocol in this design has the same four-layer structure as the TCP/IP protocol. The functions implemented by each layer are as follows:
① Link layer. The design is connected to the Internet through Ethernet, so the physical layer and data link layer must comply with the IEEE802.3 standard of Ethernet. However, the hardware components of the Ethernet controller RTL8019AS have implemented the CSMA/CD control mechanism, shielding the details of the underlying hardware processing, and providing hardware-independent interfaces to the upper-layer software, ultimately completing the reception and transmission of data in Ethernet. Therefore, the design of the physical layer and data link layer in the design is jointly implemented by the RTL8019AS hardware and driver.
② The network layer implements the ARP protocol, ICMP protocol and IP protocol. ARP is the address resolution protocol. The specific processing process is that when receiving the ARP data packet, the processor checks whether the IP address is a request or a response. If it is a response, the network card address in the response is stored in the ARP cache table; if it is a request, the processor will return its own network card physical address to the other party. ICMP is a debugging response to the PING request to detect whether the network is smooth. According to the requirements of the actual application of the system, the IP protocol only needs to implement the transmission and reception of datagrams, without the need to implement routing selection algorithms and error control, and does not need to support the fragmentation and reorganization of IP datagrams.
③The transport layer implements the TCP protocol. The TCP protocol is a connection-oriented, end-to-end reliable communication protocol. The design adopts the TCP connection establishment and closing mechanism, timeout retransmission mechanism, data packet confirmation mechanism, and flow control mechanism to ensure its reliability. In the timeout retransmission mechanism, if no confirmation is received after the timeout retransmission timer overflows, the data packet is retransmitted and the retransmission timer is reset. For simplicity, the program only sends one TCP data packet at a time, and then waits for its confirmation. Only after receiving the confirmation will it continue to send the following TCP data packet. In this design, the program retransmission interval is fixed, and the standard algorithm in the TCP protocol is not used. When a certain number of times is reached, if the sender has not received the confirmation, it will abandon the sending of the packet and close the TCP connection. TCP flow control is to coordinate the sending and receiving of the communicating parties.
The design is based on the uneven transmission rate. The system only sets a medium IP packet size receiving buffer when using the TCP protocol, so the receiving window is always set to 1024. In this way, the remote host will communicate with the local Web server at a slower transmission rate, which will not cause a crash.
④The application layer implements the HTTP protocol. HTTP is the protocol for communication between the Web server and the browser.
To simplify, the design uses a fixed HTTP message header to encapsulate the HTTP response data message. The format is as follows:
char code html_header[ ] //The server's response header when the client accesses the homepage
= {"HTTP/1.1 200 OKn" //Response line (Respond Line), the status is OK, indicating that the file can be read
"Cache-control: no-cachen" //No cache control
"Connection: Keep-Aliven" //HTTP/1.1 sustainable connection
"Content-Length: TAG:LEN1n" //File length
"Content-Type: text/htmlrnrn" }; //File format requested by the client GET
When responding to an HTTP request, the data portion of an Ethernet packet cannot exceed 1500 bytes.
If the data exceeds 1500 bytes, it needs to be sent in groups.
3.3 Results of remote control operation of Ethernet smart home controller
After the smart home controller is connected to Ethernet, users only need to enter the controller's IP address in the browser to log in to the remote control interface. After entering the correct username and password, they will enter the control page and can access and control each subsystem.
Figure 4 is the control page of the smart home appliance. The system uses GIF format images to represent the status of the smart home appliance switch. When the corresponding switch in the control page is clicked, the smart home Web server receives the HTTP request, executes the CGI program, and embeds the image of the opposite state into the corresponding position of the web page. At the same time, the single chip will output a level opposite to the previous state at the control port of the corresponding home appliance. At this time, the relay is activated and the operation state of the home appliance changes. Finally, the smart home Web server sends the new HTML page back to the user end, and the browser updates the page and displays the changed state of the home appliance.
The software system of the smart home web server also enables a timing mechanism. If the user does not perform any operation within the specified time, the system will exit the control page and return to the login page. The user must re-enter the verification information and log in before entering the control page again to perform operations, which greatly improves the security of the entire smart home control system.
References:
[1]. W78E58B datasheet http://www.dzsc.com/datasheet/W78E58B_705483.html.
[2]. RS232 datasheet http://www.dzsc.com/datasheet/RS232_585128.html.
[3]. ATF16V8B datasheet http://www.dzsc.com/datasheet/ATF16V8B_95069.html.
[4]. DS18B20 datasheet http://www.dzsc.com/datasheet/DS18B20_819975.html.
[5]. RTL8019AS datasheet http://www. dzsc.com/datasheet/RTL8019AS_173.html.
Previous article:Application of single chip microcomputer in household multifunctional electric water heater
Next article:Hardware Design of Sound Acquisition System Based on DSP
Recommended ReadingLatest update time:2024-11-17 05:44
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- Rambus Launches Industry's First HBM 4 Controller IP: What Are the Technical Details Behind It?
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- LTE Cat 1 STM32 4G EC200S
- Single-ended to balanced conversion, the actual situation is so different from the simulation, why?
- [NXP Rapid IoT Review] + Preliminary Study on Power Consumption of Some Devices
- WWAYM launches NWRCFil low-pass filter
- Embedded Linux Learning Route Planning
- Today is the summer solstice. I heard that those who went out at noon had no shadow.
- Panta STM32H750 Part 6 (Using timer synchronization to generate a specified number of PWM pulses)
- The TI Cup is coming soon. Which editions have you participated in?
- The topology of the switching power supply in the electric competition must be solved according to the problem-solving ideas
- I encountered a problem. Before the program was burned, the voltage obtained by AIO4 was half of the battery voltage. After the program was burned...