Attachments are accessible only for community members.
Nov 14, 2019
03:25 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Nov 14, 2019
03:25 AM
Hey,
I'm searching for an LwIP TCP client (prefered without RTOS) example.
Attached is my LwIP TCP Client code or project *.zip for an XMC4800. Maybe that helps somone, or sonone could help me with this code.
#include //Declarations from DAVE Code Generation (includes SFR declaration)
//#include "tcpecho_raw.h"
#include
#include "ETH_LWIP/lwip/include/lwip/api.h"
#include "ETH_LWIP/lwip/include/lwip/def.h"
#include "ETH_LWIP/lwip/include/lwip/mem.h"
#include "ETH_LWIP/lwip/include/lwip/memp.h"
#include "ETH_LWIP/lwip/include/lwip/tcp.h"
#include "ETH_LWIP/lwip/include/lwip/tcpip.h"
#include "ETH_LWIP/lwip/include/lwip/udp.h"
#include "ETH_LWIP/lwip/include/lwip/etharp.h"
#include "ETH_LWIP/lwip/include/lwip/dhcp.h"
#include "ETH_LWIP/lwip/include/lwip/sockets.h"
#include "ETH_LWIP/lwip/include/lwip/netdb.h"
#include "ETH_LWIP/lwip/include/lwip/opt.h"
#include "ETH_LWIP/lwip/include/lwip/priv/tcp_priv.h"
#include "ETH_LWIP/lwip/include/lwip/debug.h"
#include "ETH_LWIP/lwip/include/lwip/stats.h"
#include "ETH_LWIP/lwip/include/lwip/ip.h"
#include "ETH_LWIP/lwip/include/lwip/ip4.h"
#include "ETH_LWIP/lwip/include/lwip/ip4_addr.h"
#include "ETH_LWIP/lwip/include/lwip/ip6.h"
#include "ETH_LWIP/lwip/include/lwip/ip6_addr.h"
#include "ETH_LWIP/lwip/include/lwip/nd6.h"
// Functions
void netif_status_cb(struct netif *netif);
void client_write();
void DelayMicroSeconds(uint32_t);
void DelayMilliSeconds(uint32_t);
int main(void)
{
DAVE_STATUS_t status;
status = DAVE_Init(); /* Initialization of DAVE APPs */
if(status != DAVE_STATUS_SUCCESS)
{
/* Placeholder for error handler code. The while loop below can be replaced with an user error handler. */
XMC_DEBUG("DAVE APPs initialization failed\n");
while(1U)
{
}
}
/* Placeholder for user application code. The while loop below can be replaced with user application code. */
while(1U)
{
sys_check_timeouts();
DelayMilliSeconds(1000);
client_write();
}
}
void netif_status_cb(struct netif *netif)
{
XMC_UNUSED_ARG(netif);
netif_set_up(netif);
while(0 == netif_is_up(netif))
{
DelayMicroSeconds(250);
}
DIGITAL_IO_SetOutputLow(Ð_Enable);
}
void DelayMicroSeconds(uint32_t delay_val)
{
// !!! Attention should be paid to the flanks ascent and descent (IO pins) !!!
// Converts micro seconds to milli seconds with multiplication factor for TIMER_GetInterruptStatus().
uint32_t delay_cnt = delay_val * 100U;
TIMER_SetTimeInterval(&TIMER_0, delay_cnt);
TIMER_Start(&TIMER_0);
while(!TIMER_GetInterruptStatus(&TIMER_0));
TIMER_Stop(&TIMER_0);
TIMER_ClearEvent(&TIMER_0);
}
void DelayMilliSeconds(uint32_t delay_val)
{
// Converts micro seconds to milli seconds with multiplication factor for TIMER_GetInterruptStatus().
uint32_t delay_cnt = delay_val * 100000U;
TIMER_SetTimeInterval(&TIMER_0, delay_cnt);
TIMER_Start(&TIMER_0);
while(!TIMER_GetInterruptStatus(&TIMER_0));
TIMER_Stop(&TIMER_0);
TIMER_ClearEvent(&TIMER_0);
}
static err_t close_con(void *arg, struct tcp_pcb *pcb, u16_t len)
{
tcp_arg(pcb, NULL);
tcp_sent(pcb, NULL);
tcp_close(pcb);
return ERR_OK;
}
void client_write(void)
{
struct tcp_pcb *pcb;
ip_addr_t server;
err_t ret_val;
int bufspace = 0;
struct pbuf *pb;
char *string = "TCP LwIP Example without RTOS!\r\n";
pb = pbuf_alloc(PBUF_TRANSPORT, 0, PBUF_REF);
pb->payload = string;
pb->len = pb->tot_len = strlen(string);
IP4_ADDR(&server, 192,168,114,89);
pcb = tcp_new(); // create tcp pcb
tcp_bind(pcb, IP_ADDR_ANY, 8); //bind client port for outgoing connection
//tcp_arg(pcb, NULL);
ret_val = tcp_connect(pcb, &server, 7, NULL); //connect to the server
if (ret_val != ERR_OK)
{
// printf("\r\n Error: %d\n", ret_val);
}
else
{
// printf("\r\n Connect ok [%d]", ret_val);
bufspace = tcp_sndbuf(pcb); // get space which can be used to sent the data
if (bufspace)
{
do
{
tcp_write(pcb, pb->payload,pb->len, 0);
// printf("\r\nRet val: %d", ret_val);
} while (ret_val == ERR_MEM);
tcp_output(pcb);
tcp_sent(pcb, close_con);
}
// tcp_close(pcb);
}
pbuf_free(pb);
}
Thank you very much
Best regards
Patrick
I'm searching for an LwIP TCP client (prefered without RTOS) example.
Attached is my LwIP TCP Client code or project *.zip for an XMC4800. Maybe that helps somone, or sonone could help me with this code.
#include
//#include "tcpecho_raw.h"
#include
#include "ETH_LWIP/lwip/include/lwip/api.h"
#include "ETH_LWIP/lwip/include/lwip/def.h"
#include "ETH_LWIP/lwip/include/lwip/mem.h"
#include "ETH_LWIP/lwip/include/lwip/memp.h"
#include "ETH_LWIP/lwip/include/lwip/tcp.h"
#include "ETH_LWIP/lwip/include/lwip/tcpip.h"
#include "ETH_LWIP/lwip/include/lwip/udp.h"
#include "ETH_LWIP/lwip/include/lwip/etharp.h"
#include "ETH_LWIP/lwip/include/lwip/dhcp.h"
#include "ETH_LWIP/lwip/include/lwip/sockets.h"
#include "ETH_LWIP/lwip/include/lwip/netdb.h"
#include "ETH_LWIP/lwip/include/lwip/opt.h"
#include "ETH_LWIP/lwip/include/lwip/priv/tcp_priv.h"
#include "ETH_LWIP/lwip/include/lwip/debug.h"
#include "ETH_LWIP/lwip/include/lwip/stats.h"
#include "ETH_LWIP/lwip/include/lwip/ip.h"
#include "ETH_LWIP/lwip/include/lwip/ip4.h"
#include "ETH_LWIP/lwip/include/lwip/ip4_addr.h"
#include "ETH_LWIP/lwip/include/lwip/ip6.h"
#include "ETH_LWIP/lwip/include/lwip/ip6_addr.h"
#include "ETH_LWIP/lwip/include/lwip/nd6.h"
// Functions
void netif_status_cb(struct netif *netif);
void client_write();
void DelayMicroSeconds(uint32_t);
void DelayMilliSeconds(uint32_t);
int main(void)
{
DAVE_STATUS_t status;
status = DAVE_Init(); /* Initialization of DAVE APPs */
if(status != DAVE_STATUS_SUCCESS)
{
/* Placeholder for error handler code. The while loop below can be replaced with an user error handler. */
XMC_DEBUG("DAVE APPs initialization failed\n");
while(1U)
{
}
}
/* Placeholder for user application code. The while loop below can be replaced with user application code. */
while(1U)
{
sys_check_timeouts();
DelayMilliSeconds(1000);
client_write();
}
}
void netif_status_cb(struct netif *netif)
{
XMC_UNUSED_ARG(netif);
netif_set_up(netif);
while(0 == netif_is_up(netif))
{
DelayMicroSeconds(250);
}
DIGITAL_IO_SetOutputLow(Ð_Enable);
}
void DelayMicroSeconds(uint32_t delay_val)
{
// !!! Attention should be paid to the flanks ascent and descent (IO pins) !!!
// Converts micro seconds to milli seconds with multiplication factor for TIMER_GetInterruptStatus().
uint32_t delay_cnt = delay_val * 100U;
TIMER_SetTimeInterval(&TIMER_0, delay_cnt);
TIMER_Start(&TIMER_0);
while(!TIMER_GetInterruptStatus(&TIMER_0));
TIMER_Stop(&TIMER_0);
TIMER_ClearEvent(&TIMER_0);
}
void DelayMilliSeconds(uint32_t delay_val)
{
// Converts micro seconds to milli seconds with multiplication factor for TIMER_GetInterruptStatus().
uint32_t delay_cnt = delay_val * 100000U;
TIMER_SetTimeInterval(&TIMER_0, delay_cnt);
TIMER_Start(&TIMER_0);
while(!TIMER_GetInterruptStatus(&TIMER_0));
TIMER_Stop(&TIMER_0);
TIMER_ClearEvent(&TIMER_0);
}
static err_t close_con(void *arg, struct tcp_pcb *pcb, u16_t len)
{
tcp_arg(pcb, NULL);
tcp_sent(pcb, NULL);
tcp_close(pcb);
return ERR_OK;
}
void client_write(void)
{
struct tcp_pcb *pcb;
ip_addr_t server;
err_t ret_val;
int bufspace = 0;
struct pbuf *pb;
char *string = "TCP LwIP Example without RTOS!\r\n";
pb = pbuf_alloc(PBUF_TRANSPORT, 0, PBUF_REF);
pb->payload = string;
pb->len = pb->tot_len = strlen(string);
IP4_ADDR(&server, 192,168,114,89);
pcb = tcp_new(); // create tcp pcb
tcp_bind(pcb, IP_ADDR_ANY, 8); //bind client port for outgoing connection
//tcp_arg(pcb, NULL);
ret_val = tcp_connect(pcb, &server, 7, NULL); //connect to the server
if (ret_val != ERR_OK)
{
// printf("\r\n Error: %d\n", ret_val);
}
else
{
// printf("\r\n Connect ok [%d]", ret_val);
bufspace = tcp_sndbuf(pcb); // get space which can be used to sent the data
if (bufspace)
{
do
{
tcp_write(pcb, pb->payload,pb->len, 0);
// printf("\r\nRet val: %d", ret_val);
} while (ret_val == ERR_MEM);
tcp_output(pcb);
tcp_sent(pcb, close_con);
}
// tcp_close(pcb);
}
pbuf_free(pb);
}
Thank you very much
Best regards
Patrick
2 Replies
Nov 19, 2019
05:19 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Nov 19, 2019
05:19 AM
Hi,
In the src\apps\http folder of the lwip distribution you find an example for a http client.
Regards,
Jesus
In the src\apps\http folder of the lwip distribution you find an example for a http client.
Regards,
Jesus
Attachments are accessible only for community members.
Jun 18, 2021
05:49 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Jun 18, 2021
05:49 AM
Hey,
I am trying to implement a TCP client on the XMC4800 as well. This client should be able to send individual messages to a Server and to receive the response messages. Unfortunately I can't find the example of the lwip distribution.
For the beginning, I worked with the "IOT_EXAMPLE_XMC47" and implemented this example for a XMC4800. Also, I removed some functions which I don't need for the communication. I have this source code so far:
I use Wireshark to analyze the network communication between the XMC and my PC. But the TCP connection always resets and I don't know why. Probably because I just have one message to send?
I also tried to connect the XMC with Putty (RAW Connection type), but that doesn't work either. Besides, I do get a ping response form the XMC.*
Thank you for your help!
Regards,
Maxi
nd I can't implement a working connection.
Does anybody has an idea how to implement the client with Dave?
I am trying to implement a TCP client on the XMC4800 as well. This client should be able to send individual messages to a Server and to receive the response messages. Unfortunately I can't find the example of the lwip distribution.
For the beginning, I worked with the "IOT_EXAMPLE_XMC47" and implemented this example for a XMC4800. Also, I removed some functions which I don't need for the communication. I have this source code so far:
I use Wireshark to analyze the network communication between the XMC and my PC. But the TCP connection always resets and I don't know why. Probably because I just have one message to send?
I also tried to connect the XMC with Putty (RAW Connection type), but that doesn't work either. Besides, I do get a ping response form the XMC.*
Thank you for your help!
Regards,
Maxi
nd I can't implement a working connection.
Does anybody has an idea how to implement the client with Dave?