Exemplo n.º 1
0
// prepare the webpage by writing the data to the tcp send buffer
uint16_t print_webpage(uint8_t *buf)
{
        uint16_t plen;
        char vstr[5];
        plen=http200ok();
        plen=fill_tcp_data_p(buf,plen,PSTR("<h2>Email notification status</h2>\n<pre>\n"));
        plen=fill_tcp_data_p(buf,plen,PSTR("Number of PD6 to GND connections: "));
        // convert number to string:
        itoa(contact_onoff_cnt,vstr,10);
        plen=fill_tcp_data(buf,plen,vstr);
        plen=fill_tcp_data_p(buf,plen,PSTR("\nNumber of email attempts: "));
        // convert number to string:
        itoa(web_client_attempts,vstr,10);
        plen=fill_tcp_data(buf,plen,vstr);
        plen=fill_tcp_data_p(buf,plen,PSTR("\nNumber successful emails: "));
        // convert number to string:
        itoa(web_client_sendok,vstr,10);
        plen=fill_tcp_data(buf,plen,vstr);
        plen=fill_tcp_data_p(buf,plen,PSTR("\nDate of last mail: "));
        plen=fill_tcp_data(buf,plen,datebuf);
        plen=fill_tcp_data_p(buf,plen,PSTR("\nEmail notify is: "));
        if (start_web_client==4){
                plen=fill_tcp_data_p(buf,plen,PSTR("OFF"));
        }else{
                plen=fill_tcp_data_p(buf,plen,PSTR("ON"));
        }
        plen=fill_tcp_data_p(buf,plen,PSTR("\n<form action=/ method=get>\npassw: <input type=password size=8 name=pw><input type=hidden name=mn "));
        if (start_web_client==4){
                plen=fill_tcp_data_p(buf,plen,PSTR("value=1><input type=submit value=\"enable email\">"));
        }else{
                plen=fill_tcp_data_p(buf,plen,PSTR("value=0><input type=submit value=\"disable email\">"));
        }
        plen=fill_tcp_data_p(buf,plen,PSTR("</form>\n</pre><br><hr>tuxgraphics.org"));
        return(plen);
}
Exemplo n.º 2
0
// prepare the webpage by writing the data to the tcp send buffer
unsigned int print_webpage(unsigned char *buf,unsigned char on_off)
	{
    unsigned int plen;
    plen=fill_tcp_data_p(buf,0,PSTR("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\nPragma: no-cache\r\n\r\n"));
    plen=fill_tcp_data_p(buf,plen,PSTR("<h1 align=center>LCSOT²âÊÔÒ³Ãæ</h1><hr>"));
	plen=fill_tcp_data_p(buf,plen,PSTR("<center><p>״̬: "));
    if (on_off)
			{
            plen=fill_tcp_data_p(buf,plen,PSTR("<font color=\"#00FF00\"> ¿ª</font>"));
    		}
		else
			{
            plen=fill_tcp_data_p(buf,plen,PSTR("¹Ø"));
    		}
    plen=fill_tcp_data_p(buf,plen,PSTR(" <small><a href=\""));
    plen=fill_tcp_data(buf,plen,baseurl);
    plen=fill_tcp_data(buf,plen,password);
    plen=fill_tcp_data_p(buf,plen,PSTR("\">[Ë¢ÐÂ]</a></small></p>\n<p><a href=\""));
    // the url looks like this http://baseurl/password/command
    plen=fill_tcp_data(buf,plen,baseurl);
    plen=fill_tcp_data(buf,plen,password);
    if (on_off)
			{
            plen=fill_tcp_data_p(buf,plen,PSTR("/0\">¹Ø±Õ</a><p>"));
    		}
		else
			{
            plen=fill_tcp_data_p(buf,plen,PSTR("/1\">¿ªÆô</a><p>"));
    		}
    plen=fill_tcp_data_p(buf,plen,PSTR("</center><hr><p align=center>ÏêϸÐÅÏ¢Çë·ÃÎÊ£º<a href=\"http://www.lcsoft.net\">http://www.lcsoft.net</a></p>"));
    //plen=fill_tcp_data_p(buf,plen,PSTR(WebSide));
    
    return(plen);
	}
