Select Page

Ethernet based Home Automation System

Ethernet based Home Automation System is a system in which any household appliance can be controlled remotely from LAN / Wifi using very low power embedded web-server.

Introduction

We have developed a web-server code that is ported on Comstick which is a ARM9 based micro-controller development board. Micro-controller runs FreeRTOS and uIP TCP/IP stack. Micro-controller stores required html pages for server in its flash. We were able to access server from anywhere inside the IISc’s local network. Page has user interface to control output pins of board or to read ADC/pin input. We have used IAR Embedded Workbench for code development and debugging.

Hardware Platform

Processor Requirements

  • Inbuilt Ethernet Support
  • Higher Operating Frequency for Faster packet processing
  • Large Flash memory – for storing webpages content
  • Enough RAM to accommodate various IP packets in buffer while processing others.

    STR 912 Processor

    For this purpose we have selected STR912FW44X processor. Main features of the processor which will be useful to our application

    • ARM966E-S 96Mhz
    • 512K+32K internal Flash,
    • 96K internal RAM
    • 9 DMA channels (inlcuding DMA for Ethernet)
    • 10/100Mbit Ethernet MAC
    • 10 bit ADC

    STR9 Comstick

    Comstick is STR912FW44X development board by Hitex. It has a USB debugger, Ethernet and USB port and a general purpose a GPIO port which has alternate functions for CAN and ADC. It is very small size board suitable for our application where this board can be placed inside switch board to control devices.

    Software Library

    uIP TCP/IP Stack

    uIP is open source lightweight TCP/IP stack. It takes care of most of the main features of TCP/IP, it also provides ARPUDP , ICMP ping support. Using uIP Stack, it is very easy to implement Http webserver and Client. Its documentation can be found here [3].

    FreeRTOS

    FreeRTOS is Real Time Operating System which we have ported on STR912. Embedding uIP Stack in FreeRTOS ensure proper timing for TCP/IP packet processing. Many demos which using different TCP/IP stacks embedded in FreeRTOS are available on [4].

    Implementation of Webserver

    Webserver code consist of major 3 parts.

    1. Code for parsing URL and returning appropriate file including HTTP header.
    2. Storing html pages,css,images in hex.
    3. http-cgi server side scripts.

    We have used FreeRTOS embeddedTCP demo for IAR [5] as reference and modified it for adding more functionality.

    We will show the changes/additions required in uip http demo in order to run your own Web Page.

    • Select uIP TCP/IP Stack and disable all other tasks.
    • Change 91x_conf file according to configuration of STR9 Comstick.
    • Assign Physical Address MAC and IP address in uip_Task.c

    To add additional functions

    • Add CGI Keyword in html page. Starting from %! {keyword}

    for example, page to display temperature value.

    <html>
    <head>
    </head>
    <body onLoad="window.setTimeout("location.href='temperature.shtml'",7000)">
    %! temperature
    </body>
    </html>
    
    • Callback function
    HTTPD_CGI_CALL(temperature, "temperature", temperature_value);
    static const struct httpd_cgi_call *calls[] = {&temperature,NULL};
    
    static unsigned short 
    generate_temperature(void *arg) {
     return snprintf((char *)uip_appdata, UIP_APPDATA_SIZE,"%u °C\n",(int)temperature_measure());
    }
    

    Data written in uip_appdata will replace ‘%! {keyword}’ in html page.

    httpd_cgi function compares the name from httpd_cgi_call buffer and invokes corresponding function. The invoked function may include call to some extern functions for application, then it returns with length of string to be sent by SOCK which is put in buffer named appdata.

    Demo

    We had demonstrated major 3 Type of Remote Control.

    Controlling 230VAC Device

    User should Switch On/Off any device connected to 230V AC via Webserver interface. To demonstrate it, we controlled CFL lamp connected to AC using mechanical relay circuit. Relay was made on or off according to request received from Webpage. To isolate relay circuit to our Comstick board to prevent any type of damages due to spikes we used MCT2E opto-isolator.

    Controlling 230V AC Device from STR9 Comstick

    Reading Status of Sensor

    This type of control is required when a user want to monitor status of a sensor. We used a Motion Sensor (PIR sensor) which gives digital output according to human presence in the room. Server webpage will display sensor status.

    Reading Analog sensor value

    This type of control is required when user wants to measure or log information which is analog, like if we want to monitor temperature of room or we want to see graph of power consumption in room we can use this feature. For demo we have attached potentiometer to input of ADC whose value were displayed on Server webpage.

    Project Setup

    Future Improvements

    As webclient code was also tested on same board, it can be used for many applications

    • Instead of just LAN or Wifi, controlling devices from internet can be very usefull.
    • Notifications on certain sensor value change. Burglar alarm.
    • TweetPlant is very interesting application in which sensor measures humidity of soil and tweets or mail when they require watering. This kind of application can be used in farms.

    References

    1. http://www.hitex.com/?id=383
    2. http://www.st.com/internet/mcu/product/165891.jsp
    3. http://www.freertos.org/embeddedtcp.html