Hello. I need a create a client TCP in my board to connect with my computer. I programed the code, I would expected see the TCP packets in my Wireshark, but this don´t happened.
I don't know why i don't see any TCP packet. I only see a ARP packet, from my board that i expected.
I would greatly appreciate any help you can give me.
Code:
/* USER CODE BEGIN (0) */
#include "FreeRTOS.h"
#include "os_task.h"
/* USER CODE END */
/* Include Files */
#include "sys_common.h"
#include "system.h"
#include "lwip/ip_addr.h"
#include "lwip/tcp.h"
#include <string.h>
#include "cJSON.h"
#include <stdio.h>
#include <stdlib.h>
#include "stdio.h"
/************************************************************************************************/
extern void EMAC_LwIP_Main (uint8_t * emacAddress);
/*Defining global variables */
uint8 emacAddress[6U] = {0x00U, 0x08U, 0xEEU, 0x03U, 0xA6U, 0x6CU};
uint32 emacPhyAddress = 1U;
ip_addr_t Src, Dst, netmask, gw;
struct tcp_pcb * pcb;
err_t errorb, errorc, errorw, erroro, errorr, error;
uint16_t length = 275;
struct pbuf *Tx;
char *string = "TCP LwIP Example";
char mydata[400]; // Incoming data
int i = 0;
// ************************************************************************************************/
uint32_t tcp_send_packet(void);
void tcpErrorHandler(void *arg, err_t err);
err_t tcpSendCallback(void *arg, struct tcp_pcb *tpcb,u16_t len);
err_t connectCallback(void *arg, struct tcp_pcb *tpcb, err_t err);
struct tcp_pcb *testpcb;
// ************************************************************************************************/
/*Callbacks fuctions */
void tcpErrorHandler(void *arg, err_t err){
}
err_t tcpSendCallback(void *arg, struct tcp_pcb *tpcb,u16_t len)
{
}
err_t connectCallback(void *arg, struct tcp_pcb *tpcb, err_t err)
{
tcp_send_packet();
return 0;
}
// ************************************************************************************************/
// Funcion delay en segundos
void delay (float time)
{
int long c, x_time = (int long) (1.36e7 * time);
for (c=0; c <= 2 * x_time; c++){
}
}
// ************************************************************************************************/
/*Header */
uint32_t tcp_send_packet(void)
{
char *string = "SetR=01\r";
uint32_t len = strlen(string);
/* push to buffer */
errorw = tcp_write(testpcb, string, strlen(string), TCP_WRITE_FLAG_COPY);
/* now send */
tcp_output(testpcb);
return 0;
}
void lwip_init();
// ************************************************************************************************/
/*Main fuction */
int main(void)
{
EMAC_LwIP_Main(emacAddress);
/* Initialize system */
//SystemInit();
lwip_init(); //Initialize the lwIP stack and all of its subsystems.
while(1)
{
// tcp_setup();
uint32_t data = 0xdeadbeef;
/* create an ip */
struct ip_addr ip, src;
IP4_ADDR(&ip, 20, 0, 168, 192);
IP4_ADDR(&src, 1, 0, 168, 192);
testpcb = tcp_new(); //testpcb is a global struct tcp_pcb
// as defined by lwIP
/* dummy data to pass to callbacks*/
errorb = tcp_bind(pcb, &src,5001);
tcp_arg(testpcb, &data);
/* register callbacks with the pcb */
// tcp_recv(testpcb, tcpRecvCallback);
tcp_sent(testpcb, NULL); // tcpSendCallback
// tcp_err(testpcb, tcpErrorHandler);
/* now connect */
errorc = tcp_connect(testpcb, &ip, 139, connectCallback);
}
}