Exemplo n.º 3
0
uint16_t print_net_config(void)
{
	uint16_t plen;
	plen=http200ok();
	
	// Check if gatewy MAC look-up has been already done
	if (gw_arp_state==GW_ARP_STATE_IN_PROGRESS)
	{
		plen=fill_tcp_data_p(buf,plen,PSTR("waiting for GW MAC\n"));
		return(plen);
	}
	plen=fill_tcp_data_p(buf,plen,PSTR("<a href=/>[home]</a>"));
	plen=fill_tcp_data_p(buf,plen,PSTR("<h2>Network config</h2><pre>\n"));
	plen=fill_tcp_data_p(buf,plen,PSTR("<form action=/u method=get>"));
	plen=fill_tcp_data_p(buf,plen,PSTR("DHCP:<input type=checkbox value=1 name=dh "));
	if (dhcpOn){
		plen=fill_tcp_data_p(buf,plen,PSTR("checked"));
	}
	plen=fill_tcp_data_p(buf,plen,PSTR(">\nIP=<input type=text name=ip value="));
	mk_net_str(gStrbuf,myip,4,'.',10);
	plen=fill_tcp_data(buf,plen,gStrbuf);
	plen=fill_tcp_data_p(buf,plen,PSTR(">\ngwip=<input type=text name=gi value="));
	mk_net_str(gStrbuf,gwip,4,'.',10);
	plen=fill_tcp_data(buf,plen,gStrbuf);
	plen=fill_tcp_data_p(buf,plen,PSTR(">\nHeartbeat timeout=<input type=text name=hb value="));
	itoa(heartbeat_timeout_sec,gStrbuf,10);
	plen=fill_tcp_data(buf,plen,gStrbuf);
	plen=fill_tcp_data_p(buf,plen,PSTR(">\nPasswd: <input type=password name=pw>\n"));
	
	plen=fill_tcp_data_p(buf,plen,PSTR("<input type=submit value=change></form>\n<hr>"));
	return(plen);
}
Exemplo n.º 4
0
uint16_t print_alarm_config(void)
{
	uint16_t plen;
	plen=http200ok();
	
	// Check if gatewy MAC look-up has been already done
	if (gw_arp_state==GW_ARP_STATE_IN_PROGRESS)
	{
	        plen=fill_tcp_data_p(buf,plen,PSTR("waiting for GW MAC\n"));
		    return(plen);
	}
	plen=fill_tcp_data_p(buf,plen,PSTR("<a href=/>[home]</a>"));
	plen=fill_tcp_data_p(buf,plen,PSTR("<h2>Alarm config</h2><pre>\n"));
	plen=fill_tcp_data_p(buf,plen,PSTR("<form action=/u method=get>"));
	plen=fill_tcp_data_p(buf,plen,PSTR("Enabled:<input type=checkbox value=1 name=ae "));
	if (alarmOn){
		plen=fill_tcp_data_p(buf,plen,PSTR("checked"));
	}
	plen=fill_tcp_data_p(buf,plen,PSTR(">\nName:   <input type=text name=n value=\""));
	plen=fill_tcp_data(buf,plen,myname);
	plen=fill_tcp_data_p(buf,plen,PSTR("\">\nSendto: ip=<input type=text name=di value="));
	mk_net_str(gStrbuf,udpsrvip,4,'.',10);
	plen=fill_tcp_data(buf,plen,gStrbuf);
	plen=fill_tcp_data_p(buf,plen,PSTR("> port=<input type=text name=dp size=4 value="));
	itoa(udpsrvport,gStrbuf,10);
	plen=fill_tcp_data(buf,plen,gStrbuf);
	plen=fill_tcp_data_p(buf,plen,PSTR(">\nPasswd: <input type=password name=pw>\n"));
	
	plen=fill_tcp_data_p(buf,plen,PSTR("<input type=submit value=change></form>\n<hr>"));
	return(plen);
}
Exemplo n.º 5
0
/*---------------------------------------------------------------------------*/
uint16_t create_GetRequest(const uint8_t* urlBase, uint8_t* urlSuffix, uint8_t* respBuff, uint16_t tcpLen)
{
  tcpLen = fill_tcp_data(respBuff,tcpLen,"GET "); 
  tcpLen = fill_tcp_data(respBuff,tcpLen,urlSuffix); 
  tcpLen = fill_tcp_data(respBuff,tcpLen," HTTP/1.1\r\nUser-Agent: curl/7.37.1\r\nHost: "); 
  tcpLen = fill_tcp_data(respBuff,tcpLen,urlBase); 
  tcpLen = fill_tcp_data(respBuff,tcpLen,"\r\nAccept: */*\r\n\r\n"); 
  
  return tcpLen;
}
Exemplo n.º 6
0
// prepare the webpage by writing the data to the tcp send buffer
uint16_t print_webpage(uint8_t *buf)
{
        uint16_t plen;
        char vstr[15];
        plen=http200ok();
        plen=fill_tcp_data_p(buf,plen,PSTR("<a href=/>[refresh]</a>"));
        plen=fill_tcp_data_p(buf,plen,PSTR("<h2>identi.ca notification status</h2>\n<pre>\n"));
        if (client_waiting_gw()){
                plen=fill_tcp_data_p(buf,plen,PSTR("waiting for GW IP to answer arp.\n"));
                return(plen);
        }
        if (dns_state==1){
                plen=fill_tcp_data_p(buf,plen,PSTR("waiting for DNS answer.\n"));
                return(plen);
        }
        /* // debug
        plen=fill_tcp_data_p(buf,plen,PSTR("\nweb IP:\n"));
        mk_net_str(vstr, dnslkup_getip() ,4,'.',10);
        plen=fill_tcp_data(buf,plen,vstr);
        plen=fill_tcp_data_p(buf,plen,PSTR("\n"));
        */

        plen=fill_tcp_data_p(buf,plen,PSTR("Num of PD6 to GND connections: "));
        // convert number to string:
        itoa(contact_onoff_cnt,vstr,10);
        plen=fill_tcp_data(buf,plen,vstr);
        plen=fill_tcp_data_p(buf,plen,PSTR("\nNum of identi.ca attempts: "));
        // convert number to string:
        itoa(web_client_attempts,vstr,10);
        plen=fill_tcp_data(buf,plen,vstr);
        plen=fill_tcp_data_p(buf,plen,PSTR("\nNum successful identi.ca: "));
        // convert number to string:
        itoa(web_client_sendok,vstr,10);
        plen=fill_tcp_data(buf,plen,vstr);
        plen=fill_tcp_data_p(buf,plen,PSTR("\nDate of last identi.ca: "));
        plen=fill_tcp_data(buf,plen,datebuf);
        plen=fill_tcp_data_p(buf,plen,PSTR("\nTwitter notify is: "));
        if (start_web_client==4){
                plen=fill_tcp_data_p(buf,plen,PSTR("OFF"));
        }else{
                plen=fill_tcp_data_p(buf,plen,PSTR("ON"));
        }
        plen=fill_tcp_data_p(buf,plen,PSTR("\n<form action=/ method=get>\npassw: <input type=password size=8 name=pw><input type=hidden name=mn "));
        if (start_web_client==4){
                plen=fill_tcp_data_p(buf,plen,PSTR("value=1><input type=submit value=\"enable identi.ca msg\">"));
        }else{
                plen=fill_tcp_data_p(buf,plen,PSTR("value=0><input type=submit value=\"disable identi.ca msg\">"));
        }
        plen=fill_tcp_data_p(buf,plen,PSTR("</form>\n</pre><br><hr>tuxgraphics.org"));
        return(plen);
}
Exemplo n.º 7
0
/*-----------------------------------------------------------------------------
/ Tries to parse arguments like:
/  http://192.168.4.1/s,bu_bir_internet_agidir
/ and saves that string to proper EEPROM location
/------------------------------------------------------------------------------
/ tcpData[0 : 4]   => "GET /" => HTTP request header
/ tcpData[5 : 6]   => "s,"    => 's' is the ID for state machine and ',' is seperator
/ tcpData[7 : ...] => actual data we want to parse and store
/----------------------------------------------------------------------------*/
uint16_t parseTCP_setAndResponse(const char* name, uint8_t* eepromBaseAddr, uint8_t* ramBuffer, uint8_t maxLen,uint16_t tcpLen,uint8_t* respBuff)
{
  uint8_t ind = 0;

  while((tcpData[ind+7] != ' ') && (ind < (maxLen -1)))
  {
    ramBuffer[ind] = tcpData[ind+7];
    ind++;        
  }

  tcpLen = fill_tcp_data(respBuff,0,HTTP_RESPONSE_HEADER);

  if(ind < (maxLen -1))
  {
    ramBuffer[ind] = '\0';

    eeprom_update_block(ramBuffer,eepromBaseAddr,maxLen);

    tcpLen = fill_tcp_data(respBuff,tcpLen,name); 
    tcpLen = fill_tcp_data(respBuff,tcpLen," set to: ");
    tcpLen = fill_tcp_data(respBuff,tcpLen,ramBuffer);
    tcpLen = fill_tcp_data(respBuff,tcpLen,"\r\n");  
  }
  else
  {
    tcpLen = fill_tcp_data(respBuff,tcpLen,name);
    tcpLen = fill_tcp_data(respBuff,tcpLen," too long!\r\n");
  }

  return tcpLen;
}
Exemplo n.º 8
0
uint16_t printMinHTML ( uint8_t *buf, char whichSection )
{
  char buffer[10];
  uint16_t plen;
  uint8_t i;
  plen=http200ok();
  plen=fill_tcp_data_p ( buf, plen, PSTR("<!DOCTYPE html>\n<html>\n<body>\n<pre>\n") );
  for ( i = 60*whichSection ; i < 60 * whichSection + 60 ; i++ )
  {
    plen=fill_tcp_data_p(buf,plen,PSTR("\n#"));
    itoa (i, buffer, 10);
    plen=fill_tcp_data(buf, plen, buffer);
    plen=fill_tcp_data_p(buf,plen,PSTR(":"));
    itoa (readings[i], buffer, 10);
    plen=fill_tcp_data(buf, plen, buffer);
  }
  plen=fill_tcp_data_p ( buf, plen, PSTR("</pre>\n</body>\n</html>") );
  return( plen );
}
Exemplo n.º 9
0
// answer HTTP/1.0 301 Moved Permanently\r\nLocation: password/\r\n\r\n
// to redirect to the url ending in a slash
uint16_t moved_perm(uint8_t *buf)
{
	uint16_t plen;
	plen=fill_tcp_data_p(buf,0,PSTR("HTTP/1.0 301 Moved Permanently\r\nLocation: "));
	plen=fill_tcp_data(buf,plen,password);
	plen=fill_tcp_data_p(buf,plen,PSTR("/\r\nContent-Type: text/html\r\nPragma: no-cache\r\n\r\n"));
	plen=fill_tcp_data_p(buf,plen,PSTR("<h1>301 Moved Permanently</h1>\n"));
	plen=fill_tcp_data_p(buf,plen,PSTR("add a trailing slash to the url\n"));
	return(plen);
}
// prepare the webpage by writing the data to the tcp send buffer
uint16_t print_webpage(uint8_t *buf,uint8_t rev)
{
        char vstr[5];
        uint16_t plen;
        plen=fill_tcp_data_p(buf,0,PSTR("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n"));
        plen=fill_tcp_data_p(buf,plen,PSTR("<center><p>ENC28J60 silicon rev is: B"));
        itoa((enc28j60getrev()),vstr,10);
        plen=fill_tcp_data(buf,plen,vstr);
        plen=fill_tcp_data_p(buf,plen,PSTR("</center><hr><br>tuxgraphics.org\n"));
        return(plen);
}
Exemplo n.º 11
0
uint16_t printNowHTML ( uint8_t *buf )
{
  char buffer[10];
  uint16_t plen;
  uint8_t i;
  plen=http200ok();
  plen=fill_tcp_data_p ( buf, plen, PSTR("<!DOCTYPE html>\n<html>\n<body>\n<pre>\n") );
  itoa (currentUsage, buffer, 10);
  plen=fill_tcp_data(buf, plen, buffer);
  plen=fill_tcp_data_p ( buf, plen, PSTR("</pre>\n</body>\n</html>") );
  return( plen );
}
Exemplo n.º 12
0
/*
 * 函数名:print_webpage
 * 描述  :将数据写到tcp的发送缓冲区(以实现一个网页)
 * 输入  :-buf
 *         -on_off
 * 输出  :无
 * 返回  :-plen
 */
