HttpClient icon indicating copy to clipboard operation
HttpClient copied to clipboard

question about responseStatusCode

Open krapp70 opened this issue 11 years ago • 11 comments

Hi, I am a newbie of github, so I apologise if I am using this issue tracking to ask a question...

I am using Arduino UNO + Ethernet Shield + xively library (https://github.com/xively/xively_arduino, that it is based upon the HttpClient library) to put some temperature data from a sensor to the xively platform.

Everythig works fine except that happens once in while (sorry... let's say randomly) that Arduino hangs on the xively put function, which recall the HttpClient put + sendHeader + endRequest + responseStatusCode + flush + stop functions.

The question is: I modified the responseStatusCode adding a timeout condition on the while loop for the informational status code

while ( (iState == eStatusCodeRead) && (iStatusCode < 200) && 
           ( (millis() - timeoutStartResponse) < iHttpResponseTimeout ));

and I don't have freezes anymore, but I am sure (I do not know the http protocoll) that there is a better solution for this problem, maybe it's a server problems, and I would like to know what you think about.

thanks best regards Federico

krapp70 avatar Mar 13 '14 22:03 krapp70

this is not my library, I only fork it. But I also have some troubles with it. I think all troubled come from lack of RAM (not program size). You shoud reduce number of variables and recurse function calls.

2014-03-14 2:29 GMT+04:00 krapp70 [email protected]:

Hi, I am a newbie of github, so I apologise if I am using this issue tracking to ask a question...

I am using Arduino UNO + Ethernet Shield + xively library ( https://github.com/xively/xively_arduino, that it is based upon the HttpClient library) to put some temperature data from a sensor to the xively platform.

Everythig works fine except that happens once in while (sorry... let's say randomly) that Arduino hangs on the xively put function, which recall the HttpClient put + sendHeader + endRequest + responseStatusCode + flush + stop functions.

The question is: I modified the responseStatusCode adding a timeout condition on the while loop for the informational status code

while ( (iState == eStatusCodeRead) && (iStatusCode < 200) && ( (millis() - timeoutStartResponse) < iHttpResponseTimeout ));

and I don't have freezes anymore, but I am sure (I do not know the http protocoll) that there is a better solution for this problem, maybe it's a server problems, and I would like to know what you think about.

thanks best regards Federico

— Reply to this email directly or view it on GitHubhttps://github.com/amcewen/HttpClient/issues/9 .

Михаил Богатырев Digital Park http://dipark.ru

innovup avatar Mar 14 '14 04:03 innovup

something like this then?

unsigned long timeoutStartResponse = millis();
while ( (iState == eStatusCodeRead) && (iStatusCode < 200) && 
       ( (millis() - timeoutStartResponse) < iHttpResponseTimeout ));

Me too have problems with Xively timing out after about 1 week of continous upload to Xively server.

/Anders

13 mar 2014 kl. 23:29 skrev krapp70 [email protected]:

Hi, I am a newbie of github, so I apologise if I am using this issue tracking to ask a question...

I am using Arduino UNO + Ethernet Shield + xively library (https://github.com/xively/xively_arduino, that it is based upon the HttpClient library) to put some temperature data from a sensor to the xively platform.

Everythig works fine except that happens once in while (sorry... let's say randomly) that Arduino hangs on the xively put function, which recall the HttpClient put + sendHeader + endRequest + responseStatusCode + flush + stop functions.

The question is: I modified the responseStatusCode adding a timeout condition on the while loop for the informational status code

while ( (iState == eStatusCodeRead) && (iStatusCode < 200) && ( (millis() - timeoutStartResponse) < iHttpResponseTimeout )); and I don't have freezes anymore, but I am sure (I do not know the http protocoll) that there is a better solution for this problem, maybe it's a server problems, and I would like to know what you think about.

thanks best regards Federico

— Reply to this email directly or view it on GitHub.

tvillingett avatar Mar 14 '14 07:03 tvillingett

Hi, the snippet I posted was just to let you see I added the timeout:

(millis() - timeoutStartResponse) < iHttpResponseTimeout )

.. obviously I added at the beginning of the loop the definition of the variable

unsigned long timeoutStartResponse = millis()).

Anyway I think it's not a memory problem, I monitored the RAM but seen no leakage while after I modified the code adding the timeout I had no more problem. But I was looking for a better solution!

thanks Federico

krapp70 avatar Mar 14 '14 08:03 krapp70

When I move the declaration to the place as the other timeout I get compile error: unsigned long timeoutStart = millis(); unsigned long timeoutStartResponse = millis();

/Users/tvillingett/Documents/Arduino/libraries/HttpClient/HttpClient.cpp:384: error: 'timeoutStartResponse' was not declared in this scope

I might need some more coffee... I'm code blind at the moment, please tell me where you put it :)

/Anders

14 mar 2014 kl. 09:00 skrev krapp70 [email protected]:

Hi, the snippet I posted was just to let you see I added the timeout:

(millis() - timeoutStartResponse) < iHttpResponseTimeout )

.. obviously I added at the beginning of the loop the definition of the variable

unsigned long timeoutStartResponse = millis()).

Anyway I think it's not a memory problem, I monitored the RAM but seen no leakage while after I modified the code adding the timeout I had no more problem. But I was looking for a better solution!

thanks Federico

— Reply to this email directly or view it on GitHub.

tvillingett avatar Mar 14 '14 08:03 tvillingett

ops, sorry :) As soon as I come back home (I haven't still pushed the code on gitHub) I send the complete code.

bye Federico

krapp70 avatar Mar 14 '14 09:03 krapp70

I had some coffee now, and placed it right. It works with both compile and downloading to my arduino. In a week I will know if it is better than before.

Thanks!

/Anders

14 mar 2014 kl. 10:46 skrev krapp70 [email protected]:

ops, sorry :) As soon as I come back home (I haven't still pushed the code on gitHub) I send the complete code.

bye Federico

— Reply to this email directly or view it on GitHub.

tvillingett avatar Mar 14 '14 09:03 tvillingett

OK. Let me know. With this modification my Arduino has been putting data on xively for more than a week without freezing. But I am looking for a better solution, let's say I just worked empirically :)

bye Federico

krapp70 avatar Mar 14 '14 10:03 krapp70

Hello,

Your solution with the timeout is fine and good practice, if you want to dig it, i recommend to debug each var value on that while variables to see what value comes that affects it. Where to you set that vars ? Are you not reaching some part of the code on a particular situation? http://www.w3.org/Protocols/HTTP/HTRESP.html

Also i have trobble with the ethernet shield locking in the summer due to build up temperature, requiring hard reset but thats another thread.

Regards, Chaveiro

2014-03-13 22:29 GMT+00:00 krapp70 [email protected]:

Hi, I am a newbie of github, so I apologise if I am using this issue tracking to ask a question...

I am using Arduino UNO + Ethernet Shield + xively library ( https://github.com/xively/xively_arduino, that it is based upon the HttpClient library) to put some temperature data from a sensor to the xively platform.

Everythig works fine except that happens once in while (sorry... let's say randomly) that Arduino hangs on the xively put function, which recall the HttpClient put + sendHeader + endRequest + responseStatusCode + flush + stop functions.

The question is: I modified the responseStatusCode adding a timeout condition on the while loop for the informational status code

while ( (iState == eStatusCodeRead) && (iStatusCode < 200) && ( (millis() - timeoutStartResponse) < iHttpResponseTimeout ));

and I don't have freezes anymore, but I am sure (I do not know the http protocoll) that there is a better solution for this problem, maybe it's a server problems, and I would like to know what you think about.

thanks best regards Federico

Reply to this email directly or view it on GitHubhttps://github.com/amcewen/HttpClient/issues/9 .

chaveiro avatar Mar 14 '14 14:03 chaveiro

Yes, you are right... but I dont' have much free time to debug :)

At the beginning I thought was a memory problem, so I monitored for a while the RAM, but everything seemed fine. I also wanted to trace the sever response via Serial, but the freeze was radom (maybe after 2/3 days). Then I looked up to write a log in the SD, but I had some problem with the SD library!

At the end I just gave a look to the code and added the time out where I thought it could be the problem. It worked, but I wrote this post becasue it looks like a wierd problem.

As I wrote I do not know the HTTP protocol (thanks fo the link) and I am just having fun once in a while with arduino & C.; it has to remain at a fun level!

Let's wait the test of tvillingett :)

thanks Federico

krapp70 avatar Mar 14 '14 20:03 krapp70

Sorry to say that my test did fail. It failed after about 8h. We need to have a way to do some kind of debugging, with logging. There is a problem with the limited resources.

/Anders

14 mar 2014 kl. 21:42 skrev krapp70 [email protected]:

Yes, you are right... but I dont' have much free time to debug :)

At the beginning I thought was a memory problem, so I monitored for a while the RAM, but everything seemed fine. I also wanted to trace the sever response via Serial, but the freeze was radom (maybe after 2/3 days). Then I looked up to write a log in the SD, but I had some problem with the SD library!

At the end I just gave a look to the code and added the time out where I thought it could be the problem. It worked, but I wrote this post becasue it looks like a wierd problem.

As I wrote I do not know the HTTP protocol (thanks fo the link) and I am just having fun once in a while with arduino & C.; it has to remain at a fun level!

Let's wait the test of tvillingett :)

thanks Federico

— Reply to this email directly or view it on GitHub.

tvillingett avatar Mar 15 '14 10:03 tvillingett

oh... I am sorry. Anyway I don't think it's a resources problem, I only modified the loop and it's been almost a week Arduino is sending data to xively, day and night, once every ten minutes; if the timeout is not the solution then I would say that, in my case, was a server problem.

As soon as I get some time I will try to compile the skecth with the original httpclient library and see if it freezes.

If you want to give a look my sketch you can find it at https://github.com/krapp70/arduino_test_repo/tree/master/test_vari2/test_xively5 (don't mind the code about the leds, it's just for my kids) and this is what I am using:

-Arduino UNO -Arduino Ethernet Shield -Xively Library (https://github.com/xively/xively_arduino) -HttpClient Library modified (https://github.com/krapp70/HttpClient)

bye Federico

krapp70 avatar Mar 15 '14 14:03 krapp70