Skip to content

Commit

Permalink
fix(modem): Use the same public broker for examples
Browse files Browse the repository at this point in the history
  • Loading branch information
david-cermak committed Dec 6, 2024
1 parent c989c6a commit 340c92a
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,13 @@ menu "Example Configuration"
publishes another MQTT message.
Connection to the MQTT broker should be kept.

config EXAMPLE_DETECT_MODE_BEFORE_CONNECT
bool "Detect mode before connect"
default n
help
Set this to true to demonstrate mode auto-detection.
If enabled, the example tries to recognize the actual mode.
If mode is detected correctly and it is not a command mode,
then the example switches to command mode.

endmenu
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ static void usb_terminal_error_handler(esp_modem_terminal_error_t err)
}
#define CHECK_USB_DISCONNECTION(event_group) \
if ((xEventGroupGetBits(event_group) & USB_DISCONNECTED_BIT) == USB_DISCONNECTED_BIT) { \
ESP_LOGE(TAG, "USB_DISCONNECTED_BIT destroying modem dce"); \
esp_modem_destroy(dce); \
continue; \
}
Expand Down Expand Up @@ -158,6 +159,7 @@ void app_main(void)
ESP_ERROR_CHECK(esp_event_handler_register(NETIF_PPP_STATUS, ESP_EVENT_ANY_ID, &on_ppp_changed, NULL));

/* Configure the PPP netif */
esp_err_t err;
esp_modem_dce_config_t 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);
Expand Down Expand Up @@ -246,23 +248,38 @@ void app_main(void)
#error Invalid serial connection to modem.
#endif

#if CONFIG_EXAMPLE_DETECT_MODE_BEFORE_CONNECT
xEventGroupClearBits(event_group, CONNECT_BIT | GOT_DATA_BIT | USB_DISCONNECTED_BIT);

esp_err_t err = esp_modem_set_mode(dce, ESP_MODEM_MODE_DETECT);
err = esp_modem_set_mode(dce, ESP_MODEM_MODE_DETECT);
if (err != ESP_OK) {
ESP_LOGE(TAG, "esp_modem_set_mode(ESP_MODEM_MODE_DETECT) failed with %d", err);
return;
}
ESP_LOGI(TAG, "Mode detected!");
esp_modem_dce_mode_t mode = esp_modem_get_mode(dce);
ESP_LOGI(TAG, "Current mode is : %d", mode);
if (mode != ESP_MODEM_MODE_COMMAND) {
if (mode == ESP_MODEM_MODE_DATA) {
ESP_LOGI(TAG, "Waiting for IP address");
xEventGroupWaitBits(event_group, CONNECT_BIT | USB_DISCONNECTED_BIT, pdFALSE, pdFALSE, portMAX_DELAY);
CHECK_USB_DISCONNECTION(event_group);
ESP_LOGW(TAG, "Waiting for IP address DONE 1");
err = esp_modem_set_mode(dce, ESP_MODEM_MODE_COMMAND);
if (err != ESP_OK) {
ESP_LOGE(TAG, "esp_modem_set_mode(ESP_MODEM_MODE_COMMAND) failed with %d", err);
return;
}
ESP_LOGW(TAG, "Command mode done");
// err = esp_modem_hang_up(dce);
// if (err != ESP_OK) {
// ESP_LOGE(TAG, "esp_modem_hang_up failed with %d", err);
// return;
// }
// ESP_LOGW(TAG, "Hangup completed...");
}
#endif

xEventGroupClearBits(event_group, CONNECT_BIT | GOT_DATA_BIT | USB_DISCONNECTED_BIT);

/* Run the modem demo app */
#if CONFIG_EXAMPLE_NEED_SIM_PIN == 1
Expand Down Expand Up @@ -319,6 +336,7 @@ void app_main(void)
ESP_LOGI(TAG, "Waiting for IP address");
xEventGroupWaitBits(event_group, CONNECT_BIT | USB_DISCONNECTED_BIT, pdFALSE, pdFALSE, portMAX_DELAY);
CHECK_USB_DISCONNECTION(event_group);
ESP_LOGW(TAG, "Waiting for IP address DONE!");

/* Config MQTT */
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def test_pppos_connect(dut):
4. checks that the client cleanly disconnects
"""
# Check the sequence of connecting, publishing, disconnecting
dut.expect('Modem Connect to PPP Server')
dut.expect('Modem Connect to PPP Server', timeout=180)
# Check for MQTT connection and the data event
dut.expect('MQTT_EVENT_CONNECTED')
dut.expect('MQTT_EVENT_DATA')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ CONFIG_EXAMPLE_MQTT_TEST_TOPIC="/ci/esp-modem/pppos-client"
CONFIG_EXAMPLE_PAUSE_NETIF_TO_CHECK_SIGNAL=y
CONFIG_ESP_SYSTEM_PANIC_PRINT_HALT=y
CONFIG_ESP32_PANIC_PRINT_HALT=y
CONFIG_LOG_DEFAULT_LEVEL_DEBUG=y
CONFIG_EXAMPLE_DETECT_MODE_BEFORE_CONNECT=y
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ CONFIG_EXAMPLE_MODEM_PPP_AUTH_NONE=y
CONFIG_EXAMPLE_MQTT_TEST_TOPIC="/ci/esp-modem/pppos-client"
CONFIG_ESP_SYSTEM_PANIC_PRINT_HALT=y
CONFIG_ESP32_PANIC_PRINT_HALT=y
CONFIG_LOG_DEFAULT_LEVEL_DEBUG=y
CONFIG_EXAMPLE_DETECT_MODE_BEFORE_CONNECT=y
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ CONFIG_COMPILER_CXX_EXCEPTIONS=y
CONFIG_ESP_MAIN_TASK_STACK_SIZE=8192
CONFIG_EXAMPLE_CLOSE_CMUX_AT_END=y
CONFIG_EXAMPLE_MQTT_TEST_TOPIC="/ci/esp-modem/pppos-client"
CONFIG_BROKER_URI="mqtt://mqtt.eclipseprojects.io"

0 comments on commit 340c92a

Please sign in to comment.