예제 #1
0
void ICACHE_FLASH_ATTR headers(struct espconn * client, const char *filename)
{
 char *buf =(char *)os_zalloc(sizeof(char)*128);
 (void)filename;  /* could use filename to determine file type */

 os_strcpy(buf, "HTTP/1.0 200 OK\r\n");
 TCP_Send(client, buf, strlen(buf));
 os_strcpy(buf, "Connection: close\r\n");
 TCP_Send(client, buf, strlen(buf));
 os_strcpy(buf, SERVER_STRING);
 TCP_Send(client, buf, strlen(buf));
 os_sprintf(buf, "Content-Type: text/html\r\n");
 TCP_Send(client, buf, strlen(buf));
 os_strcpy(buf, "\r\n");
 TCP_Send(client, buf, strlen(buf));
 os_delay_us(1000);
 os_free(buf);
}
예제 #2
0
int16_t std_m_message_send(void *Message,int sockfd,uint16_t Length)
{
    uint16_t Totle,i;
    if(Length < 8 || Message == NULL)    return -1;
    if(Length <= STD_PACKAGE_SIZE){
        if(send(sockfd,Message,Length,0) < 0)
        return -1;
    }else{
        Totle = Length / STD_PACKAGE_SIZE;
        if(Length % STD_PACKAGE_SIZE != 0)
            Totle ++;
        for(i=1;i<=Totle;i++)
            TCP_Send(sockfd,(char *)Message+(i-1)*STD_PACKAGE_SIZE,STD_PACKAGE_SIZE,0);
    }
    return LINKC_SUCCESS;
}
예제 #3
0
void ICACHE_FLASH_ATTR process_form(char *pdata , unsigned short len,void * conn)
{
	int Locations[10];
	    int length[9];
	    int address[0];
	    char Post_Error=0;

	    char Local_Port[5]="";
	    char Remote_Port[5]="";
	    int LP,RP;
	    int Header_type;
	    int Mode;

	    int Buffer_Size;
		TCP_recieved_flag=1;

		if(Search_Word(pdata,10,"POST")!=-1){

				Locations[0]=Search_Word(pdata,len,"RID");

				Locations[1]=Search_Word(pdata,len,"&RPWD");

				Locations[2]=Search_Word(pdata,len,"&AID");

				Locations[3]=Search_Word(pdata,len,"&APWD");

				Locations[4]=Search_Word(pdata,len,"&STATION");

				Locations[5]=Search_Word(pdata,len,"&UDPLP");

				Locations[6]=Search_Word(pdata,len,"&UDPRP");

				Locations[7]=Search_Word(pdata,len,"&TERMINATOR");

				Locations[8]=Search_Word(pdata,len,"&PCTSIZE");

	            length[0]=Locations[1]-Locations[0]-4;
	            length[1]=Locations[2]-Locations[1]-6;
	            length[2]=Locations[3]-Locations[2]-5;
	            length[3]=Locations[4]-Locations[3]-6;
	            length[4]=Locations[5]-Locations[4]-9;
	            length[5]=Locations[6]-Locations[5]-7;
	            length[6]=Locations[7]-Locations[6]-7;
	            length[7]=Locations[8]-Locations[7]-12;

	            address[0]=Locations[0]+4;
	            address[1]=Locations[1]+6;
	            address[2]=Locations[2]+5;
				address[3]=Locations[3]+6;
				address[4]=Locations[4]+9;
				address[5]=Locations[5]+7;
				address[6]=Locations[6]+7;
				address[7]=Locations[7]+12;
				address[8]=Locations[8]+9;

				if(length[0]>0 && address[0]!=-1){
				os_memcpy(&info.Router_ssid,&pdata[address[0]],length[0]);
				}
				if(length[1]>0 && address[1]!=-1){
				os_memcpy(&info.Router_password,&pdata[address[1]],length[1]);
				}
				if(length[2]>0 && address[2]!=-1){
				os_memcpy(&info.Soft_AP_ssid,&pdata[address[2]],length[2]);
				}
				if(length[3]>0 && address[3]!=-1){
				os_memcpy(&info.Soft_AP_password,&pdata[address[3]],length[3]);
				}
				if(length[6]>0 && address[6]!=-1){
				os_memcpy(&Remote_Port,&pdata[address[6]],length[6]);
	            RP=Ptoi(Remote_Port);
            	info.UDP_Client_Port=(uint32)RP;
				}

				if(length[5]>0 && address[5]!=-1){
				os_memcpy(&Local_Port,&pdata[address[5]],length[5]);
	            LP=Ptoi(Local_Port);
                info.UDP_Server_Port=(uint32)LP;
				}

				if(address[4]!=-1)
				info.Mode=(uint32)pdata[address[4]];

				if(address[7]!=-1)
				info.Terminator=(uint32)pdata[address[7]];

                os_memcpy(&conv.data_struct,&info,sizeof(info));
	            spi_flash_erase_sector(0x3D);
	            spi_flash_write(0x3D000,conv.data,sizeof(info));

	            TCP_Send((struct espconn *)conn,"<h1>OK!!! ,Changes Saved<h1>",sizeof("<h1>OK!!! ,Changes Saved<h1>"));

	            return ;

	 }
		headers((struct espconn *) conn ,"http");
	    TCP_Send((struct espconn *)conn,Page,os_strlen(Page));
}