unsigned int print_webpage(unsigned char *buf,unsigned char on_off)
{
    unsigned int plen;
		/* 新建一个网页,就像新建一个文件一样 */
    plen=fill_tcp_data_p(buf,0,PSTR("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\nPragma: no-cache\r\n\r\n"));
	
		/* 在网页正中央填写信息 */
    plen=fill_tcp_data_p(buf,plen,PSTR("<center><p>灯光状态指示: "));

    if (on_off)
    {
        plen=fill_tcp_data_p(buf,plen,PSTR("<font color=\"#00FF00\"> 亮</font>"));
    }
    else
    {
        plen=fill_tcp_data_p(buf,plen,PSTR("灭"));
    }

    plen=fill_tcp_data_p(buf,plen,PSTR(" <small><a href=\""));
    plen=fill_tcp_data(buf,plen,baseurl);		 // 要在浏览器中输入的网址
    plen=fill_tcp_data(buf,plen,password);	 // 紧跟在网址后面的密码
    plen=fill_tcp_data_p(buf,plen,PSTR("\">[刷新]</a></small></p>\n<p><a href=\""));
    // the url looks like this http://baseurl/password/command
    plen=fill_tcp_data(buf,plen,baseurl);
    plen=fill_tcp_data(buf,plen,password);
    if (on_off)
    {
        plen=fill_tcp_data_p(buf,plen,PSTR("/0\">关闭灯光</a><p>"));
    }
    else
    {
        plen=fill_tcp_data_p(buf,plen,PSTR("/1\">打开灯光</a><p>"));
    }
    plen=fill_tcp_data_p(buf,plen,PSTR("</center><hr><br>****************^_^ 欢迎您使用智能家居管理系统 ^_^****************\n"));
    //plen=fill_tcp_data_p(buf,plen,PSTR("这是一个 web 测试程序"));
    
    return(plen);
}
Exemplo n.º 13
0
// main web page
uint16_t print_webpage(void)
{
	uint16_t plen;
	plen=http200ok();
	plen=fill_tcp_data_p(buf,plen,PSTR("<a href=/c>[alarm config]</a> <a href=/n>[network config]</a> <a href=./>[refresh]</a>"));
	plen=fill_tcp_data_p(buf,plen,PSTR("<h2>Alarm: "));
	plen=fill_tcp_data(buf,plen,myname);
	plen=fill_tcp_data_p(buf,plen,PSTR("</h2><pre>\n"));
	plen=fill_tcp_data_p(buf,plen,PSTR("Last alarm:\n"));
	if (lastAlarm){
		if (gMin>59){
			itoa(gMin/60,gStrbuf,10); // convert integer to string
			plen=fill_tcp_data(buf,plen,gStrbuf);
			plen=fill_tcp_data_p(buf,plen,PSTR("hours and "));
		}
		itoa(gMin%60,gStrbuf,10); // convert integer to string
		plen=fill_tcp_data(buf,plen,gStrbuf);
		plen=fill_tcp_data_p(buf,plen,PSTR("min ago"));
		}else{
		plen=fill_tcp_data_p(buf,plen,PSTR("none in last 14 days"));
	}
	plen=fill_tcp_data_p(buf,plen,PSTR("\n</pre><hr>\n"));
	return(plen);
}
Exemplo n.º 14
0
// answer HTTP/1.0 301 Moved Permanently\r\nLocation: .....\r\n\r\n
// to redirect
// type =0  : http://tuxgraphics.org/c.ico    favicon.ico file
// type =1  : /password/
uint16_t moved_perm(uint8_t *buf,uint8_t type)
{
        uint16_t plen;
        plen=fill_tcp_data_p(buf,0,PSTR("HTTP/1.0 301 Moved Permanently\r\nLocation: "));
        if (type==1){
                plen=fill_tcp_data_p(buf,plen,PSTR("/"));
                plen=fill_tcp_data(buf,plen,password);
                plen=fill_tcp_data_p(buf,plen,PSTR("/"));
        }else{
                plen=fill_tcp_data_p(buf,plen,PSTR("http://tuxgraphics.org/c.ico"));
                //plen=fill_tcp_data_p(buf,plen,PSTR("http://tuxgraphics.org/ico/print.ico"));
        }
        plen=fill_tcp_data_p(buf,plen,PSTR("\r\n\r\nContent-Type: text/html\r\n\r\n"));
        plen=fill_tcp_data_p(buf,plen,PSTR("<h1>301 Moved Permanently</h1>\n"));
        return(plen);
}
Exemplo n.º 15
0
// main webpage for setting the time and date
uint16_t print_webpage_clk(uint8_t *buf)
{
	uint16_t plen;
	plen=http200ok();
	
	plen=fill_tcp_data_p(buf,plen,PSTR("<style type=\"text/css\">* {padding:0;margin:0;} body {font-size:10pt;font-family:\"georgia\";color:#333333;background:#74888e;}\n"));
	plen=fill_tcp_data_p(buf,plen,PSTR("h5 {font-size:0.7em;} #outer {width:340px;border:2px solid #fff;background-color:#fff;margin:0 auto;} #header {background:#2b2b2b;margin-bottom:2px;}#headercontent {bottom:0;padding:0.7em 1em 0.7em 1em;}\n"));
	plen=fill_tcp_data_p(buf,plen,PSTR("#headercontent h1 {font-weight:normal;color:#fff;font-size:2.5em;}\n"));
	plen=fill_tcp_data_p(buf,plen,PSTR("#content {padding:2em 2em 0 2em;}\n"));
	plen=fill_tcp_data_p(buf,plen,PSTR("</style></head><body><div id=\"outer\"><div id=\"header\"><div id=\"headercontent\">"));
	// Webserver header
	plen=fill_tcp_data_p(buf,plen,PSTR("<h1>Klokke / dato</h1></div></div>\n"));
	plen=fill_tcp_data_p(buf,plen,PSTR("<div id=\"content\">\n"));
	//content
	plen=fill_tcp_data_p(buf,plen,PSTR("<a href=\"/cnf\"><< Tilbake</a><br><br>"));
	plen=fill_tcp_data_p(buf,plen,PSTR("<fieldset><legend>Sett ny tid og dato</legend>"));
	plen=fill_tcp_data_p(buf,plen,PSTR("<br><form action=/cdclk method=get>"));
	plen=fill_tcp_data_p(buf,plen,PSTR("<input type=text size=1 name=h value="));
	sprintf(strbuf,"%02d",ethPacket[pHour]);
	plen=fill_tcp_data(buf,plen,strbuf);
	plen=fill_tcp_data_p(buf,plen,PSTR(">"));
	plen=fill_tcp_data_p(buf,plen,PSTR(":"));
	plen=fill_tcp_data_p(buf,plen,PSTR("<input type=text size=1 name=m value="));
	sprintf(strbuf,"%02d",ethPacket[pMin]);
	plen=fill_tcp_data(buf,plen,strbuf);
	plen=fill_tcp_data_p(buf,plen,PSTR(">"));
	plen=fill_tcp_data_p(buf,plen,PSTR(":"));
	plen=fill_tcp_data_p(buf,plen,PSTR("<input type=text size=1 name=s value="));
	sprintf(strbuf,"%02d",ethPacket[pSec]);
	plen=fill_tcp_data(buf,plen,strbuf);
	plen=fill_tcp_data_p(buf,plen,PSTR(">"));
	plen=fill_tcp_data_p(buf,plen,PSTR("(hh:tt:ss)<br><br>"));
	plen=fill_tcp_data_p(buf,plen,PSTR("<input type=text size=1 name=dd value="));
	sprintf(strbuf,"%02d",ethPacket[pDate]);
	plen=fill_tcp_data(buf,plen,strbuf);
	plen=fill_tcp_data_p(buf,plen,PSTR(">"));
	plen=fill_tcp_data_p(buf,plen,PSTR("-"));
	plen=fill_tcp_data_p(buf,plen,PSTR("<input type=text size=1 name=mm value="));
	sprintf(strbuf,"%02d",ethPacket[pMonth]);
	plen=fill_tcp_data(buf,plen,strbuf);
	plen=fill_tcp_data_p(buf,plen,PSTR(">"));
	plen=fill_tcp_data_p(buf,plen,PSTR("-"));
	plen=fill_tcp_data_p(buf,plen,PSTR("<input type=text size=1 name=yy value="));
	sprintf(strbuf,"%02d",ethPacket[pYear]);
	plen=fill_tcp_data(buf,plen,strbuf);
	plen=fill_tcp_data_p(buf,plen,PSTR(">"));
	plen=fill_tcp_data_p(buf,plen,PSTR("(dd-mm-yy)<br><br>"));
	plen=fill_tcp_data_p(buf,plen,PSTR("Passord:<input type=password size=8 name=pw><br>"));
	plen=fill_tcp_data_p(buf,plen,PSTR("<input type=submit value=\"OK\"></form><br></fieldset><br>"));
	
	return(plen);
}
Exemplo n.º 16
0
// main site for control
uint16_t print_webpage_config(uint8_t *buf)
{
	uint16_t plen;
	plen=http200ok();
	
	plen=fill_tcp_data_p(buf,plen,PSTR("<style type=\"text/css\">*{padding:0;margin:0;}body{font-size:10pt;font-family:\"georgia\";color:#333333;background:#74888e;}"));
	plen=fill_tcp_data_p(buf,plen,PSTR("h5{font-size:0.7em;}#outer{width:350px;border:2px solid #fff;background-color:#fff;margin:0 auto;}#header{background:#2b2b2b;margin-bottom:2px;}#headercontent{bottom:0;padding:0.7em 1em 0.7em 1em;}"));
	plen=fill_tcp_data_p(buf,plen,PSTR("#headercontent h1{font-weight:normal;color:#fff;font-size:2.5em;}#menu{position:relative;background:#2b2b2b;height:3.5em;padding:0 1em 0 1em;margin-bottom:2px;}#menu ul{position:absolute;top:1.1em;}"));
	plen=fill_tcp_data_p(buf,plen,PSTR("#menu ul li{display:inline;}#menu ul li a{padding:0.5em 1em 0.9em 1em;color:#fff;}#content{padding:2em 2em 0 2em;}"));
	plen=fill_tcp_data_p(buf,plen,PSTR("</style></head><body><div id=\"outer\"><div id=\"header\"><div id=\"headercontent\">"));
	// Webserver header
	plen=fill_tcp_data_p(buf,plen,PSTR("<h1>Kontroll</h1></div></div>"));
	plen=fill_tcp_data_p(buf,plen,PSTR("<div id=\"menu\"><ul>"));
	//the "menu" or links
	plen=fill_tcp_data_p(buf,plen,PSTR("<li><a href=\"/\">Hoved</a></li>"));
	plen=fill_tcp_data_p(buf,plen,PSTR("<li><a href=\"/room1\">Rom-1</a></li>"));
	plen=fill_tcp_data_p(buf,plen,PSTR("<li><a href=\"/room2\">Rom-2</a></li>"));
	plen=fill_tcp_data_p(buf,plen,PSTR("<li><a href=\"/clk\">Klokke</a></li>"));
	plen=fill_tcp_data_p(buf,plen,PSTR("</ul></div><div id=\"content\">"));
	
	// Change the IP
	plen=fill_tcp_data_p(buf,plen,PSTR("<fieldset><legend><h4>Endre IP</h4></legend>"));
	plen=fill_tcp_data_p(buf,plen,PSTR("<form action=/ipc method=get>"));
	plen=fill_tcp_data_p(buf,plen,PSTR("<br>Passord:<input type=password size=8 name=pw><br>"));
	plen=fill_tcp_data_p(buf,plen,PSTR("Ny IP: <input type=text size=12 name=nip value="));
	mk_net_str(strbuf,myip,4,'.',10);
	plen=fill_tcp_data(buf,plen,strbuf);
	plen=fill_tcp_data_p(buf,plen,PSTR("><br>"));
	plen=fill_tcp_data_p(buf,plen,PSTR("<input type=submit value=\"OK\"></form><br></fieldset>"));
	
	// Change the password
	plen=fill_tcp_data_p(buf,plen,PSTR("<br><fieldset><form action=/ipc method=get>"));
	plen=fill_tcp_data_p(buf,plen,PSTR("<br>Gammelt passord:<input type=password size=8 name=pw><br>"));
	plen=fill_tcp_data_p(buf,plen,PSTR("Nytt passord: <input type=password size=8 name=npw><br>"));
	plen=fill_tcp_data_p(buf,plen,PSTR("<input type=submit value=\"OK\"></form><br></fieldset>"));
	
	return(plen);
}
Exemplo n.º 17
0
uint16_t EtherShield::ES_fill_tcp_data(uint8_t *buf,uint16_t pos, const char *s){
	return fill_tcp_data(buf,pos, s);
}
Exemplo n.º 18
0
// prepare the webpage by writing the data to the tcp send buffer
uint16_t print_webpage(uint8_t *buf)
{
	uint16_t plen;
	// periodic refresh every 60sec:
	plen=fill_tcp_data_p(buf,0,PSTR("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\nPragma: no-cache\r\nRefresh: 60\r\n\r\n"));
	// html code + css for giving the website a better userinterface
	//
	plen=fill_tcp_data_p(buf,plen,PSTR("<html><head><style type=\"text/css\">\n"));
	plen=fill_tcp_data_p(buf,plen,PSTR("* {padding:0;margin:0;} body,input {font-size:10pt;font-family:\"georgia\";background:#74888e;}\n"));
	plen=fill_tcp_data_p(buf,plen,PSTR("#outer {width:350px;border:2px solid #fff;background-color:#fff;margin:0 auto;} #header {background:#2b2b2b;margin-bottom:2px;}#headercontent {bottom:0;padding:0.7em 1em 0.7em 1em;}\n"));
	plen=fill_tcp_data_p(buf,plen,PSTR("h1 {color:#fff;font-size:2.5em;} #menu {position:relative;background:#2b2b2b;height:3.5em;padding:0 1em 0 1em;margin-bottom:2px;} #menu ul {position:absolute;top:1.1em;}\n"));
	plen=fill_tcp_data_p(buf,plen,PSTR("#menu ul li {display:inline;}#menu ul li a {padding:0.5em 1em 0.9em 1em;color:#fff;} #content {padding:2em 2em 0 2em;}\n"));
	plen=fill_tcp_data_p(buf,plen,PSTR("p.klokke {color:blue;font-size:2.5em;text-align:center;} p.dato {font-size:1em;text-align:center;}"));
	plen=fill_tcp_data_p(buf,plen,PSTR("</style></head><body><div id=\"outer\"><div id=\"header\"><div id=\"headercontent\">"));
	// Webserver header
	plen=fill_tcp_data_p(buf,plen,PSTR("<h1>Josematic 1.0b</h1></div></div>\n"));
	plen=fill_tcp_data_p(buf,plen,PSTR("<div id=\"menu\"><ul>\n"));
	//the "menu" or links
	plen=fill_tcp_data_p(buf,plen,PSTR("<li><a href=\"/\">Hoved</a></li>\n"));
	plen=fill_tcp_data_p(buf,plen,PSTR("<li><a href=\"/cnf\">Kontroll</a></li>\n"));
	plen=fill_tcp_data_p(buf,plen,PSTR("<li><a href=\"http://deface.no/hvp2009/\" target=\"_blank\">Hjelp</a></li>\n"));
	plen=fill_tcp_data_p(buf,plen,PSTR("</ul></div><div id=\"menubottom\"></div><div id=\"content\">"));
	
	// This is the start of the clock output
	plen=fill_tcp_data_p(buf,plen,PSTR("<p class=\"klokke\">"));
	
	// print out the hour
	sprintf(strbuf,"%02d",ethPacket[pHour]);
	plen=fill_tcp_data(buf,plen,strbuf);
	plen=fill_tcp_data_p(buf,plen,PSTR(":"));
	
	// minutes and so on..
	sprintf(strbuf,"%02d",ethPacket[pMin]);
	plen=fill_tcp_data(buf,plen,strbuf);
	plen=fill_tcp_data_p(buf,plen,PSTR(":"));
	
	// seconds
	sprintf(strbuf,"%02d",ethPacket[pSec]);
	plen=fill_tcp_data(buf,plen,strbuf);
	
	// This is the start of the date output
	plen=fill_tcp_data_p(buf,plen,PSTR("</p><p class=\"dato\">"));
	
	// date
	sprintf(strbuf,"%02d",ethPacket[pDate]);
	plen=fill_tcp_data(buf,plen,strbuf);
	plen=fill_tcp_data_p(buf,plen,PSTR(" - "));
	
	// month
	sprintf(strbuf,"%02d",ethPacket[pMonth]);
	plen=fill_tcp_data(buf,plen,strbuf);
	plen=fill_tcp_data_p(buf,plen,PSTR(" - "));
	
	// year
	sprintf(strbuf,"%02d",ethPacket[pYear]);
	plen=fill_tcp_data(buf,plen,strbuf);
	plen=fill_tcp_data_p(buf,plen,PSTR("</p><br><br>"));
	
	
	// The temperatur status
	// Room 1 status
	plen=fill_tcp_data_p(buf,plen,PSTR("<br>Rom-1: "));
	// Temperatur is blue for lower then 15 degrees, red for higher
	if (ethPacket[pTemp]<=15)
	{
		plen=fill_tcp_data_p(buf,plen,PSTR("<font color=blue> "));
		itoa(ethPacket[pTemp],strbuf,10);
		plen=fill_tcp_data(buf,plen,strbuf);
		plen=fill_tcp_data_p(buf,plen,PSTR("</font>&deg;C<br>"));
	}
	else
	{
		plen=fill_tcp_data_p(buf,plen,PSTR("<font color=red> "));
		itoa(ethPacket[pTemp],strbuf,10);
		plen=fill_tcp_data(buf,plen,strbuf);
		plen=fill_tcp_data_p(buf,plen,PSTR("</font>&deg;C<br>"));
	}
	plen=fill_tcp_data_p(buf,plen,PSTR("&Oslash;nsket temp: "));
	itoa(sm[0].temp,strbuf,10);
	plen=fill_tcp_data(buf,plen,strbuf);
	plen=fill_tcp_data_p(buf,plen,PSTR("&deg;C<br>"));
	
	// Check for slave status, 0 = off, 1 = on , 2 = not connected
	plen=fill_tcp_data_p(buf,plen,PSTR("Status: "));
	if (ethPacket[pStatus]==0)
	{
		plen=fill_tcp_data_p(buf,plen,PSTR("<font color=red> "));
		plen=fill_tcp_data_p(buf,plen,PSTR("Off"));
	}
	else if (ethPacket[pStatus]==1)
	{
		plen=fill_tcp_data_p(buf,plen,PSTR("<font color=green> "));
		plen=fill_tcp_data_p(buf,plen,PSTR("On"));
	}
	else if (ethPacket[pStatus]==2)
	{
		plen=fill_tcp_data_p(buf,plen,PSTR("<font color=red> "));
		plen=fill_tcp_data_p(buf,plen,PSTR("NC"));
	}
	plen=fill_tcp_data_p(buf,plen,PSTR("</font><br>"));
	
	// Room 2 status
	plen=fill_tcp_data_p(buf,plen,PSTR("<br>Rom-2: "));
	
	if ((ethPacket[pFieldsModules+pTemp])<=15)
	{
		plen=fill_tcp_data_p(buf,plen,PSTR("<font color=blue> "));
		itoa(ethPacket[pFieldsModules+pTemp],strbuf,10);
		plen=fill_tcp_data(buf,plen,strbuf);
	}
	else
	{
		plen=fill_tcp_data_p(buf,plen,PSTR("<font color=red> "));
		itoa(ethPacket[pFieldsModules+pTemp],strbuf,10);
		plen=fill_tcp_data(buf,plen,strbuf);
	}
	plen=fill_tcp_data_p(buf,plen,PSTR("</font> &deg;C<br>"));
	plen=fill_tcp_data_p(buf,plen,PSTR("&Oslash;nsket temp: "));
	itoa(sm[1].temp,strbuf,10);
	plen=fill_tcp_data(buf,plen,strbuf);
	plen=fill_tcp_data_p(buf,plen,PSTR("&deg;C<br>"));
	
	// Check for slave status, 0 = off, 1 = on , 2 = no change
	plen=fill_tcp_data_p(buf,plen,PSTR("Status: "));
	if (ethPacket[pFieldsModules+pStatus]==0)
	{
		plen=fill_tcp_data_p(buf,plen,PSTR("<font color=red> "));
		plen=fill_tcp_data_p(buf,plen,PSTR("Off</font><br>"));
	}
	else if (ethPacket[pFieldsModules+pStatus]==1)
	{
		plen=fill_tcp_data_p(buf,plen,PSTR("<font color=green> "));
		plen=fill_tcp_data_p(buf,plen,PSTR("On</font><br>"));
	}
	else if (ethPacket[pFieldsModules+pStatus]==2)
	{
		plen=fill_tcp_data_p(buf,plen,PSTR("<font color=red> "));
		plen=fill_tcp_data_p(buf,plen,PSTR("NC</font><br>"));
	}
	
	plen=fill_tcp_data_p(buf,plen,PSTR("<br><br></div></body></html>"));
	
	return(plen);
}
Exemplo n.º 19
0
// Control area for room-2
uint16_t print_webpage_room2(uint8_t *buf)
{
	uint16_t plen;
	plen=http200ok();
	plen=fill_tcp_data_p(buf,plen,PSTR("<style type=\"text/css\">* {padding:0;margin:0;} body {font-size:10pt;font-family:\"georgia\";color:#333333;background:#74888e;}\n"));
	plen=fill_tcp_data_p(buf,plen,PSTR("h5 {font-size:0.7em;} #outer {width:350px;border:2px solid #fff;background-color:#fff;margin:0 auto;} #header {background:#2b2b2b;margin-bottom:2px;}#headercontent {bottom:0;padding:0.7em 1em 0.7em 1em;}\n"));
	plen=fill_tcp_data_p(buf,plen,PSTR("#headercontent h1 {font-weight:normal;color:#fff;font-size:2.5em;}\n"));
	plen=fill_tcp_data_p(buf,plen,PSTR("#content {padding:2em 2em 0 2em;}\n"));
	plen=fill_tcp_data_p(buf,plen,PSTR("</style></head><body><div id=\"outer\"><div id=\"header\"><div id=\"headercontent\">"));
	// Webserver header
	plen=fill_tcp_data_p(buf,plen,PSTR("<h1>Rom-2</h1></div></div>\n"));
	plen=fill_tcp_data_p(buf,plen,PSTR("<div id=\"content\"><a href=\"/cnf\"><< Tilbake</a><br><br>\n"));
	
	// Room 2 status
	plen=fill_tcp_data_p(buf,plen,PSTR("Temperatur n&aring;:  "));
	// Temperatur is blue for lower then 15 degrees, red for higher
	if (ethPacket[pFieldsModules+pTemp]<=15)
	{
		plen=fill_tcp_data_p(buf,plen,PSTR("<font color=blue> "));
		itoa(ethPacket[pFieldsModules+pTemp],strbuf,10);
		plen=fill_tcp_data(buf,plen,strbuf);
	}
	else
	{
		plen=fill_tcp_data_p(buf,plen,PSTR("<font color=red> "));
		itoa(ethPacket[pFieldsModules+pTemp],strbuf,10);
		plen=fill_tcp_data(buf,plen,strbuf);
	}
	plen=fill_tcp_data_p(buf,plen,PSTR("</font>&deg;C<br>"));
	
	plen=fill_tcp_data_p(buf,plen,PSTR("&Oslash;nsket temp: "));
	itoa(sm[1].temp,strbuf,10);
	plen=fill_tcp_data(buf,plen,strbuf);
	plen=fill_tcp_data_p(buf,plen,PSTR("&deg;C<br><br>"));
	
	// Check for slave status, 0 = off, 1 = on , 2 = no change
	plen=fill_tcp_data_p(buf,plen,PSTR("Status satt til: "));
	if (sm[1].status==0)
	{
		plen=fill_tcp_data_p(buf,plen,PSTR("<font color=red> "));
		plen=fill_tcp_data_p(buf,plen,PSTR("Off"));
	}
	else if (sm[1].status==1)
	{
		plen=fill_tcp_data_p(buf,plen,PSTR("<font color=green> "));
		plen=fill_tcp_data_p(buf,plen,PSTR("On"));
	}
	plen=fill_tcp_data_p(buf,plen,PSTR("</font>"));
	
	plen=fill_tcp_data_p(buf,plen,PSTR("<br>"));
	plen=fill_tcp_data_p(buf,plen,PSTR("Status n&aring;:  "));
	if (ethPacket[pFieldsModules+pStatus]==0)
	{
		plen=fill_tcp_data_p(buf,plen,PSTR("<font color=red> "));
		plen=fill_tcp_data_p(buf,plen,PSTR("Off"));
	}
	else if (ethPacket[pFieldsModules+pStatus]==1)
	{
		plen=fill_tcp_data_p(buf,plen,PSTR("<font color=green> "));
		plen=fill_tcp_data_p(buf,plen,PSTR("On"));
	}
	else if (ethPacket[pFieldsModules+pStatus]==2)
	{
		plen=fill_tcp_data_p(buf,plen,PSTR("<font color=red> "));
		plen=fill_tcp_data_p(buf,plen,PSTR("NC"));
	}
	plen=fill_tcp_data_p(buf,plen,PSTR("</font><br><br>"));
	
	// Change status
	plen=fill_tcp_data_p(buf,plen,PSTR("<fieldset><legend><h4>Undermodul</h4></legend><form action=\"/stat2\" method=get>"));
	plen=fill_tcp_data_p(buf,plen,PSTR("<br><input type=\"radio\" name=\"onoff2\" value=1 "));
	if (sm[1].status==1)
		plen=fill_tcp_data_p(buf,plen,PSTR("checked "));
	plen=fill_tcp_data_p(buf,plen,PSTR(">Sl&aring;tt p&aring;<br>"));
	plen=fill_tcp_data_p(buf,plen,PSTR("<input type=\"radio\" name=\"onoff2\" value=0 "));
	if (sm[1].status==0)
		plen=fill_tcp_data_p(buf,plen,PSTR("checked "));
	plen=fill_tcp_data_p(buf,plen,PSTR(">Sl&aring;tt av<br>"));
	plen=fill_tcp_data_p(buf,plen,PSTR("Passord:</td><td><input type=password size=8 name=pw><br>"));
	plen=fill_tcp_data_p(buf,plen,PSTR("<input type=submit value=\"OK\"></form><br></fieldset>"));
	
	// Set temperatur
	plen=fill_tcp_data_p(buf,plen,PSTR("<br><fieldset><legend><h4>Temp</h4></legend>"));
	plen=fill_tcp_data_p(buf,plen,PSTR("<form action=/tmpc2 method=get>"));
	plen=fill_tcp_data_p(buf,plen,PSTR("<br>Ny temp: <input type=text size=1 name=ntemp2 value="));
	plen=fill_tcp_data_p(buf,plen,PSTR("><br>"));
	plen=fill_tcp_data_p(buf,plen,PSTR("Passord:<input type=password size=8 name=pw>"));
	plen=fill_tcp_data_p(buf,plen,PSTR("<br><input type=submit value=\"OK\"><br>"));
	plen=fill_tcp_data_p(buf,plen,PSTR("</form><br></fieldset>"));
	
	// end
	plen=fill_tcp_data_p(buf,plen,PSTR("</div></body></html>"));
	
	return(plen);
}
Exemplo n.º 20
0
/*
 * Main entry point
 */
