/******************************************************************************* * Function Name : main * Description : Main program. * Input : None * Output : None * Return : None *******************************************************************************/ int main(void) { RCC_Configuration(); // Configure the system clocks GPIO_Configuration(); NVIC_Configuration(); // NVIC Configuration USART1_Init(); Timer_Configuration(); WIZ_SPI_Init(); WIZ_Config(); // network config // LED3 and LED4 On! LED3_onoff(ON); LED4_onoff(ON); // Start Application printf("\r\n\r\n----------------------------------- \r\n"); printf("Twitter and DNS using W5200\r\n"); printf("----------------------------------- "); Main_Menu(); while(1) { } }
uint8_t tcp_socket_init(TCP_CONFIG *config) { static bool startup=false; if(!startup) { GPIO_Configuration(); Reset_W5200(); WIZ_SPI_Init(); Set_network(config->Source_IP, config->Gateway, config->MAC, config->Subnet); startup=true; while (getSn_SR(config->s) != SOCK_CLOSED); } if(socket(config->s,Sn_MR_TCP,config->Source_Port,0x00)== 0) /* reinitialize the socket */ { return 0; //TCP socket failed } while (getSn_SR(config->s) != SOCK_INIT); // Wait for socket to open IINCHIP_WRITE(Sn_CR(config->s), Sn_CR_LISTEN); // Start listening on port specified while (IINCHIP_READ(Sn_CR(config->s))); // Check status while (getSn_SR(config->s) != SOCK_LISTEN); // Wait for listen return 1; }
void main() { RCC_Configuration(); // Configure the system clocks GPIO_Configuration(); //GPIO configuration NVIC_Configuration(); //NVIC Configuration Timer_Configuration(); iic_init(); //ov2640_jpeg_config(JPEG_800x600); ov2640_jpeg_config(JPEG_640x480); //ov2640_jpeg_config(JPEG_320x240); /* 设置COMS参数 */ ov2640_brightness_config(0x40); ov2640_auto_exposure(3);//3 ov2640_contrast_config(0x28, 0x0c); ov2640_black_white_config(0x00); ov2640_color_saturation(0x68, 0x68); ov2640_light_mode_config(OFFICE); o2640_capture_gpio_init(); /* 关闭像素同步中断 */ ov2640_interrupt_disable(); USART1_Init(); //115200@8-n-1 //UART4_Init(38400);//camera printf("MCU initialized.\r\n"); Reset_W5500(); printf("Ethernet initialized over.\r\n"); WIZ_SPI_Init(); set_network(); printf("W5500 is ready!\r\n"); printf("camera init......OK\r\n"); JPEGCnt=0; ov2640_interrupt_enable(); while(1) { do_websocket_server(SOCK_WEBSOCKET); do_http(); } }
/******************************************************************************* * Function Name : main * Description : Main program. * Input : None * Output : None * Return : None *******************************************************************************/ int main(void) { u8 res=0; delay_init(); RCC_Configuration(); // Configure the system clocks NVIC_Configuration(); // NVIC Configuration GPIO_Configuration(); // USART3_Configuration(); USART1_Configuration(); Timer_Configuration(); LED_GPIO_Configuration(); LED1_ON;; Reset_W5500(); WIZ_SPI_Init(); ZC_Init(); WIZ_Config(); // network config & Call Set_network (); Get_ChipInfo(); presentTime = my_time; // For TCP client's connection request delay // Start Application printf("\r\n\r\n------------------------------------------- \r\n"); printf("Loopback using W5500\r\n"); printf("------------------------------------------- "); // AC_ConfigWifi(); do{ res = Dhcp_Task(); }while(res!=0); HF_WakeUp(); while(1) { HF_Cloudfunc(); } }
void ethernetInit() { // uint8 mac[6]=ETHERNET_LOCAL_MAC; // uint8 lip[4]=ETHERNET_SSN_SIP; // uint8 sub[4]=ETHERNET_SSN_SN; // uint8 gw[4]=ETHERNET_SSN_GW; uint8 ip[4]; xprintfMsg("\r\nW5500 EVB initialization over."); Reset_W5500(); WIZ_SPI_Init(); xprintfMsg("\r\nW5500 initialized!"); setSHAR(mac); setSUBR(sub); setGAR(gw); setSIPR(lip); //Init. TX & RX Memory size of w5500 sysinit(txsize, rxsize); setRTR(2000); setRCR(3); getSIPR (ip); xprintfMsg("IP : %d.%d.%d.%d\r\n", ip[0],ip[1],ip[2],ip[3]); getSUBR(ip); xprintfMsg("SN : %d.%d.%d.%d\r\n", ip[0],ip[1],ip[2],ip[3]); getGAR(ip); xprintfMsg("GW : %d.%d.%d.%d\r\n", ip[0],ip[1],ip[2],ip[3]); xprintfMsg("Network is ready.\r\n"); }
/******************************************************************************* * 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 } }