Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PdpContext is not declared (IDFGH-9350) #220

Closed
rpirsc13 opened this issue Feb 8, 2023 · 4 comments
Closed

PdpContext is not declared (IDFGH-9350) #220

rpirsc13 opened this issue Feb 8, 2023 · 4 comments

Comments

@rpirsc13
Copy link

rpirsc13 commented Feb 8, 2023

Hi,I am having the following issue that I am unable to compile the example pppos_client

ESP-IDF: v5.0
esp_modem : v0.1.26

In file included from xyz/managed_components/espressif__esp_modem/include/esp_modem_api.h:10,
                 from xyz/main/pppos_client.cpp:18:
xyz/managed_components/espressif__esp_modem/include/generate/esp_modem_command_declare.inc:127:78: error: 'PdpContext' has not been declared
  127 | ESP_MODEM_DECLARE_DCE_COMMAND(set_pdp_context, command_result, 1, STRUCT_OUT(PdpContext, p1)) \
      |                                                                              ^~~~~~~~~~
@github-actions github-actions bot changed the title PdpContext is not declared PdpContext is not declared (IDFGH-9350) Feb 8, 2023
@david-cermak
Copy link
Collaborator

@rpirsc13 Could you please share more details on how to reproduce the problem?

My guess is that you've just renamed the example's source pppos_client.c -> pppos_client.cpp, correct?
Note that esp-modem provides both C-API and C++ API and you have to choose which to use.
Keeping both APIs up to date and to reduce duplication, they are declared as macros and based on your language, the correct version is active.

By that renaming you have chosen C++ and you're trying to include the plain C API. This is unfortunately not possible.
Please use C++ API instead and replace esp_modem_api.h include with

#include "cxx_include/esp_modem_api.hpp"

@rpirsc13
Copy link
Author

rpirsc13 commented Feb 8, 2023

@david-cermak Your guess is correct.

I have used my test implementation from pppos_example.c.

I was not aware that there are separate headers for cpp. Thank you for pointing that out. Everything works as expected now.

@michaelboeding
Copy link

michaelboeding commented Aug 18, 2023

Im also having this issue. I have included them.

../managed_components/espressif__esp_modem/include/generate/esp_modem_command_declare.inc:102:78: error: 'PdpContext' has not been declared
 ESP_MODEM_DECLARE_DCE_COMMAND(set_pdp_context, command_result, 1, STRUCT_OUT(PdpContext, p1)) \
                                                                              ^~~~~~~~~~
../managed_components/espressif__esp_modem/include/generate/esp_modem_command_declare_helper.inc:17:38: note: in definition of macro 'STRUCT_OUT'
 #define STRUCT_OUT(struct_name, p1)  struct_name& p1
                                      ^~~~~~~~~~~
../managed_components/espressif__esp_modem/include/generate/esp_modem_command_declare.inc:102:1: note: in expansion of macro 'ESP_MODEM_DECLARE_DCE_COMMAND'
 ESP_MODEM_DECLARE_DCE_COMMAND(set_pdp_context, command_result, 1, STRUCT_OUT(PdpContext, p1)) \
 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../managed_components/espressif__esp_modem/include/esp_modem_api.h:21:1: note: in expansion of macro 'DECLARE_ALL_COMMAND_APIS'
 DECLARE_ALL_COMMAND_APIS(declares esp_modem_<API>(esp_modem_t *dce, ...);)
 ^~~~~~~~~~~~~~~~~~~~~~~~
#include "esp_modem_api.h"

