2014-03-18 12:08 PM
Hi,
I use LWIP and FreeRTOS like WEB server. It's OK. But now, I want send data to otger page for example by GET. Like this: http://www.page.com/p.php?json=1234 Can you help me please? Here is my code:
portCHAR PAGE_BODY[512];
struct
netconn *conn1 = NULL;
struct
ip_addr local_ip;
struct
ip_addr remote_ip;
int
rc1, rc2;
strcat
((
char
*) PAGE_BODY,
''HTTP/1.0 ''
);
strcat
((
char
*) PAGE_BODY,
''Method: POST\r\n''
);
strcat
((
char
*) PAGE_BODY,
''Server: Ethernet termostat\r\n''
);
strcat
((
char
*) PAGE_BODY,
''Content-Length: 9\r\n''
);
strcat
((
char
*) PAGE_BODY,
''json=1234\r\n\r\n''
);
strcat
((
char
*) PAGE_BODY,
''Content-type: application/x-www-form-urlencoded\n\n''
);
/* Create a new TCP connection handle */
conn1 = netconn_new(NETCONN_TCP);
if
(conn1!= NULL)
{
local_ip.addr = NULL;
rc1 = netconn_bind ( conn1, &local_ip, 0 );
IP4_ADDR(&remote_ip, 46, 28, 105, 62);
//remote_ip.addr = remote_ip; // static or by netconn_gethostbyname ()
rc2 = netconn_connect ( conn1, &remote_ip, 80 );
if
( rc1 != ERR_OK || rc2 != ERR_OK )
{
netconn_write(conn1, PAGE_BODY,
strlen
(PAGE_BODY), NETCONN_COPY);
netconn_delete ( conn1 );
}
}
else
{
printf
(
''can not create netconn''
);
}
#lmgtfy:-stm32-resources #send-data-frm-stm32-to-webserver
2014-03-18 12:42 PM
Likely not the issue here, but you really should ensure the string space is NUL terminated before using strcat(), ideally the first should be strcpy(). And the double LF/CR terminating the request should surely be at the end, followed by ''Content-Length'' of actual data.
2014-03-18 12:55 PM
Thanks, but this code has stopped at line 17. And I don't know why? This row is OK, when I using web server.
2014-03-18 01:18 PM
Now, all is OK. But data is not received in page. Where is mistake?
2014-03-18 01:34 PM
Now I try this:
struct
netconn *conn1 = NULL;
struct
ip_addr local_ip;
struct
ip_addr remote_ip;
int
rc1, rc2;
/* Create a new TCP connection handle */
conn1 = netconn_new(NETCONN_TCP);
if
(conn1!= NULL)
{
local_ip.addr = NULL;
rc1 = netconn_bind ( conn1, NULL, 0 );
IP4_ADDR(&remote_ip, 46, 28, 105, 62);
//remote_ip.addr = remote_ip; // static or by netconn_gethostbyname ()
rc2 = netconn_connect ( conn1, &remote_ip, 80 );
if
( rc1 != ERR_OK || rc2 != ERR_OK )
{
netconn_write(conn1,
''POST /save_data.php HTTP/1.0 Method: POST
Server: Ethernet termostat
Content-Length: 9
Content-type: application/x-www-form-urlencoded
json=1234
''
, 152, NETCONN_COPY);
netconn_delete ( conn1 );
}
}
It's working, but the web page isn't receive POST and nothing do.
2014-03-18 02:03 PM
static const char out[] = ''POST /save_data.php HTTP/1.0
Server: Ethernet Thermostat
Content-Length: 9
Content-Type: application/x-www-form-urlencoded
json=1234'';
netconn_write(conn1, out, sizeof(out)-1, NETCONN_COPY);
2014-03-18 02:17 PM
I try it and nothing. And sometimes at line 16 returns error.
2014-03-18 03:09 PM
And what about IP address? I have web page on address termostat.vzap.eu/post.php and if I translate to IP address, then is 46.28.105.62. But if I write this IP address to web browser, then server return error. How I set netconn for this problem?
2014-03-18 05:00 PM
Now I analyze packets in wireshark. If I apply this command: netconn_connect ( conn1, &remote_ip, 80 ); Wireshark receive TCP packet. Then receive next, and next same named TCP Retransmission. Where is problem? Why PC don't send ACK?
2014-03-18 05:41 PM
I'm not a big LwIP fan, I'm more of a Berkeley Sockets guy.
Do you need to specify a port somewhere? Should you expect a response from the Server? Should you be careful closing the connection?