cancel
Showing results for 
Search instead for 
Did you mean: 

LWIP send data

zavodny
Associate II
Posted on March 18, 2014 at 20:08

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
18 REPLIES 18
zavodny
Associate II
Posted on March 19, 2014 at 08:40

Do you need to specify a port somewhere?

Where?

Should you expect a response from the Server?

How?

Should you be careful closing the connection?

How?

sevketkahya
Associate II
Posted on March 20, 2014 at 16:24

Hi, I want to implement LwIP stack to my discovery, but I couldn't find appropriate resources. Could you please upload your project or some resources that you have? Any guidance about this subject will be appreciated.

Best regards

Posted on March 20, 2014 at 16:43

\STM32F4x7_ETH_LwIP_V1.1.0\Project\FreeRTOS\httpserver_netconn

http://www.st.com/web/en/catalog/tools/PF257906

If you have an STM32F4-DIS-BB break-out board with Ethernet, there is source specifically available from EmBest/Element14 for that.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
zavodny
Associate II
Posted on March 31, 2014 at 12:53

Hi, I've next problem. I need getting data from web server. I have one web page with JSON. When I put address of this page to web browser, I get data in JSON format. 

Now I write script in PHP. I want get data from web page. When I show web page in web browser and then I read web page in my script, it's OK. But when I read data from web page in PHP script first, then page is not exist. But in web browser is OK still.

Can you help me please? 

zavodny
Associate II
Posted on March 31, 2014 at 17:11

Now is OK. I change name of file from teploty.json to teploty.php and it's OK. 

uhrincs
Associate
Posted on November 09, 2014 at 22:38

Hello I would like to make almost the same project as you. I would like to connect to my webserver with ''netconn_connect(conn, &remote_ip, 80 ); '' but nothing happened. I can not catch any packets with wireshark. If anybody can help or can send a web client example code I will be happy. Have stm32f4 discovery board with ethernet extension. 

Posted on November 10, 2014 at 01:11

Not sure I've seen an HTTP GET example, how much socket experience do you come at this with?

STM32F4x7_ETH_LwIP_V1.0.0\Project\Standalone\tcp_echo_client\src\tcp_echoclient.c

STM32F4DIS-BB Discover More Software Examples\STM32F4xx_Ethernet_Example\Project\Standalone\tcp_echo_client\src\tcp_echoclient.c

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
uhrincs
Associate
Posted on November 10, 2014 at 22:43

I start the work with tcp echo client. It is working! Many thanks.

sanjeevkmsinha
Associate
Posted on July 25, 2016 at 08:28

Hi,

I have also the same type requirement . I want to send the Data from microcontroller to a web page like :

http://www.xyzabc.com/getdata.php

 and post_data on this URL at a regular interval.

Thanks for Information.

Best Regards,

Sanjeev