static void setupPPP() {
    //define the err
    esp_err_t err;
    /* Init and register system/core components */
    ESP_ERROR_CHECK(esp_netif_init());
    ESP_ERROR_CHECK(esp_event_loop_create_default());
    ESP_ERROR_CHECK(esp_event_handler_register(IP_EVENT, ESP_EVENT_ANY_ID, &on_ip_event, NULL));
    ESP_ERROR_CHECK(esp_event_handler_register(NETIF_PPP_STATUS, ESP_EVENT_ANY_ID, &on_ppp_changed, NULL));

    /* Configure the PPP netif */
    // create_generic_dce
    esp_modem_dce_config dce_config = ESP_MODEM_DCE_DEFAULT_CONFIG(CONFIG_EXAMPLE_MODEM_PPP_APN);
    esp_netif_config_t netif_ppp_config = ESP_NETIF_DEFAULT_PPP();
    esp_netif_t *esp_netif = esp_netif_new(&netif_ppp_config);
    assert(esp_netif);

    //event_group = xEventGroupCreate();

    //configure the dte
    // create_uart_dte 
    esp_modem_dte_config_t dte_config = ESP_MODEM_DTE_DEFAULT_CONFIG();
    /*
    esp_modem_dte_config dte_config = {
        .dte_buffer_size = 512,        // Custom value
        .task_stack_size = 4096,       // Custom value
        .task_priority = 5,            // Custom value
        .uart_config = {
            .port_num = UART_NUM_1,
            .data_bits = UART_DATA_8_BITS,
            .stop_bits = UART_STOP_BITS_1,
            .parity = UART_PARITY_DISABLE,
            .flow_control = 0,
            .source_clk = 0,
            .baud_rate = 115200,        // Custom value
            .tx_io_num = TX_PIN,            // Custom value
            .rx_io_num = RX_PIN,            // Custom value
            .rts_io_num = 27,           // Custom value
            .cts_io_num = 23,           // Custom value
            .rx_buffer_size = 4096,     // Custom value
            .tx_buffer_size = 512,      // Custom value
            .event_queue_size = 30      // Custom value
        }
    };
    */

    //setup UART specific configuration based on kconfig options 
    dte_config.uart_config.tx_io_num = TX_PIN;
    dte_config.uart_config.rx_io_num = RX_PIN;
    
    /*
    dte_config.uart_config.rts_io_num = CONFIG_EXAMPLE_MODEM_UART_RTS_PIN;
    dte_config.uart_config.cts_io_num = CONFIG_EXAMPLE_MODEM_UART_CTS_PIN;
    dte_config.uart_config.flow_control = EXAMPLE_FLOW_CONTROL;
    dte_config.uart_config.rx_buffer_size = CONFIG_EXAMPLE_MODEM_UART_RX_BUFFER_SIZE;
    dte_config.uart_config.tx_buffer_size = CONFIG_EXAMPLE_MODEM_UART_TX_BUFFER_SIZE;
    dte_config.uart_config.event_queue_size = CONFIG_EXAMPLE_MODEM_UART_EVENT_QUEUE_SIZE;
    dte_config.task_stack_size = CONFIG_EXAMPLE_MODEM_UART_EVENT_TASK_STACK_SIZE;
    dte_config.task_priority = CONFIG_EXAMPLE_MODEM_UART_EVENT_TASK_PRIORITY;
    dte_config.dte_buffer_size = CONFIG_EXAMPLE_MODEM_UART_RX_BUFFER_SIZE / 2;
    */

    ESP_LOGI(TAG, "Initializing esp_modem for a generic module...");
    esp_modem_dce_t *dce = esp_modem_new(&dte_config, &dce_config, esp_netif);

    int rssi, ber;
    err = esp_modem_get_signal_quality(dce, rssi, ber);
    if (err != ESP_OK) {
        ESP_LOGE(TAG, "esp_modem_get_signal_quality failed with %d %s", err, esp_err_to_name(err));
        return;
    }
    ESP_LOGI(TAG, "Signal quality: rssi=%d, ber=%d", rssi, ber);


    err = esp_modem_set_mode(dce, ESP_MODEM_MODE_DATA);
    if (err != ESP_OK) {
        ESP_LOGE(TAG, "esp_modem_set_mode(ESP_MODEM_MODE_DATA) failed with %d", err);
        return;
    }

    /* Wait for IP address */
    ESP_LOGI(TAG, "Waiting for IP address");
    xEventGroupWaitBits(event_group, CONNECT_BIT, pdFALSE, pdFALSE, portMAX_DELAY);

    std::string imsi; // Declare imsi as a non-const string
    err = esp_modem_get_imsi(dce, imsi); // Pass imsi to the function, assuming it expects a non-const reference
    if (err != ESP_OK) {
        ESP_LOGE(TAG, "esp_modem_get_imsi failed with %d", err);
        return;
    }
    ESP_LOGI(TAG, "IMSI=%s", imsi.c_str());



    
     // UART DTE clean-up
    esp_modem_destroy(dce);
    esp_netif_destroy(esp_netif);
    
}




@david-cermak
Copy link
Collaborator

@michaelboeding Have you tried the suggestion from #220 (comment) ?

Are you compiling the snippet you shared above in C++? This library does not support using C-API from C++.
If you want to use C-API, please compile with C compiler (in IDF build system, your source file extension should be *.c)
If you want to use C++ compiler, please use C++ API and include cxx_include/esp_modem_api.hpp.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants