---
title: "W5500 Http Client continuous data send"
url: "https://maker.wiznet.io/forum/15141"
markdown_url: "https://maker.wiznet.io/forum/15141/md"
type: "Forum topic"
category: "Ethernet Chips"
author: "mrkam"
created: "2024-02-05T08:27:04+09:00"
last_activity: "2024-02-05T08:51:50+09:00"
language: "en"
views: 164
replies: 1
source: "WIZnet Makers forum (https://maker.wiznet.io/forum/)"
---

# W5500 Http Client continuous data send

## Question

Asked by mrkam on 2024-02-05 in Ethernet Chips.

Hello,
I send data to the server with HTTP GET requests.
I want to send data periodically without closing the connection.

The procedure seems to be as follows:

1. Create a socket;

2. Open the connection;

3. Send data every 2 seconds.

However, when I send data one time, the socket state becomes SOCK_CLOSE_WAIT, and I can only send one more time.
After that, the socket state becomes SOCK_CLOSED, and I need to open the connection one more time.

What do I need to add to my code to keep the connection alive? I tried to perform the command `setSn_CR(sn, Sn_CR_SEND_KEEP)`, but it didn’t help.

In my program, I first run `httpInit()` and then periodically run `httpClientRun`.
Here is my code below:

```
void httpInit(void){	
	int8_t code;		
	
	code = socket(httpClientSocket, Sn_MR_TCP, port, 0); 
	code = connect(httpClientSocket, addr, 80);
	setSn_IR(httpClientSocket, Sn_IR_CON);
}
uint8_t httpSendData(char sensorID[], uint16_t co2Val, uint16_t pm25Val, float tempVal, float humidityVal){
	int32_t nbytesRSV;		
	uint16_t len;	
		
	socketState = getSn_SR(httpClientSocket);	
	if((socketState == SOCK_ESTABLISHED)||(socketState == SOCK_CLOSE_WAIT)){
		len = sprintf(request, "GET /api/sensor/update?id=%s&co2=%u&pm25=%u&temp=%.2f&humidity=%.2f HTTP/1.0\r\nHost: myserver.com\r\n\r\n",
										sensorID, co2Val, pm25Val, tempVal, humidityVal);		
		while(len > 0){
				int32_t nbytes = send(httpClientSocket, (uint8_t*)&request, len);				
				if(nbytes<0) return 1;							
				len -= nbytes;
		}	
	}
	else return 1;
	return 0;
}
uint8_t reconnectCounter;
void httpClientRun(char sensorID[], uint16_t co2Val, uint16_t pm25Val, float tempVal, float humidityVal)
{
	if(httpSendData(sensorID, co2Val, pm25Val, tempVal, humidityVal)){
		reconnectCounter++;				
		if(4 <= reconnectCounter){
			sockClose++;
			httpInit();		
			reconnectCounter = 0;
		}
	}		
}
```

## Replies

### Reply 1 by Eugeny, 2024-02-05

HTTP GET is designed to get data from the server, not to put it into there. In your case I do not see any explicit close socket/connection from the W5500 side, thus this is the server closing the connection. SOCK_CLOSE_WAIT confirms it - server has sent FIN to W5500 and does not want to communicate any more. You must set up the server to receive multiple HTTP request other same channel or change the transport protocol completely.

---

Source: https://maker.wiznet.io/forum/15141