int main(void) {

    //=====init green led
    LEDInit();
    LEDSet(1);

    //=====setup eth interface
    uint16_t plen = 0,  dat_p = 0;
    //initialize enc28j60
    enc28j60Init(mymac);



    _delay_ms(100);

    // Magjack leds configuration, see enc28j60 datasheet, page 11 
    // LEDB=yellow LEDA=green
    // 0x476 is PHLCON LEDA=links status, LEDB=receive/transmit
    // enc28j60PhyWrite(PHLCON,0b0000 0100 0111 01 10);
    enc28j60PhyWrite(PHLCON,0x476);


    _delay_ms(100);

    //init the ethernet/ip layer:
    init_udp_or_www_server(mymac,myip);
    www_server_port(MYWWWPORT);
    register_ping_rec_callback(PingCallback);


    while(1){

        // handle ping and wait for a tcp packet:
        dat_p = packetloop_arp_icmp_tcp(buf, enc28j60PacketReceive(BUFFER_SIZE, buf));

        // dat_p will be unequal to zero if there is a valid http get
        if(dat_p==0){
            // do nothing
            continue;
        }
        // tcp port 80 begin
        if (strncmp("GET ",(char *)&(buf[dat_p]),4)!=0){
            dat_p = fill_tcp_data_p(buf, 0, PSTR("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\nPragma: no-cache\r\n\r\n"));
            dat_p = fill_tcp_data_p(buf, dat_p, PSTR("<h1>200 OK</h1>"));
            goto SENDTCP;
        }
        if (strncmp("/ ",(char *) & (buf[ dat_p + 4] ), 2) == 0 ){
            nAccessCount++;
            dat_p = fill_tcp_data_p(buf, 0, PSTR("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\nPragma: no-cache\r\n\r\n"));
            // webcontent
            char szWebText[130] = {0};
            sprintf(szWebText,
                    "<b>ATmega8 Webserver / ENC28J60</b><br><br>Server stats:<br>Acc:%d Png:%d<br><br>(C) Radu Motisan 2012, www.pocketmagic.net<br/>Tomasz Jokiel",
                    nAccessCount, nPingCount);
            dat_p = fill_tcp_data(buf, dat_p, szWebText);
            //
            goto SENDTCP;
        }
        // all other URLs:
        dat_p = fill_tcp_data_p(buf, 0, PSTR("HTTP/1.0 401 Unauthorized\r\nContent-Type: text/html\r\n\r\n<h1>401 Unauthorized</h1>"));
        SENDTCP:
        www_server_reply(buf, dat_p); // send web page data


    }

    return (0);
} 
Exemplo n.º 21
0
/*
 * 函数名:Web_Server
 * 描述  :在浏览器上创建一个web服务器,通过web里面的命令来控制开发板上的LED的亮灭。
 * 输入  :无
 * 输出  :无
 * 返回  :-0 运行成功
 * 应用  :1 在PC机的DOS界面输入: ping 192.168.1.15 (看能否ping通)
 *         2 在IE浏览器中输入:http://192.168.1.15/123456 则会出现一个网页,通过网页
 *           中的命令可以控制开发板中的LED的亮灭
 */
