I have a problem with connecting the client to the server, at ESP32-DevKit.
A single connection is no problem, but when I make a query after the query, the client can not connect after seven successful connections. Powtarza się to zawsze na tej samej próbie.
Does anyone know what could be the reason?
Server code:
Code: Select all
static void http_server(void *pvParameters)
{
struct netconn *conn, *newconn;
err_t err;
conn = netconn_new(NETCONN_TCP);
netconn_bind(conn, NULL, 80);
netconn_listen(conn);
printf("HTTP Server listening...\n");
do
{
err = netconn_accept(conn, &newconn); //< funkcja zatrzymuje petle do momentu wystapienia polaczenia do serwera
netconn_set_nonblocking(conn, 1);
if (err == ERR_OK)
{
http_server_netconn_serve(newconn);
newconn = NULL;
}
else
{
ESP_LOGI("blad: ", "netcon accept");
}
vTaskDelay(1); //allows task to be pre-empted
} while (err == ERR_OK);
netconn_close(conn);
netconn_delete(conn);
//printf("\n");
}
static void http_server_netconn_serve(struct netconn *conn)
{
struct netbuf *inbuf;
char *buf;
u16_t buflen;
err_t err;
bufferService.bufferSize = 0;
err = netconn_recv(conn, &inbuf);
if (err == ERR_OK)
{
netbuf_data(inbuf, (void **)&buf, &buflen);
// extract the first line, with the request
char *first_line = strtok(buf, "\n"); // pobranie z bufora ramki i trybu
if (first_line)
{
if (strstr(first_line, "turnOn"))
{
sendFrameOn = 1;
//setFlagValueChange(17);
//*(uint32_t *)getParamAddressDynamicDP(17)=3;
netconn_write(conn, OPENSSL_EXAMPLE_SERVER_ACK_Modify, sizeof(OPENSSL_EXAMPLE_SERVER_ACK_Modify) - 1, NETCONN_NOCOPY);
}
else if (strstr(first_line, "turnOff"))
{
sendFramOff = 1;
netconn_write(conn, OPENSSL_EXAMPLE_SERVER_ACK_Modify, sizeof(OPENSSL_EXAMPLE_SERVER_ACK_Modify) - 1, NETCONN_NOCOPY);
}
else if (strstr(first_line, "frameController"))
{
sendReciveToServerFromController(conn, first_line);
}
else if (strstr(first_line, "frameModel"))
{
sendReciveToServerFromDevice2(conn, first_line);
}
else if (strstr(first_line, ServerSearchComend))
{
serverConfirmation(conn, first_line);
}
else
{
netconn_write(conn, OPENSSL_EXAMPLE_SERVER_ACK, sizeof(OPENSSL_EXAMPLE_SERVER_ACK) - 1, NETCONN_NOCOPY);
int size = 0;
char bufferTemp[300];
size = sprintf(bufferTemp, "<p>Temp. czerpni: <b>%4.1f C</b></p> <p>Temp. wyrzutni: <b>%4.1f C</b></p> <p>Temperatura nawiewu: <b>%4.1f C</b></p> <p>Temperatura wyci�gu: <b>%4.1f C</b></p> ", *(float *)getParamAddressDynamicDP(40), *(float *)getParamAddressDynamicDP(37), *(float *)getParamAddressDynamicDP(34), *(float *)getParamAddressDynamicDP(36));
netconn_write(conn, bufferTemp, size - 1, NETCONN_NOCOPY);
///size=sprintf(bufferTemp," <p>wolny ram: <b>%d C</b></p> <p>ramki wyslane: <b>%d C</b></p> <p>ramki odebrane: <b>%d C</b></p> ", esp_get_free_heap_size(), frameSendCounter , frameReceivedCounter);
// netconn_write(conn, bufferTemp, size-1, NETCONN_NOCOPY);
netconn_write(conn, OPENSSL_EXAMPLE_SERVER_ACK2, sizeof(OPENSSL_EXAMPLE_SERVER_ACK2) - 1, NETCONN_NOCOPY);
}
}
else
ESP_LOGI("Nieznane zapytanie serwera", " brak wykonania funkcji");
}
// close the connection and free the buffer
netconn_close(conn);
netconn_delete(conn);
netbuf_delete(inbuf);
}
Code: Select all
void socketSender(gazModem_struct *gmObject)
{
static uint8_t ilerazy = 0;
if (sendFlagCounter == 10)
{
sendFlagCounter = 0;
sendFlag = 0;
}
ESP_LOGI("isNotPossibleToSend", "%d", sendFlag);
sendFlagCounter++;
if (gmObject->receiverBuffer->currentWritePosition > 10 && sendFlag == 0) //sprawdza czy cos odebrano od uart
{
sendFlagCounter = 0;
char dataFromUart[100]; //tablica ramki odebranej od uart w char
fillArrayDataFromReceiver(gmObject, dataFromUart); // pobranie ramki gm i zapisanie jej do tablicy
ESP_LOGI(TAG, "SERVER SEND: %s", dataFromUart); //wyswietlenie odebranej ramki z uart
resetBufferCounters(gmObject->receiverBuffer); //reset buffera odpowiedzialnego za odbieranie od uart
resetBufferCounters(gmObject->transmitBuffer); // reset buffera odpowiedzialnego za wysylanie na uart
char targetName[255]; // tresc pytania serwera o ramke
targetName[0] = '\0';
strcat(targetName, LINK);
strcat(targetName, dataFromUart);
strcat(targetName, " HTTP/1.1\n\n");
int sockfd = connectSocketToServer(targetName); //tworzy polaczenie z serwerem i pobiera od niego dane
if (sockfd == -1)
{
ESP_LOGI("Blad polaczenia z serwerem ", "funkcja SOCKED SENDER");
ilerazy = 0;
}
else
{
sendFlag = 1; // ustawienie flagi odpowiedzialnej za wysylani na uarcie
receiveDataFromServer(gmObject, sockfd); //odbiera dane z serwera i wysyla na uart
ilerazy++;
ESP_LOGI("udalo sie polaczyc razy: ", "%d", ilerazy);
}
close(sockfd); // zamkniecie socket
shutdown(sockfd, 2); // zamkniecie po obu stronach
sockfd = -1;
}
}