ESP32-S3 SIM7670G-4G-EN - esp_http_client_init, called Guru Meditation Error: Core 1 panic'ed

I’m programming esp32 s3 using platformio.
My board: ESP32-S3 SIM7670G-4G-EN
framework: Arduino.
I am start Wi-Fi and connect to the access point. Then I try to initiate http via the esp_http_client_init function. My controller gets an error and reboots.

My platformini file:

[env:esp32-s3-R2N16R8_PSRAM]
platform = espressif32
board = esp32-s3-R2N16R8_PSRAM
framework = arduino
board_build.f_cpu = 240000000L
monitor_speed = 115200
upload_port = COM7
monitor_port = COM7
board_build.mcu = esp32s3
upload_protocol = esptool

My code for init http:

esp_http_client_handle_t client_http;
esp_http_client_config_t htpp_cnf;

htpp_cnf.url = "http://httpbin.org/redirect/2";
htpp_cnf.method = HTTP_METHOD_GET;
htpp_cnf.event_handler = _http_event_handler;

ESP_LOGE(TAG,"Start init http");

client_http = esp_http_client_init (&htpp_cnf);
if(client_http != NULL) ESP_LOGE(TAG,"http create client OK"); 
else ESP_LOGE(TAG,"http client create FAILED");


void FnTest_httpRequst(void)
{
 ESP_LOGE(TAG, "Http request");
     esp_err_t err = esp_http_client_perform(client_http);
    if (err == ESP_OK) 
        {
        ESP_LOGE(TAG, "HTTP GET Status = %d, content_length = %d",
         esp_http_client_get_status_code(client_http),
         esp_http_client_get_content_length(client_http));
    } 
    else {
        ESP_LOGE(TAG, "HTTP GET request failed: %s", esp_err_to_name(err));
        }
}

After call function : "esp_http_client_init (&htpp_cnf); "
I get an error and the controller reboots. I tried other esp32-s3 boards, and I also tried using the Espressiv extension in VsCode, the result was the same.

The error is as follows:

Guru Meditation Error: Core  1 panic'ed (LoadProhibited). Exception was unhandled.

Core  1 register dump:
PC      : 0x40056f8c  PS      : 0x00060c30  A0      : 0x8202bc3c  A1      : 0x3fcebe10  
A2      : 0x3fcf5268  A3      : 0x00000004  A4      : 0x00000006  A5      : 0x3fcf5268
A6      : 0x00ff0000  A7      : 0x00000000  A8      : 0x00000000  A9      : 0x3fcebde0  
A10     : 0x3fcf5268  A11     : 0x00000000  A12     : 0x00000006  A13     : 0x00000006
A14     : 0x3c0a2c4d  A15     : 0x3fcea100  SAR     : 0x0000001a  EXCCAUSE: 0x0000001c  
EXCVADDR: 0x00000004  LBEG    : 0x40056f5c  LEND    : 0x40056f72  LCOUNT  : 0xffffffff


Backtrace: 0x40056f89:0x3fcebe10 0x4202bc39:0x3fcebe20 0x4202c235:0x3fcebe50 0x4200590a:0x3fcebe90 0x42005ae9:0x3fcebf40 0x4200755e:0x3fcebf80

Please help me, I don’t understand what the problem is.

If you use the Arduino Framework, you should also make use of its features.
Use WiFi and HTTPClient!

See Example: HTTP Get Request - Wokwi ESP32, STM32, Arduino Simulator

Indeed, your example works, thank you!
But the problem is that even if I use only IDF framework, the error is the same.
I would prefer to use only IDF framework, from Arduino framework I need only web server library, other functions I write in IDF.

Ok. I was wondering about the esp-idf calls in a pure Arduino Framework environment.

If you want to go the esp-idf way, you should compare your code to the provided example esp-idf/examples/protocols/http_request/main/http_request_example_main.c at master · espressif/esp-idf · GitHub

Ok, I’ll do as you said, a little later and answer you.

But I want to ask you, what if I use the example for the HTTP client: esp-idf/examples/protocols/esp_http_client/main/esp_http_client_example.c at master · espressif/esp-idf · GitHub

Is there a difference?

I don’t know.
I am not that familiar with the esp-idf.
I live in the Arduino world :wink:

1 Like

I tried the code you suggested. Here is my code and result.