int Web_Server(void)
{   
	unsigned int plen, i1 = 0;
	unsigned int dat_p;
//	unsigned char i = 0;
	unsigned char cmd, *buf1;
	unsigned int payloadlen = 0;
  
  /* 初始化 enc28j60 的MAC地址(物理地址),这个函数必须要调用一次 */
  enc28j60Init(mymac);

	/* PHY LED 配置,LED用来指示通信的状态 */	
  enc28j60PhyWrite(PHLCON,0x476);	
	
	/* 将enc28j60第三引脚的时钟输出改为:from 6.25MHz to 12.5MHz(本例程该引脚NC,没用到) */	
  //enc28j60clkout(2);    
  
	/* 初始化以太网 IP 层 */
	init_ip_arp_udp_tcp(mymac,myip,mywwwport);
	printf("服务器初始化成功!\n");
  while(1)
  {   
			// get the next new packet:			
      plen = enc28j60PacketReceive(BUFFER_SIZE, buf);      
      
      // plen will ne unequal to zero if there is a valid packet (without crc error)			
      if(plen==0)
      {
          continue;
      }

      // arp is broadcast if unknown but a host may also
      // verify the mac address by sending it to 
      // a unicast address.		     
      if(eth_type_is_arp_and_my_ip(buf,plen))
      {
          make_arp_answer_from_request(buf);          
          continue;
      }
      
      // check if ip packets are for us:			
      if(eth_type_is_ip_and_my_ip(buf,plen)==0) 
      {
          continue;
      }      
      
      if(buf[IP_PROTO_P]==IP_PROTO_ICMP_V && buf[ICMP_TYPE_P]==ICMP_TYPE_ECHOREQUEST_V)
      {
          // a ping packet, let's send pong  DOS 下的 ping 命令包		 
          make_echo_reply_from_request(buf, plen);          
          continue;
      }

/*-----------------tcp port www start, compare only the lower byte-----------------------------------*/
      if (buf[IP_PROTO_P]==IP_PROTO_TCP_V&&buf[TCP_DST_PORT_H_P]==0&&buf[TCP_DST_PORT_L_P]==mywwwport)
      {
          if (buf[TCP_FLAGS_P] & TCP_FLAGS_SYN_V)
          {
              make_tcp_synack_from_syn(buf);
              // make_tcp_synack_from_syn does already send the syn,ack
              continue;
          }
          if (buf[TCP_FLAGS_P] & TCP_FLAGS_ACK_V)
          {
              init_len_info(buf); // init some data structures
              // we can possibly have no data, just ack:
              dat_p=get_tcp_data_pointer();
              if (dat_p==0)
              {
                  if (buf[TCP_FLAGS_P] & TCP_FLAGS_FIN_V)
                  {
                      // finack, answer with ack
                      make_tcp_ack_from_any(buf);
                  }
                  // just an ack with no data, wait for next packet
                  continue;
              }
              if (strncmp("GET ",(char *)&(buf[dat_p]),4)!=0)
              {
                  // head, post and other methods:
                  //
                  // for possible status codes see:
                  // http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
                  plen=fill_tcp_data_p(buf,0,PSTR("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n<h1>200 OK</h1>"));
                  goto SENDTCP;
              }
              if (strncmp("/ ",(char *)&(buf[dat_p+4]),2)==0)
              {
                  plen=fill_tcp_data_p(buf,0,PSTR("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n"));
                  plen=fill_tcp_data_p(buf,plen,PSTR("<p>Usage: "));
                  plen=fill_tcp_data(buf,plen,baseurl);
                  plen=fill_tcp_data_p(buf,plen,PSTR("password</p>"));
                  goto SENDTCP;
              }
              cmd=analyse_get_url((char *)&(buf[dat_p+5]));
              // for possible status codes see:
              // http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
              if (cmd==1)
              {
                  plen=fill_tcp_data_p(buf,0,PSTR("HTTP/1.0 401 Unauthorized\r\nContent-Type: text/html\r\n\r\n<h1>401 Unauthorized</h1>"));
                  goto SENDTCP;
              }
 //             if (cmd==1)	           // 用户程序
  //            {			
//									LED1(ON);
//                  i=1;							 // 命令 = 1
  //            }
//              if (cmd==0)						 // 用户程序
  //            {									
//									LED1(OFF);
    //              i=0;							 // 命令 = 0
    //          }
              // if (cmd==-2) or any other value
              // just display the status:
              plen=print_webpage(buf,1);
              
              SENDTCP:
              make_tcp_ack_from_any(buf);       // send ack for http get
              make_tcp_ack_with_data(buf,plen); // send data
              continue;
          }
      }
/*-------------------------------------- tcp port www end ---------------------------------------*/

/*--------------------- udp start, we listen on udp port 1200=0x4B0 -----------------------------*/
      if (buf[IP_PROTO_P]==IP_PROTO_UDP_V&&buf[UDP_DST_PORT_H_P]==4&&buf[UDP_DST_PORT_L_P]==0xb0)
      {
          payloadlen=	  buf[UDP_LEN_H_P];
          payloadlen=payloadlen<<8;
          payloadlen=(payloadlen+buf[UDP_LEN_L_P])-UDP_HEADER_LEN;
          //payloadlen=buf[UDP_LEN_L_P]-UDP_HEADER_LEN;
          
          ANSWER:
          //while(1){
          for(i1=0; i1<payloadlen; i1++) buf1[i1]=buf[UDP_DATA_P+i1];
          
          //make_udp_reply_from_request(buf,str,strlen(str),myudpport);
          make_udp_reply_from_request(buf,buf1,payloadlen,myudpport);          
          //}
      }
/*----------------------------------------udp end -----------------------------------------------*/
  }
          return (0);
}
Exemplo n.º 22
0
int simple_server(void)
	{      
    unsigned int plen;
    unsigned int dat_p;
    unsigned char i=0;
    unsigned char cmd_pos=0;
    unsigned char cmd;
    unsigned char payloadlen=0;
    char str[30];
    char cmdval;

        
//	Del_1ms(100);
	/*initialize enc28j60*/
	enc28j60Init(mymac);
	init_ip_arp_udp_tcp(mymac,myip,mywwwport);
    //ָʾµÆ״̬:0x476 is PHLCON LEDA(ÂÌ)=links status, LEDB(ºì)=receive/transmit
    enc28j60PhyWrite(PHLCON,0x7a4);	
	enc28j60clkout(2); // change clkout from 6.25MHz to 12.5MHz
//	Del_1ms(20);

	//init the ethernet/ip layer:
    while(1)
    	{
//		OSTimeDlyHMSM(0, 0, 0, 50);
        // get the next new packet:
        plen = enc28j60PacketReceive(BUFFER_SIZE, buf);
        //USART_DMASendData(USART1,buf,plen);

        /*plen will ne unequal to zero if there is a valid packet (without crc error) */
        if(plen==0)
        	{
            continue;
        	}
        // arp is broadcast if unknown but a host may also
        // verify the mac address by sending it to 
        // a unicast address.
        if(eth_type_is_arp_and_my_ip(buf,plen))
        	{
			make_arp_answer_from_request(buf);
			//USART_DMASendText(USART1,"make_arp_answer_from_request\n");
            continue;
        	}

        // check if ip packets are for us:
        if(eth_type_is_ip_and_my_ip(buf,plen)==0)
        	{
            continue;
        	}

        
        if(buf[IP_PROTO_P]==IP_PROTO_ICMP_V && buf[ICMP_TYPE_P]==ICMP_TYPE_ECHOREQUEST_V)
        	{
            // a ping packet, let's send pong	
			make_echo_reply_from_request(buf, plen);
			//USART_DMASendText(USART1,"make_echo_reply_from_request\n");
			continue;
        	}
               // tcp port www start, compare only the lower byte
		if (buf[IP_PROTO_P]==IP_PROTO_TCP_V&&buf[TCP_DST_PORT_H_P]==0&&buf[TCP_DST_PORT_L_P]==mywwwport)
			{
            if (buf[TCP_FLAGS_P] & TCP_FLAGS_SYN_V)
				{
                make_tcp_synack_from_syn(buf);
                // make_tcp_synack_from_syn does already send the syn,ack
                continue;
            	}
	        if (buf[TCP_FLAGS_P] & TCP_FLAGS_ACK_V)
				{
	            init_len_info(buf); // init some data structures
	            // we can possibly have no data, just ack:
	            dat_p=get_tcp_data_pointer();
	            if (dat_p==0)
					{
	                if (buf[TCP_FLAGS_P] & TCP_FLAGS_FIN_V)
						{
	                    // finack, answer with ack
	                    make_tcp_ack_from_any(buf);
	                	}
	                // just an ack with no data, wait for next packet
	                continue;
	                }
				if (strncmp("GET ",(char *)&(buf[dat_p]),4)!=0)
					{
			        // head, post and other methods:
			        //
			        // for possible status codes see:
			        // http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
			        plen=fill_tcp_data_p(buf,0,PSTR("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n<h1>200 OK</h1>"));
			        goto SENDTCP;
					}
				if (strncmp("/ ",(char *)&(buf[dat_p+4]),2)==0)
					{
			        plen=fill_tcp_data_p(buf,0,PSTR("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n"));
			        plen=fill_tcp_data_p(buf,plen,PSTR("<p>Usage: "));
			        plen=fill_tcp_data(buf,plen,baseurl);
			        plen=fill_tcp_data_p(buf,plen,PSTR("password</p>"));
			        goto SENDTCP;
					}
				cmd=analyse_get_url((char *)&(buf[dat_p+5]));
				// for possible status codes see:
				// http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
				if (cmd==-1)
					{
			        plen=fill_tcp_data_p(buf,0,PSTR("HTTP/1.0 401 Unauthorized\r\nContent-Type: text/html\r\n\r\n<h1>401 Unauthorized</h1>"));
			        goto SENDTCP;
					}
				if (cmd==1)
					{
			        //PORTD|= (1<<PD7);// transistor on
					//IOCLR |= (1<<26);
//                    LED1ON();
					i=1;
					}
				if (cmd==0)
					{
			        //PORTD &= ~(1<<PD7);// transistor off
					//IOSET |= (1<<26);
//                    LED1OFF();
					i=0;
					}
				// if (cmd==-2) or any other value
				// just display the status:
				plen=print_webpage(buf,(i));
				
				SENDTCP:
				make_tcp_ack_from_any(buf); // send ack for http get
				make_tcp_ack_with_data(buf,plen); // send data
				continue;
				}
			}
	// tcp port www end
	//
	// udp start, we listen on udp port 1200=0x4B0
		if (buf[IP_PROTO_P]==IP_PROTO_UDP_V&&buf[UDP_DST_PORT_H_P]==4&&buf[UDP_DST_PORT_L_P]==0xb0)
			{
			payloadlen=buf[UDP_LEN_L_P]-UDP_HEADER_LEN;
			// you must sent a string starting with v
			// e.g udpcom version 10.0.0.24
			if (verify_password((char *)&(buf[UDP_DATA_P])))
				{
				// find the first comma which indicates 
				// the start of a command:
				cmd_pos=0;
				while(cmd_pos<payloadlen)
					{
					cmd_pos++;
					if (buf[UDP_DATA_P+cmd_pos]==',')
						{
					    cmd_pos++; // put on start of cmd
					    break;
						}
					}
				// a command is one char and a value. At
				// least 3 characters long. It has an '=' on
				// position 2:
				if (cmd_pos<2 || cmd_pos>payloadlen-3 || buf[UDP_DATA_P+cmd_pos+1]!='=')
					{
					strcpy(str,"e=no_cmd");
					goto ANSWER;
					}
				// supported commands are
				// t=1 t=0 t=?
				if (buf[UDP_DATA_P+cmd_pos]=='t')
					{
					cmdval=buf[UDP_DATA_P+cmd_pos+2];
					if(cmdval=='1')
							{
						    //PORTD|= (1<<PD7);// transistor on
							//IOCLR |= (1<<26);
                            //LED1ON();
						    strcpy(str,"t=1");
						    goto ANSWER;
							}
						else if(cmdval=='0')
							{
						    //PORTD &= ~(1<<PD7);// transistor off
							//IOSET |= (1<<26);
                            //LED1OFF();
						    strcpy(str,"t=0");
						    goto ANSWER;
							}
						else if(cmdval=='?')
							{
	/*
						    if (IOPIN & (1<<26))
								{
					            strcpy(str,"t=1");
					            goto ANSWER;
						    	}
	*/
						    strcpy(str,"t=0");
						    goto ANSWER;
							}
					}
				strcpy(str,"e=no_such_cmd");
				goto ANSWER;
				}
			strcpy(str,"e=invalid_pw");
			ANSWER:
			make_udp_reply_from_request(buf,str,strlen(str),myudpport);
			
			}
		}
//        return (0);
	}
