#incl



ude 
"mbed.h"
#include "EthernetInterface.h"
#include "AX12.h"
#define WEB_SERVER_PORT   80
char send_dat[1024]={0,};
uint16_t calcu_len(void);
float tempC;
AnalogIn   ain(A0); // connect A0(WIZwiki-W7500) to Vout(Temp36)
AX12 feed (PA_13, PA_14, 2);
int main (void
{
    printf("Wait a second...rn");
    uint8_t mac_addr[6] = {0x000x080xDC0x000x010x02}; 
    const char ip_addr[] = "192.168.0.222"
    const char mask_addr[] = "255.255.255.0"
    const char gateway_addr[] = "192.168.0.1";
    
    uint16_t len;
    EthernetInterface eth;
    //eth.init(mac_addr); //Use DHCP
    eth.init(mac_addr, ip_addr, mask_addr, gateway_addr); //Use Static
    eth.connect();
    printf("Server IP Address is %srn", eth.getIPAddress());
    
    TCPSocketServer server;
    server.bind(WEB_SERVER_PORT);
    server.listen();
    feed.SetGoal(939,1);
    while (true
    {
        printf("Wait for new connection...rn");
        TCPSocketConnection client;
        server.accept(client);
        client.set_blocking(false15000); // Timeout after (1.5)s
        
        printf("Connection from: %srn", client.get_address());
        char buffer[256];
        char dat[128];
        char *dat_temp;
        
        memset(dat, 0sizeof(dat));
        memset(send_dat, 0sizeof(send_dat));
        memset(buffer, 0sizeof(buffer));
        
        while (true) {
            
            wait(0.5);
            int n = client.receive_all(buffer, sizeof(buffer));
            if (n <= 0break;
            //buffer[n] = '';
            
            printf("rev_dat : %srn", buffer);
            
            float V = ain.read() * 3.3// connect Vs(Temp36) to 3.3V(WIZwiki-W7500)      
            tempC = (V-0.5) * 100// calculate temperature C
                       
            if((buffer[0]=='G')&&(buffer[1]=='E')&&(buffer[2]=='T')&&(buffer[3]==' '))// GET_Request
            { 
                if((buffer[5]=='?'))
                {
                    feed.SetGoal(554,1);
                    feed.SetGoal(554,1);
                    wait(1.0);
                    feed.SetGoal(939,1);
                    feed.SetGoal(939,1);
                }
                dat_temp = "HTTP/1.1 200 OKrn";                           strcat(dat, dat_temp);
                dat_temp = "Content-Type: text/htmlrn";                   strcat(dat, dat_temp);
                dat_temp = "Connection: closern";                         strcat(dat, dat_temp);
                //len = calcu_len();
                sprintf(dat, "%sContent-Length: %drnrn", dat, calcu_len());     strcat(dat, dat_temp);
            
                client.send(dat, strlen(dat));
                printf("send_dat : %srn", dat);
            
                client.send(send_dat, sizeof(send_dat));   
                printf("send_dat : %srn", send_dat);
                //printf("send_dat size : %drn", len);
                
                memset(dat, 0sizeof(dat));
                memset(send_dat, 0sizeof(send_dat));
                memset(buffer, 0sizeof(buffer));
            }
            
        }
        
        client.close();
    }
    
}
uint16_t calcu_len(void)
{
    char * dat_temp;
    char * forbidden = NULL;
    char str[4]={0,};
 
    //dat_temp = "<!DOCTYPE HTML>rn";                                                                       strcat(send_dat, dat_temp);
    dat_temp = "<html>rn";                                                                                strcat(send_dat, dat_temp);
    dat_temp = "rn";                                                                                  strcat(send_dat, dat_temp);
    dat_temp = "<head>rn";                                                                                strcat(send_dat, dat_temp);
    dat_temp = "<meta http-equiv="content-type" content="text/html; charset=euc-kr">rn";              strcat(send_dat, dat_temp);
    dat_temp = "<title>fishbowl</title>rn";                                                               strcat(send_dat, dat_temp);
    dat_temp = "<meta name="generator" content="Namo WebEditor">rn";                                  strcat(send_dat, dat_temp);
    dat_temp = "</head>rn";                                                                               strcat(send_dat, dat_temp);
    dat_temp = "rn";                                                                                      strcat(send_dat, dat_temp);
    dat_temp = "<body bgcolor="white" text="black" link="blue" vlink="purple" alink="red">rn";  strcat(send_dat, dat_temp);
    dat_temp = "<p>fishbowl</p>rn";                                                                       strcat(send_dat, dat_temp);
    //dat_temp = "<p> </p>rn";                                                                         strcat(send_dat, dat_temp);
    dat_temp = "<p>Temperature in the fishbowl = $$$$$</p>rn";                                            strcat(send_dat, dat_temp);
    
    dat_temp = "<form name="form1">rn";                                                                 strcat(send_dat, dat_temp);
    dat_temp = "<p><input type="hidden" name="do" value="ON"></p>rn";                               strcat(send_dat, dat_temp);
    dat_temp = "<p>FEED <input type="button" name="formbutton1" value="ON" onclick="submit();"></p>rn";                   strcat(send_dat, dat_temp);
    dat_temp = "</form>rn";                                                                               strcat(send_dat, dat_temp);
    
    //dat_temp = "<p></p>rn";                                                                               strcat(send_dat, dat_temp);
    dat_temp = "</body>rn";                                                                               strcat(send_dat, dat_temp);
    dat_temp = "rn";                                                                                      strcat(send_dat, dat_temp);
    dat_temp = "</html>rn";                                                                               strcat(send_dat, dat_temp);
    forbidden = strstr(send_dat, "$$$$$");
    memset(forbidden,0,5);
    sprintf((char*)str, "%5.2f", tempC);
    memcpy(forbidden,str,5);
 
    return strlen(send_dat);
}