/*  WiFi softAP Example

   This example code is in the Public Domain (or CC0 licensed, at your option.)

   Unless required by applicable law or agreed to in writing, this
   software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
   CONDITIONS OF ANY KIND, either express or implied.
*/
#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_mac.h"
#include "esp_wifi.h"
#include "esp_event.h"
#include "esp_log.h"
#include "nvs_flash.h"
#include "esp_system.h"
#include "lwip/err.h"
#include "lwip/sys.h"




#include "lwip/sockets.h"
#include "lwip/netdb.h"
#include "lwip/dns.h"

/* The examples use WiFi configuration that you can set via project configuration menu.

   If you'd rather not, just change the below entries to strings with
   the config you want - ie #define EXAMPLE_WIFI_SSID "mywifissid"
*/

#define F_SET 1
#define F_RES 0


const char* WIFI_SSID    = "Wokwi-GUEST";
const char* WIFI_PASS    = "11111111";

static const char *TAG = "wifi_AP";

 void http_get_task (void *pvParameters);
unsigned char F_WIFI_CONNECT;


static void wifi_event_handler(void* arg, esp_event_base_t event_base,
                                    int32_t event_id, void* event_data)
{
    wifi_event_sta_connected_t *event_stacon ;
wifi_event_sta_disconnected_t *event_stadis;
ip_event_got_ip_t  *ip_sta;
wifi_event_ap_staconnected_t *event_apcon;
wifi_event_ap_stadisconnected_t *event_apdiscon;

   if(event_base == WIFI_EVENT)
{
    switch (event_id)
    {
    case WIFI_EVENT_STA_START: //2
         ESP_LOGE(TAG,"WIFI_HNDR:[WIFI_EVENT_STA_START]");   
          esp_wifi_connect();     
        break;

    case WIFI_EVENT_STA_CONNECTED://4
         ESP_LOGE(TAG,"WIFI_HNDR:[WIFI_EVENT_STA_CONNECTED]");
         event_stacon = (wifi_event_sta_connected_t*) event_data;
         ESP_LOGE(TAG,"STA_CONNECTED-SSID[%s]",event_stacon->ssid);         
        break;
    
    case WIFI_EVENT_STA_DISCONNECTED://5
         ESP_LOGE(TAG,"WIFI_HNDR:[WIFI_EVENT_STA_DISCONNECTED]");
         event_stadis = ( wifi_event_sta_disconnected_t*)event_data;
         ESP_LOGE(TAG, "STA_DISON_SSID:[%s]",event_stadis->ssid);      
           esp_wifi_connect();    
         break;

    case WIFI_EVENT_STA_STOP://3
         ESP_LOGE(TAG,"WIFI_HNDR:[WIFI_EVENT_STA_STOP]");
         break;

  
    case WIFI_EVENT_AP_START: //12
        ESP_LOGE(TAG,"WIFI_HNDR:[WIFI_EVENT_AP_START]");
         break;

    case WIFI_EVENT_AP_STOP://13
     ESP_LOGE(TAG,"WIFI_HNDR:[WIFI_EVENT_AP_STOP]");
         break;

    case WIFI_EVENT_AP_STACONNECTED: //14
        ESP_LOGE(TAG,"WIFI_HNDR:[WIFI_EVENT_AP_STACONNECTED]");
         event_apcon = (wifi_event_ap_staconnected_t*)event_data;
         ESP_LOGE(TAG, "AP_CON -station_MAC:["MACSTR"] , AID=%d",MAC2STR(event_apcon->mac), event_apcon->aid);
 
    break;

    case WIFI_EVENT_AP_STADISCONNECTED: //15
        ESP_LOGE(TAG,"WIFI_HNDR:[WIFI_EVENT_AP_STADISCONNECTED]");
        event_apdiscon = (wifi_event_ap_stadisconnected_t*)event_data;
        ESP_LOGE(TAG, "station "MACSTR" leave, AID=%d", MAC2STR(event_apdiscon->mac), event_apdiscon->aid);
        break;
  
   default: break;
    }

} //END_WIFi_EVENT

if(event_base == IP_EVENT)
    {
    switch (event_id)
        {
        case IP_EVENT_STA_GOT_IP ://0
        ESP_LOGE(TAG,"WIFI_HNDR:[IP_EVENT_STA_GOT_IP]");
        ip_sta = (ip_event_got_ip_t*)event_data;
    
        ESP_LOGE(TAG, "ETHIP:" IPSTR, IP2STR(&ip_sta->ip_info.ip));
        ESP_LOGE(TAG, "ETHMASK:" IPSTR, IP2STR(&ip_sta->ip_info.netmask));
        ESP_LOGE(TAG, "ETHGW:" IPSTR, IP2STR(&ip_sta->ip_info.gw));     
        F_WIFI_CONNECT = F_SET;
        break;

        case IP_EVENT_STA_LOST_IP://1
        ESP_LOGE(TAG,"WIFI_HNDR:[IP_EVENT_STA_LOST_IP]");
        break;

        case IP_EVENT_AP_STAIPASSIGNED:
        ESP_LOGE(TAG,"IP_AP_STAIPASSIGNED");
            break;
        }  

    }  
}


