Having trouble with creating TCP connection using the LwIP tcp_connect()

Hi,

Right now I’m trying to create a IoT device that will collect temperature sensor data and send this data to the cloud, where the cloud will be hosting an instance of a time series database (InfluxDB) that will store this sensor data periodically. I’m using EKH05 to implement this IoT device.

My setup right now is an EKH05, which periodically capture sensor data from the on-board module, an EKH01 that acts as an access point for my EKH05, and my local computer which is connected to the EKH01 via ethernet interface. My initial step towards accomplishing my goal is to create a simple TCP persistent connection between my EKH05 to EKH01 through the HaLoW link. To achieve this, I’m using the LwIP TCP api (lwip/tcp.h) that comes with the stm32 CMSIS package that is provided by Morse.

I’m having trouble with the initial three-way handshake step of establishing the TCP connection. I’m using tcp_connect() function to connect to the AP. My AP have a halow IP of 192.168.1.1 and my EKH05 is 192.168.1.224. I’m trying to connect to the AP on port 3222. Here is a snippet of the code that I written

void sensor_monitoring_task(void *args){
	printf("Sensor monitoring task started\n");

	// Checks that HaLoW link is up and connected to the AP
	bool linkup = false;
	while(!linkup){
		printf("Link is still down, sleeping for 5 seconds\n");
		mmosal_task_sleep(5000);
		if(mmipal_get_link_state() == MMIPAL_LINK_UP) linkup = true;
	}

	LOCK_TCPIP_CORE();

	uint16_t server_port = 3222;
	ip_addr_t ap;
	int ok = ipaddr_aton("192.168.1.1", &ap);
	if(!ok){
		printf("Failed to convert ip string to int data type");
	}

	// TCP Protocol Control Block (PCB) setup steps
	struct tcp_pcb *newpcb;
	newpcb = tcp_new_ip_type(IP_GET_TYPE(&ap));
	if(newpcb == NULL){
		printf("Failed to create TCP PCB\n");
	}

	// Setups for all the call back
	// sensor_tcp_sent_callback and sensor_tcp_poll just returns ERR_OK
	// sensor_tcp_err do TCP close clean up
	tcp_arg(newpcb, newpcb);
	tcp_sent(newpcb, sensor_tcp_sent_callback);
	tcp_poll(newpcb, sensor_tcp_poll, 2U);
	tcp_err(newpcb, sensor_tcp_err);

	// Steps to create TCP connection
	err_t err = tcp_connect(newpcb, &ap, server_port, sensor_tcp_client_connected);
    if (err != ERR_OK)
    {
        printf("Failed to do tcp_connect\n");
        tcp_close(newpcb);
    }else{
    	printf("TCP connection successfully created\n");
    }

	UNLOCK_TCPIP_CORE();
    while(1){

    }
}

From the above code, call to tcp_connect returns ERR_OK, but it suppose to call the callback function sensor_tcp_client_connected when the connection is made sucessfully, but this never happens and instead sensor_tcp_err is the one that keeps being invoked. I can definitely see the SYN packet for the first step of TCP connection establishment is being sent to the AP, and the AP sends back a SYN-ACK packets. But the final third step of the three-way handshake is not done by my EKH05. See the pic below.

Right now I’m stuck at making this works, and I would appreciate any insights on why this could be happening. My reference code is the tcp client for MMiperf. I have no problem with getting the UDP implementation working.

Fixed my problem, just need a TCP server listening on the other end