ESP8266 Developer Zone The Official ESP8266 Forum 2016-09-07T18:04:06+08:00 https://bbs.espressif.com:443/feed.php?f=7&t=2739 2016-09-07T18:04:06+08:00 2016-09-07T18:04:06+08:00 https://bbs.espressif.com:443/viewtopic.php?t=2739&p=9763#p9763 <![CDATA[Re: user_tcp_recv_cb - parameter 'arg']]>


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:

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:

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:

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).

Statistics: Posted by Stational — Wed Sep 07, 2016 6:04 pm


]]>
2016-09-06T21:44:32+08:00 2016-09-06T21:44:32+08:00 https://bbs.espressif.com:443/viewtopic.php?t=2739&p=9755#p9755 <![CDATA[Re: user_tcp_recv_cb - parameter 'arg']]> 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. :)

Statistics: Posted by Guest — Tue Sep 06, 2016 9:44 pm


]]>
2016-09-05T20:35:47+08:00 2016-09-05T20:35:47+08:00 https://bbs.espressif.com:443/viewtopic.php?t=2739&p=9741#p9741 <![CDATA[Re: user_tcp_recv_cb - parameter 'arg']]>

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:

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:

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?

Statistics: Posted by Stational — Mon Sep 05, 2016 8:35 pm


]]>
2016-09-05T09:54:09+08:00 2016-09-05T09:54:09+08:00 https://bbs.espressif.com:443/viewtopic.php?t=2739&p=9729#p9729 <![CDATA[Re: user_tcp_recv_cb - parameter 'arg']]>
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.

Statistics: Posted by Guest — Mon Sep 05, 2016 9:54 am


]]>
2016-09-04T03:48:30+08:00 2016-09-04T03:48:30+08:00 https://bbs.espressif.com:443/viewtopic.php?t=2739&p=9720#p9720 <![CDATA[user_tcp_recv_cb - parameter 'arg']]>
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:

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:

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

Statistics: Posted by Stational — Sun Sep 04, 2016 3:48 am


]]>