i get fatal exception or wdt overflow exception with this code below.
Actually it connects my local web page then it receives properly but after 10th or more run it crashes.
#include "esp_common.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "lwip/sockets.h"
#include "lwip/dns.h"
#include "lwip/netdb.h"
#include "uart.h"
#define server_ip "10.20.0.136"
#define server_port 80
void task2(void *pvParameters)
{
printf("Hello, welcome to client!\r\n");
while (1) {
int recbytes;
int sin_size;
int str_len;
int sta_socket;
struct sockaddr_in local_ip;
struct sockaddr_in remote_ip;
sta_socket = socket(PF_INET, SOCK_STREAM, 0);
if (-1 == sta_socket) {
close(sta_socket);
printf("C > socket fail!\n");
continue;
}
vTaskDelay(1000 / portTICK_RATE_MS);
//printf("C > socket ok!\n");
bzero(&remote_ip, sizeof(struct sockaddr_in));
remote_ip.sin_family = AF_INET;
remote_ip.sin_addr.s_addr = inet_addr(server_ip);
remote_ip.sin_port = htons(server_port);
if (0 != connect(sta_socket, (struct sockaddr *)(&remote_ip), sizeof(struct sockaddr))) {
close(sta_socket);
printf("C > connect fail!\n");
vTaskDelay(4000 / portTICK_RATE_MS);
continue;
}
//printf("C > connect ok!\n");
char *pbuf = (char *)zalloc(1024);
sprintf(pbuf, "%s\n", "GET http://10.20.0.136 HTTP/1.1\r\nHost: host:port\r\nConnection: close\r\n\r\n");
if (write(sta_socket, pbuf, strlen(pbuf) + 1) < 0) {
printf("C > send fail\n");
}
//printf("C > send success\n");
free(pbuf);
char *recv_buf = (char *)zalloc(128);
while ((recbytes = read(sta_socket , recv_buf, 128)) > 0) {
recv_buf[recbytes] = 0;
printf("%s\n",recv_buf);
}
free(recv_buf);
if (recbytes <= 0) {
close(sta_socket);
printf("C > read data fail!\n");
}
}
}
void user_init(void)
{
UART_SetBaudrate(UART0,BIT_RATE_115200);
printf("SDK version:%s\n", system_get_sdk_version());
/* need to set opmode before you set config */
wifi_set_opmode(STATION_MODE);
{
struct station_config *config = (struct station_config *)zalloc(sizeof(struct station_config));
sprintf(config->ssid, "Guest");
sprintf(config->password, "Geo256Cell");
/* need to sure that you are in station mode first,
* otherwise it will be failed. */
wifi_station_set_config(config);
free(config);
}
xTaskCreate(task2, "tsk2", 2048, NULL, 2, NULL);
}