Ethernet smart home controller design

1 Introduction 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 architecture. The purpose of this paper is to design a low-cost, general-purpose home-based smart home controller that integrates local control and remote control to control the operation of indoor appliances and the collection of environmental parameters. The local control in the design uses infrared technology. The remote control realizes the embedded Web server by developing the streamlined TCP/IP protocol and the HTTP protocol, so that the user can control and monitor the equipment and environment in the home through any browser. . 2 Ethernet smart home controller hardware design The smart home controller adopts 8-bit single-chip microcomputer W78E58B as the core processing unit of the system. The hardware block diagram of the system is shown in Figure 1.

This article refers to the address: http://


The local end is based on infrared communication technology, the transmitting end adopts NB9148 infrared encoding module, the receiving end adopts SJ1838 for receiving and demodulating, and the control signal is transmitted to W78E58B. External expansion RAM 62256 to improve the data transfer speed of the microcontroller and the processing of complex TCP/IP protocols. RS232 serial communication is mainly used for downloading and debugging of programs, as well as communication conversion interface. The GAL device ATF16V8B is used for chip selection to save system space resources.

The DS18B20 is used for ambient temperature acquisition.
The hardware platform for remote control consists of W78E58B and Ethernet controller RTL8019AS. The RTL8019AS is a dedicated Ethernet control chip designed for the ISA bus to implement the physical layer protocol of the network. The RTL8019AS has a built-in 10BASE-T transceiver that uses a jumper to connect to the RJ-45 through a network filter 20F-01 that improves the interference immunity of network communications. E2PROM AT24C512 is used to implement web file storage for embedded web server access. It is also used to store some settings of users such as IP address, gateway and MAC address of network card chip.

3 Ethernet smart home controller software design Ethernet smart home controller software implementation is completed on the microcontroller, mainly including virtual I2C bus read and write program, infrared receiving and control program, temperature acquisition program, network card chip RTL8019AS driver , the implementation of the embedded Web server and other handlers. In this article, only the driver of the network card chip and the implementation of the embedded Web server are discussed.
3.1 Ethernet Controller RTL8019AS Driver
The driver for the RTL8019AS is the program interface between the TCP/IP protocol and the underlying physical device. It masks the details of the underlying hardware processing and provides a hardware-independent interface to the upper layer software. The TCP/IP protocol can receive and transmit Ethernet data by simply calling the Ethernet driver. The driver of the network card chip RTL8019AS includes the RTL8019AS initialization program, the packet receiving program, and the packet transmitting program.
3.1.1 RTL8019AS Initialization
The RTL8019AS is reset by the RSTDRV pin. After reset, initialize the RTL8019AS first. The initialization operation includes setting PSTART=0x4c, PSTOP=0x80, so that 0x40~0x4b is the transmission buffer of the network card, 0x4c~0x7f is the receiving buffer of the network card; setting RCR=0xcc, only receiving the data of the target physical address and setting the physical address Packet, broadcast address data packet and multicast address pack; set TCR=0xe0, work in normal mode; set DCR=0xc8, use FIFO buffer and 8-bit data DMA; set IMR=0x00, mask all interrupts; multicast address register MAR0 ~ MAR7, are set to 0x00; set the network card physical address register PAR0 ~ PAR5; set CR = 0x22, select the register of page 0, enter the normal working state; set ISR = 0xff, clear all interrupt flag bits.
3.1.2 RTL8019AS Data Transmission

First, the data to be sent is encapsulated in the Ethernet data frame format, and then the CR register is set to 12H to start the remote write DMA. The RTL8019AS will automatically send the frame data to the data transmission buffer of the RTL8019AS, and write the result to the status register. . Finally, set CR to 3EH, start the local write DMA and 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 receive buffer forms a circular FIFO queue. The PSTART and PSTOP registers define the start and end pages of the cyclic queue; CURR is the write pointer and 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.


