From e85f45b539bde3d408ffba306d5d84ffdcdca629 Mon Sep 17 00:00:00 2001 From: David Cermak Date: Sun, 26 Jun 2022 22:17:21 +0200 Subject: [PATCH] examples/cxx: Remove esp_modem examples Examples are maintained and supported in esp-protocols --- .../experimental/esp_modem_cxx/CMakeLists.txt | 8 - .../cxx/experimental/esp_modem_cxx/README.md | 62 -------- .../esp_modem_cxx/main/CMakeLists.txt | 2 - .../esp_modem_cxx/main/Kconfig.projbuild | 42 ------ .../esp_modem_cxx/main/idf_component.yml | 6 - .../esp_modem_cxx/main/simple_client.cpp | 137 ------------------ .../esp_modem_cxx/main/simple_mqtt_client.cpp | 101 ------------- .../esp_modem_cxx/main/simple_mqtt_client.hpp | 77 ---------- .../esp_modem_cxx/sdkconfig.defaults | 8 - 9 files changed, 443 deletions(-) delete mode 100644 examples/cxx/experimental/esp_modem_cxx/CMakeLists.txt delete mode 100644 examples/cxx/experimental/esp_modem_cxx/README.md delete mode 100644 examples/cxx/experimental/esp_modem_cxx/main/CMakeLists.txt delete mode 100644 examples/cxx/experimental/esp_modem_cxx/main/Kconfig.projbuild delete mode 100644 examples/cxx/experimental/esp_modem_cxx/main/idf_component.yml delete mode 100644 examples/cxx/experimental/esp_modem_cxx/main/simple_client.cpp delete mode 100644 examples/cxx/experimental/esp_modem_cxx/main/simple_mqtt_client.cpp delete mode 100644 examples/cxx/experimental/esp_modem_cxx/main/simple_mqtt_client.hpp delete mode 100644 examples/cxx/experimental/esp_modem_cxx/sdkconfig.defaults diff --git a/examples/cxx/experimental/esp_modem_cxx/CMakeLists.txt b/examples/cxx/experimental/esp_modem_cxx/CMakeLists.txt deleted file mode 100644 index fc77d2092f..0000000000 --- a/examples/cxx/experimental/esp_modem_cxx/CMakeLists.txt +++ /dev/null @@ -1,8 +0,0 @@ -# The following lines of boilerplate have to be in your project's CMakeLists -# in this exact order for cmake to work correctly -cmake_minimum_required(VERSION 3.16) - -set(EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/examples/cxx/experimental/experimental_cpp_component) - -include($ENV{IDF_PATH}/tools/cmake/project.cmake) -project(simple_cxx_ppp_client) diff --git a/examples/cxx/experimental/esp_modem_cxx/README.md b/examples/cxx/experimental/esp_modem_cxx/README.md deleted file mode 100644 index 4751cc12b3..0000000000 --- a/examples/cxx/experimental/esp_modem_cxx/README.md +++ /dev/null @@ -1,62 +0,0 @@ -| Supported Targets | ESP32 | ESP32-S2 | -| ----------------- | ----- | -------- | - -# Simple example of esp_modem component - -(See the README.md file in the upper level 'examples' directory for more information about examples.) - - -## Overview - -This example demonstrates the use of the [esp-modem component](https://components.espressif.com/component/espressif/esp_modem) to connect to a network and send some AT commands. -It uses modem CMUX mode so that commands and network could be used at the same time. - -## About the esp_modem - -The esp_modem component is deployed automatically when building this example. It will be located inside this example directory, in relative path `managed_components/espressif__esp_modem`. -You can find a brief introduction in the root directory of the component, in the main `README.md` for or a full html documentation in the relative path `docs/html/index.html`. - -## How to use example - -### Hardware Required - -To run this example, you need an ESP32 dev board connected to a GSM/4G cellular module, which supports AT commands and PPP connectivity. -The example uses UART to communicate with the modem and it uses the below pin assignment: - -| ESP32 | Cellular Modem | -| ------ | -------------- | -| GPIO25 | RX | -| GPIO26 | TX | -| GND | GND | - -### Configure the project - -* Choose the modem module in `Choose supported modem device(DCE)` option. -* Set the access point name in `Set Access Point Name(APN)` option, which should depend on the operator of your SIM card. -* Enable `EXAMPLE_NEED_SIM_PIN`: To unlock the SIM card with a PIN code if needed - -## Example Output - -The example will unlock the SIM card (if enabled) and enter the CMUX mode. -Then it would initiate the connection to a public MQTT broker and at the same time reading some data using AT commands. - -``` -I (571) uart: queue free spaces: 30 -I (1731) cmux_example: Modem has correctly entered multiplexed command/data mode -I (2241) cmux_example: Operator name: "OperatorName" -I (7781) esp-netif_lwip-ppp: Connected -I (7781) esp-netif_lwip-ppp: Name Server1: xxx.xxx.xxx.xxx -I (7781) esp-netif_lwip-ppp: Name Server2: xxx.xxx.xxx.xxx -I (7781) cmux_example: Got IP address -I (7791) cmux_example: IP : xxx.xxx.xxx.xxx -I (7791) cmux_example: Netmask : xxx.xxx.xxx.xxx -I (7801) cmux_example: Gateway : xxx.xxx.xxx.xxx -I (7801) system_api: Base MAC address is not set -I (7811) system_api: read default base MAC address from EFUSE -I (9061) cmux_example: TOPIC: /topic/esp-modem -I (9061) cmux_example: DATA: Hello modem -I (9061) cmux_example: Data received -I (9211) cmux_example: Modem IMSI number: xxxxxxxxxxxxxxxx -I (21221) esp-netif_lwip-ppp: User interrupt -I (21221) esp_modem_netif: PPP state changed event 5 -``` diff --git a/examples/cxx/experimental/esp_modem_cxx/main/CMakeLists.txt b/examples/cxx/experimental/esp_modem_cxx/main/CMakeLists.txt deleted file mode 100644 index 25a9423f77..0000000000 --- a/examples/cxx/experimental/esp_modem_cxx/main/CMakeLists.txt +++ /dev/null @@ -1,2 +0,0 @@ -idf_component_register(SRCS "simple_client.cpp" "simple_mqtt_client.cpp" - INCLUDE_DIRS ".") diff --git a/examples/cxx/experimental/esp_modem_cxx/main/Kconfig.projbuild b/examples/cxx/experimental/esp_modem_cxx/main/Kconfig.projbuild deleted file mode 100644 index b5e6be2753..0000000000 --- a/examples/cxx/experimental/esp_modem_cxx/main/Kconfig.projbuild +++ /dev/null @@ -1,42 +0,0 @@ -menu "Example Configuration" - - choice EXAMPLE_MODEM_DEVICE - prompt "Choose supported modem device (DCE)" - default EXAMPLE_MODEM_DEVICE_BG96 - help - Select modem device connected to the ESP DTE. - config EXAMPLE_MODEM_DEVICE_SIM800 - bool "SIM800" - help - SIMCom SIM800L is a GSM/GPRS module. - It supports Quad-band 850/900/1800/1900MHz. - config EXAMPLE_MODEM_DEVICE_BG96 - bool "BG96" - help - Quectel BG96 is a series of LTE Cat M1/Cat NB1/EGPRS module. - config EXAMPLE_MODEM_DEVICE_SIM7600 - bool "SIM7600" - help - SIM7600 is a Multi-Band LTE-TDD/LTE-FDD/HSPA+ and GSM/GPRS/EDGE module. - endchoice - - config EXAMPLE_MODEM_PPP_APN - string "Set MODEM APN" - default "internet" - help - Set APN (Access Point Name), a logical name to choose data network - - config EXAMPLE_NEED_SIM_PIN - bool "SIM PIN needed" - default n - help - Enable to set SIM PIN before starting the example - - config EXAMPLE_SIM_PIN - string "Set SIM PIN" - default "1234" - depends on EXAMPLE_NEED_SIM_PIN - help - Pin to unlock the SIM - -endmenu diff --git a/examples/cxx/experimental/esp_modem_cxx/main/idf_component.yml b/examples/cxx/experimental/esp_modem_cxx/main/idf_component.yml deleted file mode 100644 index 41c0db93e4..0000000000 --- a/examples/cxx/experimental/esp_modem_cxx/main/idf_component.yml +++ /dev/null @@ -1,6 +0,0 @@ -targets: - - esp32 - - esp32s2 -description: cmux example of esp_modem -dependencies: - espressif/esp_modem: "~0.1.12" diff --git a/examples/cxx/experimental/esp_modem_cxx/main/simple_client.cpp b/examples/cxx/experimental/esp_modem_cxx/main/simple_client.cpp deleted file mode 100644 index 2fa538d4ec..0000000000 --- a/examples/cxx/experimental/esp_modem_cxx/main/simple_client.cpp +++ /dev/null @@ -1,137 +0,0 @@ -/* PPPoS Client 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 -#include "freertos/FreeRTOS.h" -#include "freertos/event_groups.h" -#include "esp_netif.h" -#include "esp_log.h" -#include "cxx_include/esp_modem_dte.hpp" -#include "esp_modem_config.h" -#include "cxx_include/esp_modem_api.hpp" -#include "esp_event_cxx.hpp" -#include "simple_mqtt_client.hpp" - - -#define BROKER_URL "mqtt://mqtt.eclipseprojects.io" - -using namespace esp_modem; -using namespace idf::event; - -constexpr auto TAG = "cmux_example"; - - -extern "C" void app_main(void) -{ - /* Init and register system/core components */ - auto loop = std::make_shared(); - ESP_ERROR_CHECK(esp_netif_init()); - /* Configure the DTE */ - esp_modem_dte_config_t dte_config = ESP_MODEM_DTE_DEFAULT_CONFIG(); - - /* Configure the DCE */ - esp_modem_dce_config_t dce_config = ESP_MODEM_DCE_DEFAULT_CONFIG(CONFIG_EXAMPLE_MODEM_PPP_APN); - - /* Configure the PPP netif */ - esp_netif_config_t netif_ppp_config = ESP_NETIF_DEFAULT_PPP(); - - /* Create the DTE, PPP and DCE objects */ - auto uart_dte = create_uart_dte(&dte_config); - assert(uart_dte); - - esp_netif_t *esp_netif = esp_netif_new(&netif_ppp_config); - assert(esp_netif); - - #if CONFIG_EXAMPLE_MODEM_DEVICE_BG96 == 1 - std::unique_ptr dce = create_BG96_dce(&dce_config, uart_dte, esp_netif); - #elif CONFIG_EXAMPLE_MODEM_DEVICE_SIM800 == 1 - std::unique_ptr dce = create_SIM800_dce(&dce_config, uart_dte, esp_netif); - #elif CONFIG_EXAMPLE_MODEM_DEVICE_SIM7600 == 1 - std::unique_ptr dce = create_SIM7600_dce(&dce_config, uart_dte, esp_netif); - #else - #error "Unsupported device" - #endif - assert(dce); - - /* Setup basic operation mode for the DCE (pin if used, CMUX mode) */ -#if CONFIG_EXAMPLE_NEED_SIM_PIN == 1 - bool pin_ok = true; - if (dce->read_pin(pin_ok) == command_result::OK && !pin_ok) { - if (dce->set_pin(CONFIG_EXAMPLE_SIM_PIN) == command_result::OK) { - vTaskDelay(pdMS_TO_TICKS(1000)); // Need to wait for some time after unlocking the SIM - } else { - ESP_LOGE(TAG, "Failed to set PIN... exiting"); - return; - } - } -#endif - - if (dce->set_mode(esp_modem::modem_mode::CMUX_MODE) && dce->set_mode(esp_modem::modem_mode::DATA_MODE)) { - ESP_LOGI(TAG, "Modem has correctly entered multiplexed command/data mode"); - } else { - ESP_LOGE(TAG, "Failed to configure desired mode... exiting"); - return; - } - - /* Read some data from the modem */ - std::string str; - while (dce->get_operator_name(str) != esp_modem::command_result::OK) { - // Getting operator name could fail... retry after 500 ms - vTaskDelay(pdMS_TO_TICKS(500)); - } - ESP_LOGI(TAG, "Operator name: %s", str.c_str()); - - /* Try to connect to the network and publish an mqtt topic */ - ESPEventHandlerSync event_handler(loop); - event_handler.listen_to(ESPEvent(IP_EVENT, ESPEventID(ESP_EVENT_ANY_ID))); - auto result = event_handler.wait_event_for(std::chrono::milliseconds(60000)); - if (result.timeout) { - ESP_LOGE(TAG, "Cannot get IP within specified timeout... exiting"); - return; - } else if (result.event.id == ESPEventID(IP_EVENT_PPP_GOT_IP)) { - auto *event = (ip_event_got_ip_t *)result.ev_data; - ESP_LOGI(TAG, "Got IP address"); - ESP_LOGI(TAG, "IP : " IPSTR, IP2STR(&event->ip_info.ip)); - ESP_LOGI(TAG, "Netmask : " IPSTR, IP2STR(&event->ip_info.netmask)); - ESP_LOGI(TAG, "Gateway : " IPSTR, IP2STR(&event->ip_info.gw)); - - /* When connected to network, subscribe and publish some MQTT data */ - MqttClient mqtt(BROKER_URL); - event_handler.listen_to(MqttClient::get_event(MqttClient::Event::CONNECT)); - event_handler.listen_to(MqttClient::get_event(MqttClient::Event::DATA)); - - auto reg = loop->register_event(MqttClient::get_event(MqttClient::Event::DATA), - [&mqtt](const ESPEvent &event, void *data) { - ESP_LOGI(TAG, " TOPIC: %s", mqtt.get_topic(data).c_str()); - ESP_LOGI(TAG, " DATA: %s", mqtt.get_data(data).c_str()); - }); - mqtt.connect(); - while (true) { - result = event_handler.wait_event_for(std::chrono::milliseconds(60000)); - if (result.event == MqttClient::get_event(MqttClient::Event::CONNECT)) { - mqtt.subscribe("/topic/esp-modem"); - mqtt.publish("/topic/esp-modem", "Hello modem"); - continue; - } else if (result.event == MqttClient::get_event(MqttClient::Event::DATA)) { - ESP_LOGI(TAG, "Data received"); - break; /* Continue with CMUX example after getting data from MQTT */ - } else { - break; - } - } - - } else if (result.event.id == ESPEventID(IP_EVENT_PPP_LOST_IP)) { - ESP_LOGE(TAG, "PPP client has lost connection... exiting"); - return; - } - - /* Again reading some data from the modem */ - if (dce->get_imsi(str) == esp_modem::command_result::OK) { - ESP_LOGI(TAG, "Modem IMSI number: %s", str.c_str()); - } -} diff --git a/examples/cxx/experimental/esp_modem_cxx/main/simple_mqtt_client.cpp b/examples/cxx/experimental/esp_modem_cxx/main/simple_mqtt_client.cpp deleted file mode 100644 index 7dfe01dd7b..0000000000 --- a/examples/cxx/experimental/esp_modem_cxx/main/simple_mqtt_client.cpp +++ /dev/null @@ -1,101 +0,0 @@ -/* PPPoS Client 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 -#include "mqtt_client.h" -#include "esp_event_cxx.hpp" -#include "simple_mqtt_client.hpp" - -using namespace idf::event; - -/** - * Reference to the MQTT event base - */ -ESP_EVENT_DECLARE_BASE(MQTT_EVENTS); - -/** - * Thin wrapper around C mqtt_client - */ -struct MqttClientHandle -{ - explicit MqttClientHandle(const std::string & uri) - { - esp_mqtt_client_config_t config = { }; - config.broker.address.uri = uri.c_str(); - client = esp_mqtt_client_init(&config); - esp_mqtt_client_register_event(client, MQTT_EVENT_ANY, mqtt_event_handler, this); - } - - ~MqttClientHandle() - { - esp_mqtt_client_destroy(client); - } - - static void mqtt_event_handler(void *args, esp_event_base_t base, int32_t id, void *data) - { - // forwards the internal event to the global ESPEvent - esp_event_post(base, id, data, sizeof(esp_mqtt_event_t), portMAX_DELAY); - } - - esp_mqtt_client_handle_t client; -}; - -/** - * @brief Definitions of MqttClient methods - */ -MqttClient::MqttClient(const std::string & uri): - h(std::unique_ptr(new MqttClientHandle(uri))) - {} - -void MqttClient::connect() -{ - esp_mqtt_client_start(h->client); -} - -idf::event::ESPEvent MqttClient::get_event(MqttClient::Event ev) -{ - switch (ev) { - case Event::CONNECT: { - return { MQTT_EVENTS, ESPEventID(MQTT_EVENT_CONNECTED) }; - } - case Event::DATA: - return { MQTT_EVENTS, ESPEventID(MQTT_EVENT_DATA) }; - } - return { }; -} - -int MqttClient::publish(const std::string &topic, const std::string &data, int qos) -{ - return esp_mqtt_client_publish(h->client, topic.c_str(), data.c_str(), 0, qos, 0); -} - -int MqttClient::subscribe(const std::string &topic, int qos) -{ - return esp_mqtt_client_subscribe(h->client, topic.c_str(), qos); -} - -std::string MqttClient::get_topic(void * event_data) -{ - auto event = (esp_mqtt_event_handle_t)event_data; - if (event == nullptr || event->client != h->client) - return {}; - - return std::string(event->topic, event->topic_len); -} - -std::string MqttClient::get_data(void * event_data) -{ - auto event = (esp_mqtt_event_handle_t)event_data; - if (event == nullptr || event->client != h->client) - return {}; - - return std::string(event->data, event->data_len); -} - -MqttClient::~MqttClient() = default; diff --git a/examples/cxx/experimental/esp_modem_cxx/main/simple_mqtt_client.hpp b/examples/cxx/experimental/esp_modem_cxx/main/simple_mqtt_client.hpp deleted file mode 100644 index ca3d564af8..0000000000 --- a/examples/cxx/experimental/esp_modem_cxx/main/simple_mqtt_client.hpp +++ /dev/null @@ -1,77 +0,0 @@ -/* PPPoS Client 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. -*/ -#ifndef _SIMPLE_MQTT_CLIENT_H_ -#define _SIMPLE_MQTT_CLIENT_H_ - -#include -#include -#include "esp_event_cxx.hpp" - -struct MqttClientHandle; - -/** - * @brief Simple MQTT client wrapper - */ -class MqttClient { -public: - enum class Event { - CONNECT, - DATA, - }; - - explicit MqttClient(const std::string & uri); - ~MqttClient(); - - /** - * @brief Start the mqtt-client - */ - void connect(); - - /** - * @brief Publish to topic - * @param topic Topic to publish - * @param data Data to publish - * @param qos QoS (0 by default) - * @return message id - */ - int publish(const std::string & topic, const std::string & data, int qos = 0); - - /** - * @brief Subscribe to a topic - * @param topic Topic to subscribe - * @param qos QoS (0 by default) - * @return message id - */ - int subscribe(const std::string & topic, int qos = 0); - - /** - * @brief Get topic from event data - * @return String topic - */ - std::string get_topic(void *); - - /** - * @brief Get published data from event - * @return String representation of the data - */ - std::string get_data(void *); - - /** - * @brief Convert internal MQTT event to standard ESPEvent - * @param ev internal mqtt event - * @return corresponding ESPEvent - */ - static idf::event::ESPEvent get_event(Event ev); - -private: - std::unique_ptr h; -}; - - -#endif //_SIMPLE_MQTT_CLIENT_H_ diff --git a/examples/cxx/experimental/esp_modem_cxx/sdkconfig.defaults b/examples/cxx/experimental/esp_modem_cxx/sdkconfig.defaults deleted file mode 100644 index 78916c78d0..0000000000 --- a/examples/cxx/experimental/esp_modem_cxx/sdkconfig.defaults +++ /dev/null @@ -1,8 +0,0 @@ -# Override some defaults to enable PPP -CONFIG_LWIP_PPP_SUPPORT=y -CONFIG_LWIP_PPP_NOTIFY_PHASE_SUPPORT=y -CONFIG_LWIP_PPP_PAP_SUPPORT=y -CONFIG_LWIP_TCPIP_TASK_STACK_SIZE=4096 -# Do not enable IPV6 in dte<->dce link local -CONFIG_LWIP_PPP_ENABLE_IPV6=n -CONFIG_COMPILER_CXX_EXCEPTIONS=y