Esempio n. 1
0
int main(void)
{
	int fd;
	int len;
	char wBuffer[1];
	char *szSSID = "linksys";
	char *szPassword = "******";
	wBuffer[0] = 1;
	
 	N_Info_t gNetInfo;
	memset(&gNetInfo,'\0',sizeof(N_Info_t));
/*
	if(mkfifo(NET_FIFO,0666) < 0)
	{
		if(errno == EEXIST)
			printf("mk is error!\n");
		else
			exit(-1);
	}
	fd = open(NET_FIFO,O_WRONLY|O_NONBLOCK);
	write(fd,wBuffer,1);
	
	len = strlen(szSSID);
	printf("len:%d\n",len);
	wBuffer[0] = len;
	write(fd,wBuffer,1);
	write(fd,szSSID,len);
	len = strlen(szPassword);
	wBuffer[0] = len;
	write(fd,wBuffer,1);
	write(fd,szPassword,len);
	
	close(fd);
	return;
*/
/*
	while(1)
	{
		sleep(2);
		ReadNetInfo(&gNetInfo);
		gNetInfo.iSearch_Flag= 1;
		SaveNetInfo(&gNetInfo);
		DisplayNetInfo(&gNetInfo);

*/
		ReadNetInfo(&gNetInfo);
		strcpy(gNetInfo.szLink_SSID,"linksys");
		strcpy(gNetInfo.szLink_Password,"AA8465E6A4");
		gNetInfo.iConnect_Format = 2;
		SaveNetInfo(&gNetInfo);
		while(1)
		{
			ReadNetInfo(&gNetInfo);
			if((gNetInfo.iAction_Flag & 0x1) == 1)
			{
				if(gNetInfo.iStatus_Wireless == 1)
				{
					printf("connect is ok!\n");
				}
				else
				{
					printf("connect if fail!\n");
				}
				Clear_Connect_Flag();
			}
			else
			{
				DisplayNetInfo(&gNetInfo);
			}
		
			sleep(2);
			
		}
//	}	

}
Esempio n. 2
0
/*******************************************************************************
* Function Name  : main
* Description    : Main program.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
int main(void)
{  
	uint16 i; 
        RCC_Configuration(); // Configure the system clocks
	NVIC_Configuration(); // NVIC Configuration
	GPIO_Configuration();
	USART1_Init(115200);
	Timer_Configuration();
        
        printf("============================================\r\n");
	printf("   HTTP client for W5200 \r\n");
	printf("============================================\r\n");
       
	WIZ_SPI_Init();	
        Reset_W5200();
        wizInit();
        InitNetInfo();
        DisplayNetInfo();
	              
        // LED3 and LED4 On!
	LED3_onoff(ON);
	LED4_onoff(ON);
     
       
        uint8  url[MAX_URL_SIZE];			//full url
	uint8  url_dn[MAX_URL_SIZE];			//domain name url
	uint8  url_path[MAX_URL_SIZE];		//local path in html server
	char * split;				//string split pointer 
	
	
	uint16 done_http = 0;
	uint16 start_idx = 0 ;
	uint16 end_idx = 0;
	uint16 tmp_start;
	uint16 tmp_end;
	uint8 BR [4]= "<BR>";
	uint8 rBR [4]= "\r\n";
	uint8 TITLE [7]= "<TITLE>";
	uint8 bTITLE [8]= "</TITLE>";
	

	uint16 tmp_idx;
	uint8 no_pr = 0;
	uint8 str[17];
       
	
            while (1)
            {
                          
              sprintf((char*)str,"%.3d.%.3d.%.3d.%.3d ",
				IINCHIP_READ (SIPR0+0), IINCHIP_READ (SIPR0+1), 
				IINCHIP_READ (SIPR0+2), IINCHIP_READ (SIPR0+3));
                            
                           
                            /* Get Http Address  */
                            printf("\r\n Please enter a HTTP Address without 'http://' \n\r"); 
                            printf("http://");
                            memset(url,0,sizeof(url));	
                            //Modified by Gang 2011-10-04
                            zScanf_s(1, url);
                            printf("\r\n Your HTTP address is: %s \r\n",url);		
                            
                            /* Parse URL Path  */
                            split = strchr((char const*)url,'/');			
                            strcpy((char*)url_path,split); 			
                            printf("Domain path: %s \r\n",url_path);
                    
                            /* Parse URL Domain  */
                            split = strtok((char*)url,"/");			
                            strcpy((char*)url_dn,split);				
                            printf("Domain name: %s \r\n",url_dn);
                            
               
                            /* Do DNS Client */
                            memset(httpclient_NetInfo.HTTPs_IP,0,sizeof(httpclient_NetInfo.HTTPs_IP));
                            //Delay_ms(10);
                            done_dns = dns_query(DNS_SOCK, url_dn, httpclient_NetInfo.HTTPs_IP);
                            printf("\r\n HTTPs_IP= %d.%d.%d.%d",httpclient_NetInfo.HTTPs_IP[0],httpclient_NetInfo.HTTPs_IP[1],httpclient_NetInfo.HTTPs_IP[2],httpclient_NetInfo.HTTPs_IP[3]);
                          
                            while(done_dns) {
                            
                            /* Do HTTP Client */
                            done_http = http_client(HTTPC_SOCK, httpclient_NetInfo.HTTPs_IP, url_path, url_dn,data_buf);
                           
                            if(done_http) { // on success, done_dns is not  '0'
                                            
    #define Recieved_DATA
    #ifdef Recieved_DATA
                                            printf("\r\n<< Recieved Data -- START>> \r\n");
                                           
                                            for(i=0; i<done_http; i++){
                                                  
                                                  printf("%c",(uint8)data_buf[i]);
                                              }   
                                            printf("\r\n");
                                            printf("<< Recieved Data -- END>> \r\n");
                                           
    #endif
                                        /* parsed index */
                                            //All other HTML elements are nested between the opening <html> and </html> tags.
                                            start_idx = pased_idx((uint8 *)str_start , sizeof(str_start), done_http );
                                            end_idx   = pased_idx((uint8 *)str_end , sizeof(str_end), done_http );			
    
                                            /* printf get <html> ...</html> */							
                                            for(i=start_idx; i<(end_idx+7); i++){						
                                                    /* remove header */
                                                    data_buf[i-start_idx] = data_buf[i];
                                             }   
                                            printf("\r\n");
                                            
    
                                            /* replace <br> tag to \r\n */
                                            //The br tag is used for specifying a line break.
                                            do{
                                                    tmp_idx = pased_idx((uint8*)BR, sizeof(BR) , end_idx-start_idx) ;
                                                    if(tmp_idx == 0 ) 
                                                            break;
                                                 
                                                    memcpy((uint8 *)data_buf+tmp_idx, (uint8*)rBR, sizeof(rBR)) ;
                                            }while(tmp_idx!=end_idx-start_idx);
    
    #define Parsed_DATA
    #ifdef Parsed_DATA
                                            /* parsed DATA */
                                            printf("\r\n<< Parsed Data -- START >>");
                                            printf("\r\nTITLE : \r\n");
                                            /* parse <TITLE> and </TITLE> tags */
                                            tmp_start = pased_idx((uint8 *)TITLE , sizeof(TITLE),(end_idx-start_idx) ) + sizeof(TITLE);
                                            tmp_end   = pased_idx((uint8 *)bTITLE , sizeof(bTITLE),(end_idx-start_idx) );												
                                            for(i=tmp_start; i<tmp_end; i++){
                                                   
                                                    printf("%c",(uint8)data_buf[i]); // printf title
                                            }   
    
                                            printf("\r\n BODY : \r\n");
                                            /*DO NOT PRINT TAG COMMAND: between '<' with '>' */
                                            for(i=tmp_end; i<(end_idx-start_idx); i++){
                                                    //Tag command - ex.)<PRE>
                                                    //'<' is a start point of tag command.
                                                    if((uint8)data_buf[i]=='<'){ 
                                                            no_pr = 0;
                                                    }
                                                    //'>' is a end point of Tag command.
                                                    //To avoid in row tags -> ex.) <PRE><H1>						
                                                    if((uint8)data_buf[i]=='>' && (uint8)data_buf[i+1] !='<' ) {
                                                            no_pr = 1;
                                                            i++;
                                                    }					
                                                    if(no_pr){
                                                        Delay_ms(1);    
                                                        printf("%c",(uint8)data_buf[i]);
                                                    }
                                            }   
                                            printf("\r\n<< Parsed Data -- END >>\r\n");
    #endif
                                            /* Init. parameter */
                                            start_idx= 0;
                                            end_idx= 0;				
                                    done_dns = 0;  
                                    break;
    
                            }
                           //done_http
                            //done_dns=0;
                    }//while : done_dns == 1		
            }
}