3.2 Embedded Web Server Implementation The W78E58B 8-bit MCU is used in the design. Due to the limited storage space of the MCU, the processing speed is relatively slow, and the complete TCP/IP protocol is not required in the entire remote control. Therefore, the streamlined TCP/IP protocol can be employed in remotely controlled network connection and access technologies. To implement the interactive function, it is necessary to implement the HTTP protocol based on the streamlined TCP/IP protocol and build an embedded Web server. The streamlined 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:
1 link layer. The design is connected to the Internet through Ethernet, so the physical layer and data link layer must conform to the IEEE802.3 standard of Ethernet. However, the hardware component of the Ethernet controller RTL8019AS has implemented the CSMA/CD control mechanism, masking the details of the underlying hardware processing, and providing hardware-independent interfaces to the upper layer software, ultimately completing the reception of data in the Ethernet. send. Therefore, the design of the physical layer and the data link layer in the design is implemented by the RTL8019AS hardware and driver.
2 The network layer implements ARP protocol, ICMP protocol and IP protocol. ARP is an address resolution protocol. The specific process is that when an ARP packet is received, the processor checks whether the IP address is a request or a response. If it is a response, the NIC address in the response is stored in the ARP cache table; if it is a request, the processor will return its own physical address of the NIC to the other party. ICMP is a request to debug the response to PING to check if the network is compliant. According to the requirements of the actual application of the system, the IP protocol only needs to implement datagram transmission and reception, and does not need to implement routing algorithm and error control, and does not need to support fragmentation and reassembly of IP datagrams.
3 The transport layer implements the TCP protocol. The TCP protocol is a connection-oriented, end-to-end reliable communication protocol. The design adopts the establishment and shutdown mechanism of TCP connection, timeout retransmission mechanism, data packet confirmation mechanism and flow control mechanism to ensure its reliability. In the timeout retransmission mechanism, if the acknowledgment has not been received after the timeout retransmission timer overflows, the data packet is retransmitted and the retransmission timer is reset. For the sake of simplicity, the program only sends one TCP packet at a time, and then waits for its acknowledgment, and will continue to send the following TCP packet only after receiving the acknowledgment. In this design, the interval of program retransmission is fixed, and the standard algorithm in the TCP protocol is not used. When the sender has not received the acknowledgment after reaching a certain number of times, the packet transmission is abandoned and the TCP connection is closed. TCP traffic control is to coordinate the transmission and reception of both sides of the communication

Designed with unbalanced rates. The design considers that when the system uses the TCP protocol, only one medium IP packet size receive buffer is set, so the receive window is constantly set to 1024. In this way, the remote host communicates with the local web server at a slower transmission rate without causing a crash.
4 The application layer implements the HTTP protocol. HTTP is a protocol for communicating between a web server and a browser. For simplicity, the design uses a fixed HTTP header to encapsulate HTTP response data packets. The format is as follows:
Char code html_header[ ] //The response header of the server when the client accesses the home page
= {"HTTP/1.1 200 OKn" //Respond Line, the status is OK, indicating that the file can be read.
"Cache-control: no-cachen" //No cache control
"Connection: Keep-Aliven" //Sustainable link to HTTP/1.1
"Content-Length: TAG: LEN1n" // file length
"Content-Type: text/htmlrnrn" };//The file format of the client GET request is in response to the HTTP request, since the data portion of the Ethernet packet cannot exceed 1500 bytes, so when sending data exceeds 1500 bytes, it is required Send by packet.
3.3 Ethernet Smart Home Controller Remote Control Operation Result After the smart home controller is connected to the Ethernet, the user can log in to the remote control interface by simply entering the IP address of the controller in the browser. When the username and password are entered correctly, the control page is accessed and the user can access and control each subsystem.
Figure 4 shows the control page of the smart home appliance. The system uses the GIF format picture to indicate 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 opposite state image into the corresponding position of the web page. At the same time, the MCU will output a level opposite to the previous state at the control port of the corresponding home appliance. At this time, the relay operates and the operating state of the home appliance changes. Finally, the smart home web server sends the new HTML page back to the client, the browser updates the page, and displays the changed home appliance status.


The software system of the smart home web server also enables the timing mechanism. When 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 re-entering the control page to perform the operation, which greatly improves the security of the entire smart home control system.

Coils

Car Phone Wireless Charging Coil,Circuit Board Induction Coils,Intersection Induction Coils,Induction Coil Set

Shenzhen Sichuangge Magneto-electric Co. , Ltd , https://www.scginductor.com