//---------------------------------------------------------------------------- //HTTP Request an einen Webserver stelle void http_request (void) { unsigned long index = MAX_TCP_ENTRY; if (http_get_state > 1 && http_get_state < 20) http_get_state++; if (http_get_state == 0) { //offnet eine Verbindung zu meinem Webserver HTTPC_DEBUG("ARP Request\n\r"); unsigned int my_http_cp = 2354; add_tcp_app (my_http_cp, (void(*)(unsigned char))test); //ARP Request senden if(arp_request (WEATHER_SERVER_IP)) { for(unsigned long a=0;a<2000000;a++){asm("nop");}; tcp_port_open (WEATHER_SERVER_IP,LBBL_ENDIAN_INT(80),LBBL_ENDIAN_INT(my_http_cp)); unsigned char tmp_counter = 0; while((index >= MAX_ARP_ENTRY) && (tcp_entry[index].app_status != 1)) { index = tcp_entry_search (WEATHER_SERVER_IP,LBBL_ENDIAN_INT(80)); if (tmp_counter++ > 30) { HTTPC_DEBUG("TCP Eintrag nicht gefunden (HTTP_CLIENT)!\r\n"); return; } } HTTPC_DEBUG("TCP Eintrag gefunden (HTTP_CLIENT)!\r\n"); tcp_entry[index].first_ack = 1; http_get_state = 2; } else { http_get_state = 1; } } //if (http_get_state == 10) if (http_get_state > 10 && http_get_state < 20) { HTTPC_DEBUG("\r\n\r\n\r\nDaten Anfordern\r\n"); index = tcp_entry_search (WEATHER_SERVER_IP,LBBL_ENDIAN_INT(80)); memcpy_P(ð_buffer[TCP_DATA_START],WEATHER_GET_STRING,(sizeof(WEATHER_GET_STRING)-1)); tcp_entry[index].status = ACK_FLAG | PSH_FLAG; create_new_tcp_packet((sizeof(WEATHER_GET_STRING)-1),index); } }
//---------------------------------------------------------------------------- //Daten kommen von einem Webserver an!! void test (unsigned char index) { for (int a = TCP_DATA_START_VAR;a < TCP_DATA_END_VAR;a++) { HTTPC_DEBUG("%c",eth_buffer[a]); } tcp_entry[index].time = TCP_TIME_OFF; tcp_entry[index].status = ACK_FLAG; create_new_tcp_packet(0,index); }
void notifications__run(void) { unsigned long index = MAX_TCP_ENTRY; if (http_get_state < 1) { HTTPC_DEBUG("httpc: ARP lookup for notification server\n\r"); unsigned int httpc__source_port = 2354; add_tcp_app(httpc__source_port, (void(*)(unsigned char))httpc_acknowledge); // Send ARP request if (arp_request(NOTIFICATIONS__SERVER_HOST)) { for(unsigned long a = 0;a < 2000000; a++) { asm("nop"); }; tcp_port_open(NOTIFICATIONS__SERVER_HOST, HTONS(NOTIFICATIONS__SERVER_PORT), htons(httpc__source_port)); unsigned char tmp_counter = 0; while ((index >= MAX_ARP_ENTRY) && (tcp_entry[index].app_status != 1)) { index = tcp_entry_search(NOTIFICATIONS__SERVER_HOST, HTONS(NOTIFICATIONS__SERVER_PORT)); if (tmp_counter++ > 30) { HTTPC_DEBUG("httpc: tcp entry not found!\r\n"); return; } } HTTPC_DEBUG("httpc: tcp entry found!\r\n"); tcp_entry[index].first_ack = 1; ++http_get_state; } else { ++http_get_state; } } else if (http_get_state == 20000) { HTTPC_DEBUG("httpc: sending HTTP request\r\n"); index = tcp_entry_search(NOTIFICATIONS__SERVER_HOST, HTONS(NOTIFICATIONS__SERVER_PORT)); memcpy_P(ð_buffer[TCP_DATA_START], PUT_REQUEST, (sizeof(PUT_REQUEST)-1)); tcp_entry[index].status = ACK_FLAG | PSH_FLAG; create_new_tcp_packet((sizeof(PUT_REQUEST)-1), index); http_get_state = 20001; } else if (http_get_state < 20000) http_get_state++; // wait.. ugly }
//---------------------------------------------------------------------------- //HTTP Request an einen Webserver stelle void http_request (void) { unsigned long index = MAX_TCP_ENTRY; if (http_get_state > 1 && http_get_state < 20) http_get_state++; if (http_get_state == 0) { //offnet eine Verbindung zu meinem Webserver HTTPC_DEBUG("ARP Request to HTTP URL\n\r"); unsigned int my_http_cp = 2354; add_tcp_app (my_http_cp, (void(*)(unsigned char))test); //ARP Request senden if(arp_request (WEATHER_SERVER_IP)) { for(unsigned long a=0;a<2000000;a++){asm("nop");}; tcp_port_open (WEATHER_SERVER_IP,HTONS(80),HTONS(my_http_cp)); unsigned char tmp_counter = 0; while((index >= MAX_ARP_ENTRY) && (tcp_entry[index].app_status != 1)) { index = tcp_entry_search (WEATHER_SERVER_IP,HTONS(80)); if (tmp_counter++ > 30) { HTTPC_DEBUG("TCP Eintrag nicht gefunden (HTTP_CLIENT)!\r\n"); return; } } HTTPC_DEBUG("TCP Eintrag gefunden (HTTP_CLIENT)!\r\n"); tcp_entry[index].first_ack = 1; ///tcp_entry[index].dest_port = ; http_get_state = 2; } else { http_get_state = 1; } } //if (http_get_state == 10) if (http_get_state > 10 && http_get_state < 20) { usart_write ("\n\rHTTP GET sent \r\n"); index = tcp_entry_search (WEATHER_SERVER_IP,HTONS(80)); create_tcp_packet ( 0,//unsigned char index, 0,//unsigned char ip_adr[], mymac,//unsigned char mac_adr_my[], myLAN,//unsigned char mac_adr_LAN[], 80, //usigned int src_port, 80,//unsigned int dest_port WEATHER_GET_STRING, sizeof(WEATHER_GET_STRING) ); //memcpy_P(ð_buffer[TCP_DATA_START],WEATHER_GET_STRING,(sizeof(WEATHER_GET_STRING)-1)); tcp_entry[index].status = ACK_FLAG | PSH_FLAG; //create_new_tcp_packet((sizeof(WEATHER_GET_STRING)-1),index); } }