Design of smart home controller based on Ethernet

Publisher:温柔花香Latest update time:2013-11-30 Source: dzscKeywords:Ethernet Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
  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 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.

Keywords:Ethernet Reference address:Design of smart home controller based on Ethernet

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

STM32NET study notes ARP and Ethernet part
1 Introduction (Collected notes in early 2013, published to CSDN blog at the end of 2013) Embedded Ethernet development is a very challenging job. After several months of study, I personally feel that there are roughly two ways. The first way is to be familiar with socket programming through high-level languages, su
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号