Exemplo n.º 23
0
int main(void){
	
	uint16_t plen;
	uint16_t dat_p;
	uint8_t cmd;
	
	// set the clock speed to "no pre-scaler" (8MHz with internal osc or
	// full external speed)
	// set the clock prescaler. First write CLKPCE to enable setting of clock the
	// next four instructions.
	CLKPR=(1<<CLKPCE); // change enable
	CLKPR=0; // "no pre-scaler"
	uartInit();
	uartSetBaudRate(9600);
	
	_delay_loop_1(50); // 12ms
	/* enable PD2/INT0, as input */
	DDRD&= ~(1<<DDD2);
	
	
	
	// test button
	cbi(DDRD,PIND6);
	sbi(PORTD,PIND6); // internal pullup resistor on
	_delay_loop_1(50); // 12ms
	// read eeprom values unless, the PD6 pin is connected to GND during bootup
	// PD6 is used to reset to factory default. Note that factory default is
	// not stored back to eeprom.
	if (eeprom_read_byte((uint8_t *)0x0) == 19 && ! bit_is_clear(PIND,PIND6)){
		// ok magic number matches accept values
		eeprom_read_block((uint8_t *)myip,(void *)1,sizeof(myip));
		eeprom_read_block((uint8_t *)monitoredhost,(void *)6,sizeof(monitoredhost));
		pinginterval=eeprom_read_byte((uint8_t *)11);
		sendping=eeprom_read_byte((uint8_t *)12);
		eeprom_read_block((char *)password,(void *)13,sizeof(password));
		password[7]='\0'; // make sure it is terminated, should not be necessary
	}
	
	/*initialize enc28j60*/
	enc28j60Init(mymac);
	enc28j60clkout(2); // change clkout from 6.25MHz to 12.5MHz
	_delay_loop_1(50); // 12ms
	// LED
	/* enable PB1, LED as output */
	//DDRB|= (1<<DDB1);
	/* set output to Vcc, LED off */
	//LEDOFF;
	
	// the transistor on PD7
	DDRD|= (1<<DDD7);
	PORTD &= ~(1<<PIND7);// transistor off
	
	/* Magjack leds configuration, see enc28j60 datasheet, page 11 */
	// LEDB=yellow LEDA=green
	//
	// 0x476 is PHLCON LEDA=links status, LEDB=receive/transmit
	// enc28j60PhyWrite(PHLCON,0b0000 0100 0111 01 10);
	enc28j60PhyWrite(PHLCON,0x476);
	_delay_loop_1(50); // 12ms
	
	
	//init the ethernet/ip layer:
	init_ip_arp_udp_tcp(mymac,myip,MYWWWPORT);
	timer_init();
	_delay_ms(1000);
	uartFlushReceiveBuffer();
	sei(); // interrupt enable
	
	while(1){
		//uartSendByte('a');
		
		//checkForEthPacket(ethPacket);
		stop_timer=2;
		if (checkForEthPacket(ethPacket))
		{
			sendEthPacket(time, sm);
			time.hr = 99;
		}
		stop_timer=0;
		// 			wait_data++;
		// 			if (wait_data>40)
		// 				wait_data=0;
		//_delay_ms(500);
		// spontanious messages must not interfer with
		// web pages
		if (pagelock==0 && enc28j60hasRxPkt()==0){
			if (sendping &&  havemac==0){
				client_arp_whohas(buf,monitoredhost);
				havemac=2;
			}
			if (sendping && havemac==1 && pingnow){
				pingnow=0;
				client_icmp_request(buf,monitoredhost,PINGPATTERN);
				pingtimer++; // otheweise we would call this function again
				hoststatus++;
				if (hoststatus==0xff){
					hoststatus=1; // wrap to 1
				}
			}
		}
		// get the next new packet:
		plen = enc28j60PacketReceive(BUFFER_SIZE, buf);
		
		/*plen will be unequal to zero if there is a valid 
		* packet (without crc error) */
		if(plen==0){
			continue;
		}
		
		// arp is broadcast if unknown but a host may also
		// verify the mac address by sending it to
		// a unicast address.
		if(eth_type_is_arp_and_my_ip(buf,plen)){
			if (eth_type_is_arp_req(buf)){
				make_arp_answer_from_request(buf);
			}
			if (eth_type_is_arp_reply(buf)){
				if (client_store_gw_mac(buf,monitoredhost)){
					havemac=1;
				}
			}
			continue;
		}
		
		// check if ip packets are for us:
		if(eth_type_is_ip_and_my_ip(buf,plen)==0){
			continue;
		}
		
		if(buf[IP_PROTO_P]==IP_PROTO_ICMP_V && buf[ICMP_TYPE_P]==ICMP_TYPE_ECHOREPLY_V){
			if (buf[ICMP_DATA_P]== PINGPATTERN){
				if (check_ip_message_is_from(buf,monitoredhost)){
					// ping reply is from monitored host and ping was from us
					hoststatus=0;
					hostbackafterreboot=1;
				}
			}
		}
		if(buf[IP_PROTO_P]==IP_PROTO_ICMP_V && buf[ICMP_TYPE_P]==ICMP_TYPE_ECHOREQUEST_V){
			if (check_ip_message_is_from(buf,monitoredhost)){
				// ping is from monitored host
				hoststatus=0;
				hostbackafterreboot=1;
			}
			// a ping packet, let's send pong
			make_echo_reply_from_request(buf,plen);
			continue;
		}
		// tcp port www start, compare only the lower byte
		if (buf[IP_PROTO_P]==IP_PROTO_TCP_V&&buf[TCP_DST_PORT_H_P]==0&&buf[TCP_DST_PORT_L_P]==MYWWWPORT){
			if (buf[TCP_FLAGS_P] & TCP_FLAGS_SYN_V){
				make_tcp_synack_from_syn(buf);
				// make_tcp_synack_from_syn does already send the syn,ack
				continue;
			}
			if (buf[TCP_FLAGS_P] & TCP_FLAGS_ACK_V){
				init_len_info(buf); // init some data structures
				// we can possibly have no data, just ack:
				dat_p=get_tcp_data_pointer();
				if (dat_p==0){
					if (buf[TCP_FLAGS_P] & TCP_FLAGS_FIN_V){
						// finack, answer with ack
						make_tcp_ack_from_any(buf);
					}
					// just an ack with no data, wait for next packet
					continue;
				}
				if (strncmp("GET ",(char *)&(buf[dat_p]),4)!=0){
					// head, post and other methods:
					//
					// for possible status codes see:
					// http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
					plen=fill_tcp_data_p(buf,0,PSTR("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n<h1>200 OK</h1>"));
					goto SENDTCP;
				}
				if (strncmp("/ ",(char *)&(buf[dat_p+4]),2)==0){
					plen=print_webpage(buf);
					goto SENDTCP;
				}
				cmd=analyse_get_url((char *)&(buf[dat_p+5]));
				pagelock=1; // stop automatic actions until webpage is displayed
				//
				// error, default, will get overwritte in case 
				// something else is selected:
				plen=fill_tcp_data_p(buf,0,PSTR("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n<h1>Error</h1>"));
				plen=fill_tcp_data(buf,plen,errmsg);
				plen=fill_tcp_data_p(buf,plen,PSTR("<br><br><a href=/>-&gt;continue</a>\n"));
				// for possible status codes see:
				// http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
				if (cmd==1){
					resethost();
					plen=print_webpage_confirm(buf);
				}
				if (cmd==2){
					store_in_eeprom();
					plen=print_webpage_confirm(buf);
				}
				if (cmd==7){
					store_in_eeprom();
					plen=print_webpage_confirm(buf);
					reinitmac=1;
				}
				// start and stop of wd, this is not store in eeprom
				if (cmd==5){
					pingtimer=1; // wd on 
					plen=print_webpage_confirm(buf);
				}
				if (cmd==4){
					pingtimer=0; // wd off 
					plen=print_webpage_confirm(buf);
				}
				if (cmd==3){
					plen=print_webpage_now(buf);
				}
				if (cmd==6){
					plen=print_webpage_config(buf);
				}
				// testing the temp OK / NOK
				if (cmd==20){
					sm[0].temp= atoi(strbuf);
					plen=print_webpage_confirm(buf);
				}
				if (cmd==21){
					sm[1].temp= atoi(strbuf);
					plen=print_webpage_confirm(buf);
				}
				
				// on / off - slave-modules
				// ON slave-module-1
				if (cmd==34){
					sm[0].status = atoi(strbuf);
					plen=print_webpage_confirmrm1(buf);
				}
				// OFF slave-module-1
				if (cmd==31){
					sm[0].status = atoi(strbuf);
					plen=print_webpage_confirmrm1(buf);
				}
				// ON slave-module-2
				if (cmd==32){
					sm[1].status = atoi(strbuf);
					plen=print_webpage_confirmrm2(buf);
				}
				// OFF slave-module-2
				if (cmd==33){
					sm[1].status = atoi(strbuf);
					plen=print_webpage_confirmrm2(buf);
				}
				
				if (cmd==35){
					plen=print_webpage_confirmclk(buf);
				}
				if (cmd==36){
					plen=print_webpage_confirmclk(buf);
				}
				
				// Room-1
				if (cmd==10){
					plen=print_webpage_room1(buf);
				}
				// ROom-2
				if (cmd==11){
					plen=print_webpage_room2(buf);
				}
				// Clock & date
				if (cmd==12){
					plen=print_webpage_clk(buf);
				}
				
				//
				SENDTCP:
				make_tcp_ack_from_any(buf); // send ack for http get
				make_tcp_ack_with_data(buf,plen); // send data
				continue;
			}
			
		}
		// tcp port www end
		//
		// udp not implemented
	}
	return (0);
}