int size_ssid;
void wifi_init_sta(void)
{
ESP_ERROR_CHECK(esp_netif_init());
ESP_ERROR_CHECK(esp_event_loop_create_default());
esp_netif_create_default_wifi_sta();

wifi_init_config_t wifi_init_cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK(esp_wifi_init(&wifi_init_cfg));


    ESP_ERROR_CHECK(esp_event_handler_instance_register(WIFI_EVENT,
                                                        ESP_EVENT_ANY_ID,
                                                        &wifi_event_handler,
                                                        NULL,
                                                        NULL));
    
    ESP_ERROR_CHECK(esp_event_handler_instance_register(IP_EVENT,
                                                        ESP_EVENT_ANY_ID,
                                                        &wifi_event_handler,
                                                        NULL,
                                                        NULL));

wifi_config_t wifi_config_sta;
memset(&wifi_config_sta, 0, sizeof(wifi_config_t));

size_ssid = sizeof(WIFI_SSID);
ESP_LOGE(TAG,"Size ssid :[%i]", size_ssid);
strlcpy((char*)wifi_config_sta.sta.ssid,WIFI_SSID,12);
//strlcpy((char*)wifi_config_sta.sta.password,WIFI_PASS,sizeof(WIFI_PASS));
wifi_config_sta.sta.threshold.authmode  = WIFI_AUTH_OPEN;
 ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA) );
   ESP_ERROR_CHECK(esp_wifi_set_config(WIFI_IF_STA, &wifi_config_sta) ); // ESP_IF_WIFI_STA
    ESP_ERROR_CHECK(esp_wifi_start() );

//"WiFi_Bondarenko_Family","hDj8BP2b74b
}

void app_main(void)
{
    //Initialize NVS
    esp_err_t ret = nvs_flash_init();
    if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
      ESP_ERROR_CHECK(nvs_flash_erase());
      ret = nvs_flash_init();
    }
    ESP_ERROR_CHECK(ret);
F_WIFI_CONNECT = F_RES;
  
wifi_init_sta();


xTaskCreate(&http_get_task, "http_get_task", 8096, NULL, 5, NULL);
}


//HTTP 
#define WEB_SERVER  "example.com"
#define WEB_PORT "80"
#define WEB_PATH "/"

static const char *REQUEST = "GET " WEB_PATH " HTTP/1.0\r\n"
    "Host: "WEB_SERVER":"WEB_PORT"\r\n"
    "User-Agent: esp-idf/1.0 esp32\r\n"
    "\r\n";


