user_tcp_recv_cb - parameter 'arg'

Stational
Posts: 42
Joined: Sat Jul 02, 2016 10:54 pm

user_tcp_recv_cb - parameter 'arg'

Postby Stational » Sun Sep 04, 2016 3:48 am

Hi,

i am wondering if the argument called 'arg' of the user_tcp_recv_cb - function is from the type struct espconn and can be used to send a http request?

Code: Select all

LOCAL void ICACHE_FLASH_ATTR user_tcp_recv_cb(void *arg, char *pusrdata, unsigned short length)


I am asking because i do that and my website doesn't respond to the request. I do it like this:

Code: Select all

struct espconn *pespconn = (struct espconn *)arg;
send_request_temp(pespconn, returnObject[n].ID);

pratik

Re: user_tcp_recv_cb - parameter 'arg'

Postby pratik » Mon Sep 05, 2016 9:54 am

Hello,

The passed arg is actually a pointer to the structure that contains info on the connection which sent you the data. So you are right about using it to send data.
If things are not working, I'd suggest disabling multiple connections by setting max connections to 1. Then see if it works.
Also, register a data sent callback that confirms that the data was sent.

Stational
Posts: 42
Joined: Sat Jul 02, 2016 10:54 pm

Re: user_tcp_recv_cb - parameter 'arg'

Postby Stational » Mon Sep 05, 2016 8:35 pm

Thanks for your reply, pratik.

If things are not working, I'd suggest disabling multiple connections by setting max connections to 1. Then see if it works.

Okay, i did that in the tcp_connect callback:

Code: Select all

espconn_tcp_set_max_con_allow(pespconn,1);


In this callback i first call a function "user_send_get_requests" which sends a HTTP request (for this one i get the tcp_sent callback message). I receive some data from that request which i process in the tcp_recv callback. In this callback i call another function which sends another HTTP request with the processed data, and for that one i don't get a tcp_recv callback. I check the state of espconn. Before espconn_send (so before i send the 2nd request), pespconn has the state "5", after espconn_send it has the state "4" (so it isn't disconnected):

Code: Select all

LOCAL void ICACHE_FLASH_ATTR
user_send_request_temp(struct espconn *pespconn, char *reqID){
   os_printf("STATE: %d\n", (int)pespconn->state);
   //removed some code here
   espconn_send(pespconn, pbuf,os_strlen(pbuf));
   os_printf("STATE: %d\n", (int)pespconn->state);
}


Setting the max allowed tcp connections didn't help :(

Any ideas?

pratik

Re: user_tcp_recv_cb - parameter 'arg'

Postby pratik » Tue Sep 06, 2016 9:44 pm

This does not seem like an SDK issue.
I'd suggest these approaches of tracing the problem down:
1. Verify that the data is sent using the send function (inside the recv_callback) is actually transmitted by setting a sent_callback.
2. If step 1 confirms data is being sent alright, then you can check espconn status in this sent_callback function, instead of where you are checking now. This way, if sent_cb is not executed or has error - you know that the link was faulty and the GET request failed.
3. If above is all good but the server still does not respond, you should make sure the server understands the GET command using telnet.
4. If above steps work, you probably need to use a local server and debug the link in further detail.

I believe step 2 will probably solve your issue. :)

Stational
Posts: 42
Joined: Sat Jul 02, 2016 10:54 pm

Re: user_tcp_recv_cb - parameter 'arg'

Postby Stational » Wed Sep 07, 2016 6:04 pm

Thanks a lot for your help :)

2. If step 1 confirms data is being sent alright, then you can check espconn status in this sent_callback function, instead of where you are checking now. This way, if sent_cb is not executed or has error - you know that the link was faulty and the GET request failed.

As I said i am sending two requests, the first one runs successfully and i also get a tcp_sent callback (which looks like this):

Code: Select all

LOCAL void ICACHE_FLASH_ATTR
user_tcp_sent_cb(void *arg)
{
   struct espconn *pespconn = (struct espconn *)arg;
    os_printf("tcp sent succeed, STATE IS: %d !!! \r\n",(int)pespconn->state);
}


The state of the connection is '3' (so ESPCONN_LISTEN i guess), this means for me that the connection is still established and not disconnected? Therefore i think that it shouldn't be a problem to send another request with the same connection, should it?

I use the exact same request structure in my second request, for example, this is my first request:

Code: Select all

os_sprintf(requestText, "GET /SQL.php?request=getReq / HTTP/1.1\r\nUser-Agent: curl/7.37.0\r\nHost: %s\r\nAccept: */*\r\n\r\n",NET_DOMAIN);


where NET_DOMAIN is my website.

That's my second request:

Code: Select all

os_sprintf(requestText, "GET /SQL.php?request=enterTemp&reqid=%s&value=%d / HTTP/1.1\r\nUser-Agent: curl/7.37.0\r\nHost: %s\r\nAccept: */*\r\n\r\n",reqID,tempValue,NET_DOMAIN);


Why would the first one work but the second one not? I print the request to serial terminal and it looks like this:

GET /SQL.php?request=enterTemp&reqid=5&value=34 / HTTP/1.1
User-Agent: curl/7.37.0
Host: http://www.mywebsite.org
Accept: */*


you know that the link was faulty and the GET request failed.


Because of that i don't think that my request is wrong but it failed for sure. I also sent the originally second request as first one and it worked fine!

3. If above is all good but the server still does not respond, you should make sure the server understands the GET command using telnet.

Unfortunately my webspace provider doesn't offer a telnet connection (i am using a hoster who offers free webspaces).

Who is online

Users browsing this forum: No registered users and 56 guests