i tried to integrate this into uli's code. when i start the webserver it
does a request to my webserver. I verified this by using wireshark. but
the problem; it isnt working, yet. i do see packet retransmissions. i
searched for a while and found other topics with the same problems.
does someone have this code working or maybe have an other solution to
put data into a remote sql db? i'm looking for a 'real time put'
solution so a bash script getting the data from the atmega is not what
i'm looking for.
Hello,
the problem is at Uli's data recive routine.
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);
}
if your webserver close the connection (FIN) at same time with sending
last data packet - uli's code send only an ACK and not an FIN/ACK
thereby the connection is not close.
To test use the follow code, but i used in my webserver an ASM code
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;
if(tcp_entry[index].status & FIN_FLAG) {
http_get_state=20;
return;
}
tcp_entry[index].status = ACK_FLAG;
create_new_tcp_packet(0,index);
}
Sascha
Hi Sascha,
i tried the code but without any luck.
i captured again with wireshark and i see:
1 - atmega send syn to webserver
2 - webserver send syn/ack back to atmega
3 - and again: webserver send syn/ack back to atmega ??
4 - then i get 6 retrainsmissions from the atmega to the webserver with
http GET requests.
5 - webserver send syn/ack back to atmega
6 - 3 times, atmega send psh and ack with http data (GET)
7 - atmega sends rst, ack to webserver
end.
what to do?
Hello,
I testet some code, see attachement ...
changes outside of http_get, code based on version 1.2.5 from ulli:
>main.c
at startup called httpg_init()
>cmd.c / cmd.h
add command "get" to start http-download
So the statemachine works but implement is not perfect (catch out
errors).
A problem remains - after connection closed most stacks wait sometimes
at new packets with same portnumber. If you within 1-2 mins, running a
new download the connection hang. To avoid this you must change port at
each connection.
Into my server implement this. In example:
> Start download
* get an random portnumber
* add_tcp_app with this portnumber
* running download
* after connection closed kill_tcp_app with selected portnumber
here a link with something information about my server:
Beitrag "Re: Zeigt her Eure Kunstwerke !"
Sascha
Hi Sascha,
Thanks for your code. I'm trying but i get a little confused.
in your main.c you still got:
1
#if GET_WEATHER
2
http_request ();
3
#endif
but in your cmd.c you are doing a request to command_httpG which
requests run_http_request(); which requests
1
void run_http_request (void)
2
{
3
if (http_get_state==-1)
4
{
5
http_get_state=0;
6
} else {
7
HTTPC_DEBUG("ERROR - HTTP Request BUSY\n\r");
8
}
9
}
without any call to other functions?
when only calling http_request(); in the main.c doesnt work,
http_get_state is at start -1 ?
do i need to add http_request in the run_http_request function ?
and replace http_request(); in main.c to run_http_request(); ?
wireshark:
atmega > webserver : SYN
webserver > atmega RST, ACK
i think handshake is going wrong?
btw, i've got 2 subnets in my lan, local lan and wlan
local lan = atmega 192.168.x.x, webserver = wlan 192.168.y.x
Sj Sj wrote:> Hi Sascha,>> Thanks for your code. I'm trying but i get a little confused.>> in your main.c you still got:>>
1
> #if GET_WEATHER
2
> http_request ();
3
> #endif
4
>
this code i dont changed, its runs http_get statemachine simultaneously
into main loop
> but in your cmd.c you are doing a request to command_httpG which> requests run_http_request(); which requests>>
1
> void run_http_request (void)
2
> {
3
> if (http_get_state==-1)
4
> {
5
> http_get_state=0;
6
> } else {
7
> HTTPC_DEBUG("ERROR - HTTP Request BUSY\n\r");
8
> }
9
> }
10
>
>> without any call to other functions?
yes it's ok, the http_request() check var http_get_state at every
calling from main loop. At reset or if request complete the state is -1,
that says the http_request() its nothing to do.
> when only calling http_request(); in the main.c doesnt work,
have you set GET_WEATHER to 1 in config.h?
> http_get_state is at start -1 ?
yes, so its wait to run with GET command
> do i need to add http_request in the run_http_request function ?
no
> and replace http_request(); in main.c to run_http_request(); ?
no
Sascha
I tried again,
downloaded a fresh uli file ;P
copy past your files into the directory
changed atmega32 > 644
changed some in config.h
but with the same result
i added my source, can you give it a try?
hello,
i download your archive, changed ipaddresses and clockspeed, then
programed to my server.
At serial console type "get" - and it works fine
I see that you changed the IP-Address for download but not changed
GET-String?!
you written that used different subnet's, can test at configuration at
same subnet?
Sascha
heh,
this is really strange, i tried in the same subnet and still, not
working.
i enclosure a wireshark cap file.
line 1: broadcast after boot atmega
line 2: broadcast after boot atmega
line 3: bcast after 'get' command
line 4: reply after get
line 5: tcp start?
line 6: ??
Ok found some new information.
i did install a new webserver on an other pc. lets call this one pc2.
the setup is still in the same subnet.
i've attached 2 wireshark captures. on of pc 2 (new
http_get_test-working-pc2-1145090810.cap) and one of pc1 (old
http_get_test-failure-pc1-1155090810.cap)
PC2 situation:
i booted atmega and typed get. as you can see in wireshark its working!
line 1 to 10.
then i tried again and it failure, as you said line 11..14
PC1:
i booted atmega and typed get. as you can see in wireshark line 3 is
strange, any idea? think this is the problem? but why, its the same code
working with pc1 :/
ok, shameful, the http services on pc1 was crashed :|
it's working
i read about tcp/ip handshaking and close connections.
i'm not sure but if i understand your story it is normal that tcp/ip
ends with a time_wait state at the server side?
This means that the webserver did get a FIN from the mega to determinate
the tcp/ip connection. it sends back to the mega a ACK packet and a FIN.
then it get a ACK back from the mega.
after this procedure the webserver port goes into TIME-WAIT and timed
out after 2 mins << this is what you mean by waiting 2 mins before retry
to setup a connection..? why its waiting 2 minutes, if the mega sends
back the LAST ack then the connection can be closed, right? why wait 2
minutes or is this part of code missing? i cant find it back in the
wireshark captures
beside the atmega project, does every application use this procedure?
what if an application wants to send traffic again? it count the
LOCAL_HTTP_PORT++ ? and setup a connection again?
is there a simple way to detect failures ? duplicate acks, no remote
port is open, any other failures.. ? if so, what would be a simple way
to handle this?
Sj Sj wrote:> i read about tcp/ip handshaking and close connections.
good
> i'm not sure but if i understand your story it is normal that tcp/ip> ends with a time_wait state at the server side?
it is normal? i dont know but i see at ViewTCP also at other connections
sometimes
> This means that the webserver did get a FIN from the mega to determinate> the tcp/ip connection. it sends back to the mega a ACK packet and a FIN.> then it get a ACK back from the mega.
in file "http_get_test-working-pc2-1145090810.cap"
webserver send FIN in packet 7, ATmega answer with a ACK (8) and a
FIN,ACK (9), webserver sends ACK (10)
i can not see an error at this sequence, if i compare with other traffic
the same sequence are used
> after this procedure the webserver port goes into TIME-WAIT and timed> out after 2 mins << this is what you mean by waiting 2 mins before retry> to setup a connection..? why its waiting 2 minutes, if the mega sends> back the LAST ack then the connection can be closed, right? why wait 2> minutes or is this part of code missing? i cant find it back in the> wireshark captures
at TIME-WAIT state or later no more packets exchanged
you can see the state with TCPView http://tcpview.softonic.de/> beside the atmega project, does every application use this procedure?
the http_get is the reversed function of a http server - in the server
project is not needed, but at ulis stack (or my project) is used to show
some infomation (from web) on display
> what if an application wants to send traffic again?
for example http connections can request more than one files with same
connection
>it count the LOCAL_HTTP_PORT++ ? and setup a connection again?
yes this works, but you must kill the last http_get_app from application
stack before changed port. an "kill_tcp_app" function you must implement
in stack because yet not available.
increment PORT is a good way but limit the portrange e.g. 2200 to 2400
if you look at browser traffic then see - each connection used a new
portnumber
> is there a simple way to detect failures ? duplicate acks, no remote> port is open, any other failures.. ? if so, what would be a simple way> to handle this?
oh - detect failures at tcp are very difficult but wireshark helps
Sascha
Thanks again,
i found some code in sendmail.c starting at 241
if mail can't be send it count++ a higher port.
i tried the code below ant it seems to be working, can you verify the
code?
added the else statement, else when FIN the connection you get an extra ACK, the extra ACK is not needed i think?
2
3
void test (unsigned char index)
4
{
5
for (int a = TCP_DATA_START_VAR;a < TCP_DATA_END_VAR;a++)
6
{
7
HTTPC_DEBUG("%c",eth_buffer[a]);
8
}
9
tcp_entry[index].time = TCP_TIME_OFF;
10
if(tcp_entry[index].status & FIN_FLAG)
11
{
12
http_get_state=-1;
13
HTTPC_DEBUG("HTTP Request - EOF\n\r");
14
//tcp_Port_close(index);
15
}
16
else ////changed to else
17
{
18
tcp_entry[index].status = ACK_FLAG;
19
create_new_tcp_packet(0,index);
20
}
21
}
1
removed //unsigned int my_http_cp = LOCAL_HTTP_PORT; using global one, think else it points to other registers when using it?? my atmega crashes when i use it.. ;P
for (int a = TCP_DATA_START_VAR;a < TCP_DATA_END_VAR;a++)
5
{
6
HTTPC_DEBUG("%c",eth_buffer[a]);
7
}
8
tcp_entry[index].time = TCP_TIME_OFF;
9
if(tcp_entry[index].status & FIN_FLAG)
10
{
11
http_get_state=-1;
12
HTTPC_DEBUG("HTTP Request - EOF\n\r");
13
}
14
tcp_entry[index].status = ACK_FLAG;
15
create_new_tcp_packet(0,index);
16
}
/\ send's a ACK packet for each incomming packet, the FIN/ACK packet
following send by the stack.c if FIN is stated in recived packet.
the portchange function is an good idea too, but calculation with time
is not necessary.
1
/*new code*/
2
unsigned int my_httpget_cp_new = my_http_cp + 1;
3
if (my_httpget_cp_new > (LOCAL_HTTP_PORT+300)) my_httpget_cp_new = LOCAL_HTTP_PORT;
Sascha Weber wrote:> /\ send's a ACK packet for each incomming packet, the FIN/ACK packet> following send by the stack.c if FIN is stated in recived packet.
hm, i dont understand what you mean. can you try it again?
----
now i can send data via GET method, i dont know if this is a good way to
send over data. i was thinking something about soap but i think this
would be overkill ?
the main goal is getting data into mysql, any other suggestion to send
over data? think creating a client would be to difficult
Sj Sj wrote:> Sascha Weber wrote:>>> /\ send's a ACK packet for each incomming packet, the FIN/ACK packet>> following send by the stack.c if FIN is stated in recived packet.>> hm, i dont understand what you mean. can you try it again?
with your change (else branch) ACK only send in packets without FIN-flag
> now i can send data via GET method, i dont know if this is a good way to> send over data.> i was thinking something about soap but i think this> would be overkill ?
yes i thinking too, if the exchange with GET enough for your application
the soap-protokoll dont bring a advantage
> the main goal is getting data into mysql, any other suggestion to send> over data? think creating a client would be to difficult
if you can use a cronjob at webserver, it can request data from atmega -
your data put into the file which sends from atmega
Sascha
I'm not sure about the else.
if i remove the else i get one ack to much in wireshark, i.e. i THINK i
see one to much.
but,
if i look to the code, after every received packet in function:
1
void http_request (void)
2
3
tcp_entry[index].status = ACK_FLAG | PSH_FLAG;
there's an ack send
maybe this ack is send to much and not the one in the test function.
perhaps it is by chance?
if i look at sendmail.c there is no ack send:
1
//Daten kommen vom EMAIL- Server an!! (Mail wird versendet)
Sj Sj wrote:> I'm not sure about the else.>> if i remove the else i get one ack to much in wireshark, i.e. i THINK i> see one to much.
i see, after server send's datapacket with FIN atmega send an ACK packet
and an FIN/ACK packet - of principle is enough to send second packet
with FIN/ACK.
see also ...
http://en.wikipedia.org/wiki/Transmission_Control_Protocol#Connection_termination
"It is also possible to terminate the connection by a 3-way handshake,
when host A sends a FIN and host B replies with a FIN & ACK (merely
combines 2 steps into one) and host A replies with an ACK.[13] This is
perhaps the most common method."
<- B can send one packet with FIN&ACK or 2 packets - one with ACK and
one with FIN
i test it to send in second packet only FIN and not FIN/ACK, then
TCPView says FIN_wait2 status.
> but,>> if i look to the code, after every received packet in function:>
1
> void http_request (void)
2
>
3
> tcp_entry[index].status = ACK_FLAG | PSH_FLAG;
4
>
this only send with GET request - once per connection
> if i look at sendmail.c there is no ack send:>
1
> //Daten kommen vom EMAIL- Server an!! (Mail wird versendet)
in to the test() function
as result i do get 3 way handshake but then, for a while nothing happen.
after a period of time (32 secs) it sends a 'TCP ACK' protocol packet
thats it.
i guess it would be possible to mutate the code more formally like
sendmail.c but there's something going wrong. can you help me a little?
Sj Sj wrote:> Hi again,>> I'm trying to mutate http_get.c into a style of sendmail.c, of course> without luck.
why?
> if i look to sendmail.c there is no>>
1
> ////tcp_entry[index].first_ack = 1;
2
>
>> in the mail_send() function, so i comment it in the http_get.c (any idea> why this line is used?)
i think that is useless, then in stack.c i found this at
//Server öffnet Port
... for outgoing connections, and at
//Empfangene Packet wurde bestätigt keine Daten für Anwendung
//z.B. nach Verbindungsaufbau (SYN-PACKET)
... for incomming connections
> i moved:>
1
>
2
> //if (http_get_state == 10)
3
> if (http_get_state > 10 && http_get_state < 20)
4
> {
5
> HTTPC_DEBUG("\r\n\r\n\r\nDaten Anfordern\r\n");
6
> index = tcp_entry_search (WEATHER_SERVER_IP,HTONS(80));
>> in to the test() function>> as result i do get 3 way handshake but then, for a while nothing happen.> after a period of time (32 secs) it sends a 'TCP ACK' protocol packet> thats it.
the test() function is only execute if incomming packets recived from
server. If you see at stack.c "//Server öffnet Port" - there atmega
send's ACK packet for 3 way handshake (step 3), but user application
[test()] is not running
> i guess it would be possible to mutate the code more formally like> sendmail.c but there's something going wrong. can you help me a little?
at sendmail there is a little difference:
after opening connenction initiated by atmega, the server sends a packet
first. Thereby the user_appliction [mail_send(void)] is running after
connection opend.
At http_get, you must send the first packet (/GET ...) after connenction
established.
Sascha
thanks,
i saw it later, but thanks for the confirmation.
i'm trying to create a dynamic GET url but it's PROGMEM.
i tried a few codes but every time the microcontroller reboots
the url:
and where %d = the dynamic value
any suggestions? i tried to use sprintf_P but then the mic crashes and i
need to declare a big char for the url string, but then the advantage
isn't any more i guess.
-------
ok found a solution:
Hello Sj Sj,
I got from Sascha a tip that you both spoke about the problem to fetch
web sites with ETH_M32. I have the same problem. Did you fix the
problem?
Can you send me your source of the http_get.c.
Thanks for your support
Markus
Hi Markus,
see attachment, this is my working code. if you change the code or have
some new idea's, please share.
are you using the m32 or webserver with fat support version from uli?
Hey Sj Sj,
thanks for the answer. I use at the moment the standard Stack 1.2.5 from
Uli. My AVR is a 644P.
I tried your code but I have no look. It doesn't work.
Following situation:
AVR send SYN
WEB SERVER SYN;ACK
AVR sends no ACK, it sends the GET Request
I have to check the code.
Do you have any answer?
br Markus
hm maybe this part of code stuck, im trying to create a dynamic url but
didnt work yet,
try this:
comment the last PROGMEM line and uncomment the first, think the %d
stucks
I did before. I use this code.
PROGMEM char WEATHER_GET_STRING[] = {"GET /xampp/mypost.php
HTTP/1.1\r\n"
"Host: 10.1.61.188\r\n"
//"Keep-Alive: 300\r\n"
"Connection: Close\r\n\r\n"};
It's a INTRANET with a Apache Server. All ip's you see are in the
private lan.
aint be sure but i think you dont need to add PROGMEM char
WEATHER_GET_STRING[] = {"GET /xampp/mypost.php HTTP/1.1\r\n"
xampp dir to the url
are you using wireshark to verify the handshake? please upload, you can
filter out the rest of your network traffic
hi how its going? already got it working?
i tried the same code with the 'will mmc/ftp' version and its not
working. no idea yet,
its sending the post as a retransmission :/
Hello Harry,
my I am new here. My Hobbys are Centre Dialect and detecting lies.
I craving to deal with people here with the unchanging interests.
Cu
Kat
i've got a working code but it does not working when i'm logging to a
remote lan via vpn.
<lan atmega> <vpn device> internet <vpn device> <webserver>
for local lan test i used a windows webserver, remote its linux.
i dont know why but it seems that the GET sends earlier then an ack is
send:
any idea why its working on local lan but not via vpn?
when my pc is quite busy and rs232 is 'hanging' sometimes the connection
works, looks like timing / delay issue
, only then ACK-Packet has been send.
At fast connections at LAN, the looptime in main for calling
http_request brings enough delay to send ACK before http_get_state
achieved a value greater than 10.
Sascha
... no - while waiting the stack must process incoming pakets
see attachment
to info:
* stackentry found if SYN-Packet has been sent (tcp_entry_search)
* app_status=1 if SYN/ACK has been received and ACK sent
in mainloop it would better that calling 'http_request' only once every
second. Then timeouts are better definable.
Sascha
at stack.c you can see that app_status set to 1 after debugmessage
"TCP Port wurde vom Server geöffnet STACK:0; TCP SrcPort -23368"
the failur in my code is, that the variable 'index' is not initialize
from second call of http_request.
I correct it ...
Sascha
i tested with a linux machine in my other local lan (routed) and got the
same results as the vpn!!
this is what i see when i connect from a pc > vpn > linux webserver
Hello,
the only different between Windows and Linux ist the extra ACK-Paket in
Frame 5 as answer of GET-Paket. I look at stack.c and tcp_application is
running every ACK-Paket is incoming - also an empty ACK-Paket. From APP
=>void test (unsigned char index) this pakets also replyed with ACK -
its an ACK to much.
Test with return if paket is empty ...
[c]
//Daten kommen von einem Webserver an!!
void test (unsigned char index)
{
char buffer[10]={0};
for (int a = TCP_DATA_START_VAR;a < TCP_DATA_END_VAR;a++)
{
HTTPC_DEBUG("%c",eth_buffer[a]);
if (eth_buffer[a] == '$') //look for #$ string
{
if (eth_buffer[a+1] == '#')
{
if (eth_buffer[a+2] != '1')
{
usart_write("SQL insert failed\r\n",eth_buffer[a+2]);
}
}
}
}
tcp_entry[index].time = TCP_TIME_OFF;
if(tcp_entry[index].status & FIN_FLAG)
{
http_get_state=-1;
usart_write("HTTP Request - EOF\n\r");
usart_write("-------\r\n");
return;
}
if (TCP_DATA_START_VAR == TCP_DATA_END_VAR)
{
return; //no reply for empty pakets
}
tcp_entry[index].status = ACK_FLAG;
create_new_tcp_packet(0,index);
}
Sascha
thanks again! its working
but still got a amount of questions,
- why it's replying to an empty ack? why is linux sending this ack and
windows don't?
- why do i need to delay the http_request in main() when using vpn?
- seems to be that sometimes when my pc is busy, rs232 is delayed,
because rs232 delay, tcp packets of the atmega are to late because of
rs232 looping? if its to late then the tcp session broke, any idea how
to fix this?
Sj Sj wrote:> thanks again! its working>> but still got a amount of questions,>> - why it's replying to an empty ack? why is linux sending this ack and> windows don't?
why? both variants are approved, the stack can send an "only"-ACK-packet
(Linux) or it can combine with reply of data (Win)
> - why do i need to delay the http_request in main() when using vpn?
you don't need the delay, I said it's better for set timeoutvalues if
the time between two calls is a fixed value
For example you can use the 1 sec timebase from timer.c, add a flag that
check in main to call http_request(), or move the line ...
> - seems to be that sometimes when my pc is busy, rs232 is delayed,> because rs232 delay, tcp packets of the atmega are to late because of> rs232 looping? if its to late then the tcp session broke, any idea how> to fix this?
if connection etablished in stack.c is an function 'tcp_timer_call' to
kill stackentry after 3 sec (TCP_MAX_ENTRY_TIME) of inactivity. Before
connection etablished the timeout is realized with counting of
'http_get_state'.
Sascha
i tested the code and it crashes after a while.
like about > 1 hour logging. with samples of 10 secs, the tcp stack is
crashing, i think.
last count was from sourceport 2345 till 2663 = 318
i debugged the code when testing.
everytime the last GET is going fine. but then it crashed and i dont
know where.
when its working the debug code looks like:
HTTP GET URL: GET /temp/insert.php?S1=1&T1=0&S2=2&T2=202&S3=3&T3=0&S4=4&T4=201&Time=20:32:56&Date=2010-10-07 HTTP/1.1
82
Host: www.webservicex.net
83
Connection: close
not even tcp stack debug code so thats why i think it crashes, the tcp
entry list is empty too..
[code]
RROR - HTTP Request BUSY
tcp
ERROR
tcp
00 IP:000.000.000.000 PORT:0000 Time:0000
01 IP:000.000.000.000 PORT:0000 Time:0000
02 IP:000.000.000.000 PORT:0000 Time:0000
03 IP:000.000.000.000 PORT:0000 Time:0000
04 IP:000.000.000.000 PORT:0000 Time:0000
Ready
arp
00 MAC:00.00.00.00.00.00 IP:000.000.000.000 Time:0000
01 MAC:00.10.db.9f.f0.02 IP:192.168.010.001 Time:0099
02 MAC:00.00.00.00.00.00 IP:000.000.000.000 Time:0000
03 MAC:00.00.00.00.00.00 IP:000.000.000.000 Time:0000
04 MAC:00.00.00.00.00.00 IP:000.000.000.000 Time:0000
Ready
[code]
any idea how to futher debug this and if there is a timer that crashes?
after a reboot everything works fine.
what crashes?
AVRServer ist complete busy?
No connections at net are acceptet, no serial commands are execute?
Before are moving count of 'http_get_state' it works continuously?
How much you start the transmission - 10s? -> its too often!
TCP-Connection-Timeout is 30s!
If connection is break, after this time the stackentry is killed.
Therefore the requestrate should greater than Timeout!
Sascha
hi,
i tought it was crashing but i still can ping the device, telnet to the
device and the webserver http page is working.
[quote]
Before are moving count of 'http_get_state' it works continuously?
[/quote]
no
[quote]
How much you start the transmission - 10s? -> its too often!
TCP-Connection-Timeout is 30s!
If connection is break, after this time the stackentry is killed.
Therefore the requestrate should greater than Timeout!
[/quote]
temp samples are 10 secs yes. what do you mean by timeout 30 secs? i
start a new tcp session with a different tcp source port.
and if it's to often, why its working for aproxx > 1 hour?
Sj Sj wrote:> hi,>> i tought it was crashing but i still can ping the device, telnet to the> device and the webserver http page is working.
then server not crashed! The error message is "HTTP Request BUSY" ?
>> TCP-Connection-Timeout is 30s!>> If connection is break, after this time the stackentry is killed.>> Therefore the requestrate should greater than Timeout!>> temp samples are 10 secs yes. what do you mean by timeout 30 secs? i> start a new tcp session with a different tcp source port.
you read temps every 10 secs? You send temps also ervery 10 secs?
> and if it's to often, why its working for aproxx > 1 hour?
if tcp-connection is hang stackentry is kill after timeout (30secs), if
you start a new connection - a new stackentry is needed but only place
for 5 entrys at stack.
--
If you get "HTTP Request BUSY" it says that previous transmission is not
end.
If counting 'http_get_state' each second, a timeout not until 21 secs.
please send your actual timer.c, and http_get.c
Sascha
yes, error message is ERROR - HTTP Request BUSY
every 10 secs is a temperature sample and GET to the remote server. this
delay was small, just for testing.
today i tried to sample/GET every 40 secs. it runs for 4.5 hours then it
quits
with 10 secs it approx 1,10 hour, 40 secs 4,5, looks proportional.
see attachments
i commented
1
//NEW
2
//if (http_get_state == 20) //20 or more (if waittime to short) but you must change some values more
I changed something ...
new http_get_state's
-1 nothing to do
0 start request; try to open connection
2 tcp-entry at stack successful, SYN-packet sent
if error at tcp-entry go to state -1
2..6 wait to SYN-ACK receiving [4 secs max]
if reached 6 go to state -1
10 connection etablished; data sent
10..16 wait for incomming data from server (at each packet reset state
to 11)
timeout after 5 secs and go to state -1
test it with minimum of 20 secs between requests, and look for last
message before crash (i hope not).
Sascha
i tried the code,
but... without luck =)
see attachment.
- much arp request at startup,
- after "Connection etablished!" 3 times Daten Anfordern instead of 1 ?
is there a problem with parallel access to variable "http_get_state"
from main/http_request and ISR in timer.c possible? Is the declaration
correct? - I dont know about C.
Sascha
is set in http_get.c but timer.c start http_get_state at 0
timer.c is including the http_get_state from http_get.h because if i
dont include this file i get an error.
1
System Ready
2
Compiliert am Oct 12 2010 um 18:48:24
3
Compiliert mit GCC Version 4.3.2
4
5
IP 192.168.1.99
6
MASK 255.255.255.0
7
GW 192.168.1.1
8
http_get_state timer = -1
9
10
TIME: 17:52:18
11
HTTP Request
12
http_get_state timer = 0
13
http_get_state timer = 0
14
debug 1
15
debug 2
16
debug 3
17
debug 4
18
TCP Eintrag gefunden (HTTP_CLIENT)!
19
http_get_state timer = 2
20
http_get_state timer = 3
21
http_get_state timer = 4
22
http_get_state timer = 5
23
TCP-SYN-Timerout!
24
http_get_state timer = -1
25
HTTP Request
26
http_get_state timer = 0
27
debug 1
28
debug 2
29
debug 3
30
debug 4
31
TCP Eintrag gefunden (HTTP_CLIENT)!
32
http_get_state timer = 2
33
LM92_ReadTemperature
34
http_get_state timer = 3
35
http_get_state timer = 4
36
http_get_state timer = 5
37
TCP-SYN-Timerout!
38
http_get_state timer = -1
39
HTTP Request
40
http_get_state timer = 0
http_get_state is always counting and its the counter from timer.c
1
if(http_get_state>1)
2
{
3
http_get_state++;
so i think if >1 is not working, or is -1 greater then 1 ? =)
until now it seems to be working, but i only tested for a few hours.
i split the lm92 (temperature sensor) samples and the http_requests with
different timers.
lm92 polls every 10 secs and http_request 40 secs.
i copied the same code from ntp_timer in main.c
the var's are countdown in timer.c the strange thing is, sometimes
lm92_timer is -1 if POST and lm92 samples runs at the same time.
using ! does not seem reliable, i think it would be better to define the
countdown var as
HTTPC_DEBUG("TCP Eintrag nicht gefunden (HTTP_CLIENT)!\r\n");
7
http_get_state=-1;
8
mail_enable=1;
9
sprintf(mail_error,"%s","no TCP");
10
11
return;
12
}
13
}
1
else
2
{
3
http_get_state=-1;
4
mail_enable=1;
5
sprintf(mail_error,"%s","no arp");
6
7
}
1
2
if(http_get_state==6)
3
{
4
usart_write("TCP-SYN-Timerout!\r\n");//no syn-ack within 4 secs (State from 2 to 6)
5
http_get_state=-1;
6
mail_enable=1;
7
sprintf(mail_error,"%s","No Syn");
8
}
9
10
if(http_get_state==16)
11
{
12
usart_write("TCP-Connection-Timeout!\r\n");//no incomming packets within 5 secs (State from 11 to 16)
13
http_get_state=-1;
14
mail_enable=1;
15
sprintf(mail_error,"%s","TCP Time");
16
}
i still get mails with TCP Time and No Syn messages. i dont know how to
fix, is this normal? can tcp packets dropped that much? sometimes it
goes ok for a while but then it stucks for 30 mins, it fixes itself but
i miss data...
Sj Sj wrote:> i still get mails with TCP Time and No Syn messages. i dont know how to> fix, is this normal?
i don't know
> can tcp packets dropped that much? sometimes it> goes ok for a while but then it stucks for 30 mins, it fixes itself but> i miss data...
packet loss is not an error, but regular single packet loss only.
with which transmission path you tested?
how much send packets?
an delay for 30 mins sees for me as an packet block up at your server to
prevent DOS-Attack?!
Sascha
ok this is strange,
i bugged better and see that the data is inserted but after a while
every insert(http_get_state) ends with 16. i captured with wireshark and
the packets are ok! looks like when data arrives, http_get_state == 11
till 16 is to short?
1
if(http_get_state==16)
2
{
3
usart_write("TCP-Connection-Timeout!\r\n");//no incomming packets within 5 secs (State from 11 to 16)
4
http_get_state=-1;
5
mail_enable=1;
6
sprintf(mail_error,"%s","TCP Time");
7
}
any suggestions? else i try to change 16 to 20?
1
if(tcp_entry[index].status&FIN_FLAG)
2
{
3
http_get_state=-1;
4
5
usart_write("HTTP Request - EOF\n\r");
6
usart_write("-------\r\n");
7
return;
8
}
after inserting the sql data i see at console HTTP Request - EOF then it
tooks 5 secs before i get the message
1
usart_write("TCP-Connection-Timeout!\r\n");
so it looks like that the timer.c overwrite's the value -1
Sj Sj wrote:> so it looks like that the timer.c overwrite's the value -1
yes this can be a problem!
solution:
at timer.c only set a flag like 'eth.timer', move the http_get_state
handling from timer.c to http_get.c and process if flag is set and reset
flag following.
timer.c
Sj Sj wrote:> i dont understand your solution, the variable is already used for other> states so i cant use it for 0/1 (flag)?
which variable ?
for flag you must define a new global variable ...
Hallo,
i look at your debuglog and i belief the problem is at "void test
(unsigned char index)". It's the only position to set state to 11. The
function is running after transmission FIN+ACK and set state to -1
another once if ACK-packet from server received and set state to 11 and
set TCP-Time to 255 (TCP_TIME_OFF) also.
add the follow line ...
i captured with wireshark maybe it helps.
it runs fine for x minutes and then it crashes. looks like the mega
can't handle the duplicated syn from the webserver?
it looks like when it failures sequence numbers are zero, the next try
(tcp session) the sequence number is again zero, this cant be?
or can a sequence number be zero again when using a different source
port?
i'm not sure, aint be that good to research...
Sj Sj wrote:> when adding this line it failures at start> ...> http_get_state timer sec 0> lm92_timer 9, http_request_timer 39> http_get_state timer sec 0> lm92_timer 8, http_request_timer 38> http_get_state timer sec 3> lm92_timer 7, http_request_timer 37> http_get_state timer sec 4> lm92_timer 6, http_request_timer 36> http_get_state timer sec 5> lm92_timer 5, http_request_timer 35> TCP-SYN-Timerout!> http_get_state -1> ...>> think because it dont reaches the fin flag anymore
i dont understand - AVR don't get SYN-ACK from server, but the
connection establishment is handled by stack, and the function "test" is
not runnig there.
------------------------------------------------------------------------
> i captured with wireshark maybe it helps.>> it runs fine for x minutes and then it crashes. looks like the mega> can't handle the duplicated syn from the webserver?
this capture is recorded without or with added line?
for SYN/ACK at frame 463 avr sends no reply with ACK !? Is it too busy?
Between frame 471 and 472 ACK-packet, which created by stack.c, are
missing!
------------------------------------------------------------------------
> it looks like when it failures sequence numbers are zero, the next try> (tcp session) the sequence number is again zero, this cant be?
Yes it's ok - the zero is always the "relativ seq-number" the absolute
number starts always with the value at >stack.c/tcp_port_open<
Sascha