#define WAITE_WIFI_CONNECT 0
#define HTTP_REQUST        1

    void http_get_task (void *pvParameters)
    {

        struct addrinfo hints;
        hints.ai_family = AF_INET;
        hints.ai_socktype = SOCK_STREAM;

        struct addrinfo *res;
        struct in_addr *addr;
        int s, r;
        char recv_buff[512];
         int err ;
        unsigned char state;
        state = WAITE_WIFI_CONNECT;
        for(;;)
        {
            if(state == WAITE_WIFI_CONNECT) 
            {
                vTaskDelay(1000/portTICK_PERIOD_MS);
                ESP_LOGI(TAG,"Waite connect WiFi");

                if(F_WIFI_CONNECT == F_SET)
                {
                ESP_LOGI(TAG,"WIFI_CONNECTED!");
                state = HTTP_REQUST;
                }
            }
if(state == HTTP_REQUST)
    {

            err = getaddrinfo(WEB_SERVER, WEB_PORT, &hints, &res);

            if(err !=0 || res == NULL)
              {
                ESP_LOGE(TAG, "DNS lookup failed err=%d res=%p", err, res);
                vTaskDelay(1000 / portTICK_PERIOD_MS);
               continue;
              }

        addr = &((struct sockaddr_in *)res->ai_addr)->sin_addr;
        ESP_LOGI(TAG, "DNS lookup succeeded. IP=%s", inet_ntoa(*addr));

        s = socket(res->ai_family, res->ai_socktype, 0);

           if(s < 0) {
            ESP_LOGE(TAG, "... Failed to allocate socket.");
            freeaddrinfo(res);
            vTaskDelay(1000 / portTICK_PERIOD_MS);
            continue;
        }
       
       
        ESP_LOGI(TAG, "... allocated socket");


     if(connect(s, res->ai_addr, res->ai_addrlen) != 0) {
            ESP_LOGE(TAG, "... socket connect failed errno=%d", errno);
            close(s);
            freeaddrinfo(res);
            vTaskDelay(4000 / portTICK_PERIOD_MS);
            continue;
        }

         ESP_LOGI(TAG, "... connected");
        freeaddrinfo(res);

      if (write(s, REQUEST, strlen(REQUEST)) < 0) {
            ESP_LOGE(TAG, "... socket send failed");
            close(s);
            vTaskDelay(4000 / portTICK_PERIOD_MS);
            continue;
        }
        ESP_LOGI(TAG, "... socket send success");



   struct timeval receiving_timeout;
        receiving_timeout.tv_sec = 5;
        receiving_timeout.tv_usec = 0;
        if (setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &receiving_timeout,
                sizeof(receiving_timeout)) < 0) {
            ESP_LOGE(TAG, "... failed to set socket receiving timeout");
            close(s);
            vTaskDelay(4000 / portTICK_PERIOD_MS);
            continue;
        }



   ESP_LOGI(TAG, "... set socket receiving timeout success");


            /* Read HTTP response */
        do {
            bzero(recv_buff, sizeof(recv_buff));
            r = read(s, recv_buff, sizeof(recv_buff)-1);
            for(int i = 0; i < r; i++) {
                putchar(recv_buff[i]);
            }
        } while(r > 0);

        ESP_LOGI(TAG, "... done reading from socket. Last read return=%d errno=%d.", r, errno);
        close(s);


        for(int countdown = 10; countdown >= 0; countdown--) {
            ESP_LOGI(TAG, "%d... ", countdown);
            vTaskDelay(1000 / portTICK_PERIOD_MS);
        }

        ESP_LOGI(TAG, "Starting again!");

    }//else
        }
    vTaskDelete(NULL);
}

Result:

e[0;31mE (137) wifi_AP: Size ssid :[4]e[0m
e[0;31mE (317) wifi_AP: WIFI_HNDR:[WIFI_EVENT_STA_START]e[0m
e[0;31mE (977) wifi_AP: WIFI_HNDR:[WIFI_EVENT_STA_CONNECTED]e[0m
e[0;31mE (977) wifi_AP: STA_CONNECTED-SSID[Wokwi-GUEST]e[0m
e[0;31mE (1977) wifi_AP: WIFI_HNDR:[IP_EVENT_STA_GOT_IP]e[0m
e[0;31mE (1977) wifi_AP: ETHIP:10.10.0.2e[0m
e[0;31mE (1977) wifi_AP: ETHMASK:255.255.0.0e[0m
e[0;31mE (1977) wifi_AP: ETHGW:10.0.0.1e[0m
e[0;31mE (2317) wifi_AP: DNS lookup failed err=200 res=0x0e[0m
e[0;31mE (3317) wifi_AP: DNS lookup failed err=200 res=0x0e[0m
e[0;31mE (4317) wifi_AP: DNS lookup failed err=200 res=0x0e[0m

Did it work for you?

No, it doesn’t work.
An error occurs at the function call stage
err = getaddrinfo(WEB_SERVER, WEB_PORT, &hints, &res);

I get err: DNS lookup failed err=200 res=0x0
The error is repeated for other sites.

But that’s not the example i mentioned.

Does the Arduino example work for you?