mirror of
https://github.com/espressif/esp-protocols.git
synced 2025-07-21 22:42:23 +02:00
fix(esp-modem): Example to use variable mqtt topic/data
This example is used in the CI with public broker and users playing with the example can influence stability of tests if we share the same topic id
This commit is contained in:
@ -184,4 +184,22 @@ menu "Example Configuration"
|
|||||||
|
|
||||||
endmenu
|
endmenu
|
||||||
|
|
||||||
|
config EXAMPLE_MQTT_BROKER_URI
|
||||||
|
string "MQTT Broker URL"
|
||||||
|
default "mqtt://mqtt.eclipseprojects.io"
|
||||||
|
help
|
||||||
|
URL of the mqtt broker which this example connects to.
|
||||||
|
|
||||||
|
config EXAMPLE_MQTT_TEST_TOPIC
|
||||||
|
string "MQTT topic to publish/subscribe"
|
||||||
|
default "/topic/esp-pppos"
|
||||||
|
help
|
||||||
|
MQTT topic, which we subscribe on and publish to.
|
||||||
|
|
||||||
|
config EXAMPLE_MQTT_TEST_DATA
|
||||||
|
string "MQTT data to publish/receive"
|
||||||
|
default "esp32-pppos"
|
||||||
|
help
|
||||||
|
MQTT data message, which we publish and expect to receive.
|
||||||
|
|
||||||
endmenu
|
endmenu
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
|
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||||
*/
|
*/
|
||||||
@ -30,7 +30,6 @@
|
|||||||
#define EXAMPLE_FLOW_CONTROL ESP_MODEM_FLOW_CONTROL_HW
|
#define EXAMPLE_FLOW_CONTROL ESP_MODEM_FLOW_CONTROL_HW
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define BROKER_URL "mqtt://mqtt.eclipseprojects.io"
|
|
||||||
|
|
||||||
static const char *TAG = "pppos_example";
|
static const char *TAG = "pppos_example";
|
||||||
static EventGroupHandle_t event_group = NULL;
|
static EventGroupHandle_t event_group = NULL;
|
||||||
@ -68,7 +67,7 @@ static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_
|
|||||||
switch ((esp_mqtt_event_id_t)event_id) {
|
switch ((esp_mqtt_event_id_t)event_id) {
|
||||||
case MQTT_EVENT_CONNECTED:
|
case MQTT_EVENT_CONNECTED:
|
||||||
ESP_LOGI(TAG, "MQTT_EVENT_CONNECTED");
|
ESP_LOGI(TAG, "MQTT_EVENT_CONNECTED");
|
||||||
msg_id = esp_mqtt_client_subscribe(client, "/topic/esp-pppos", 0);
|
msg_id = esp_mqtt_client_subscribe(client, CONFIG_EXAMPLE_MQTT_TEST_TOPIC, 0);
|
||||||
ESP_LOGI(TAG, "sent subscribe successful, msg_id=%d", msg_id);
|
ESP_LOGI(TAG, "sent subscribe successful, msg_id=%d", msg_id);
|
||||||
break;
|
break;
|
||||||
case MQTT_EVENT_DISCONNECTED:
|
case MQTT_EVENT_DISCONNECTED:
|
||||||
@ -76,7 +75,7 @@ static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_
|
|||||||
break;
|
break;
|
||||||
case MQTT_EVENT_SUBSCRIBED:
|
case MQTT_EVENT_SUBSCRIBED:
|
||||||
ESP_LOGI(TAG, "MQTT_EVENT_SUBSCRIBED, msg_id=%d", event->msg_id);
|
ESP_LOGI(TAG, "MQTT_EVENT_SUBSCRIBED, msg_id=%d", event->msg_id);
|
||||||
msg_id = esp_mqtt_client_publish(client, "/topic/esp-pppos", "esp32-pppos", 0, 0, 0);
|
msg_id = esp_mqtt_client_publish(client, CONFIG_EXAMPLE_MQTT_TEST_TOPIC, CONFIG_EXAMPLE_MQTT_TEST_DATA, 0, 0, 0);
|
||||||
ESP_LOGI(TAG, "sent publish successful, msg_id=%d", msg_id);
|
ESP_LOGI(TAG, "sent publish successful, msg_id=%d", msg_id);
|
||||||
break;
|
break;
|
||||||
case MQTT_EVENT_UNSUBSCRIBED:
|
case MQTT_EVENT_UNSUBSCRIBED:
|
||||||
@ -271,11 +270,11 @@ void app_main(void)
|
|||||||
/* Config MQTT */
|
/* Config MQTT */
|
||||||
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
|
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
|
||||||
esp_mqtt_client_config_t mqtt_config = {
|
esp_mqtt_client_config_t mqtt_config = {
|
||||||
.broker.address.uri = BROKER_URL,
|
.broker.address.uri = CONFIG_EXAMPLE_MQTT_BROKER_URI,
|
||||||
};
|
};
|
||||||
#else
|
#else
|
||||||
esp_mqtt_client_config_t mqtt_config = {
|
esp_mqtt_client_config_t mqtt_config = {
|
||||||
.uri = BROKER_URL,
|
.uri = CONFIG_EXAMPLE_MQTT_BROKER_URI,
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
esp_mqtt_client_handle_t mqtt_client = esp_mqtt_client_init(&mqtt_config);
|
esp_mqtt_client_handle_t mqtt_client = esp_mqtt_client_init(&mqtt_config);
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
|
# SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
|
||||||
# SPDX-License-Identifier: Unlicense OR CC0-1.0
|
# SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||||
from __future__ import print_function, unicode_literals
|
from __future__ import print_function, unicode_literals
|
||||||
|
|
||||||
@ -16,7 +16,7 @@ def test_pppos_connect(dut):
|
|||||||
# Check for MQTT connection and the data event
|
# Check for MQTT connection and the data event
|
||||||
dut.expect('MQTT_EVENT_CONNECTED')
|
dut.expect('MQTT_EVENT_CONNECTED')
|
||||||
dut.expect('MQTT_EVENT_DATA')
|
dut.expect('MQTT_EVENT_DATA')
|
||||||
dut.expect('TOPIC=/topic/esp-pppos')
|
dut.expect('TOPIC=/ci/esp-modem/pppos-client')
|
||||||
dut.expect('DATA=esp32-pppos')
|
dut.expect('DATA=esp32-pppos')
|
||||||
# Check that we have disconnected
|
# Check that we have disconnected
|
||||||
dut.expect('User interrupted event')
|
dut.expect('User interrupted event')
|
||||||
|
@ -9,5 +9,6 @@ CONFIG_EXAMPLE_MODEM_UART_RX_PIN=5
|
|||||||
CONFIG_EXAMPLE_MODEM_DEVICE_SIM800=y
|
CONFIG_EXAMPLE_MODEM_DEVICE_SIM800=y
|
||||||
CONFIG_EXAMPLE_MODEM_DEVICE_BG96=n
|
CONFIG_EXAMPLE_MODEM_DEVICE_BG96=n
|
||||||
CONFIG_EXAMPLE_MODEM_PPP_APN="lpwa.vodafone.com"
|
CONFIG_EXAMPLE_MODEM_PPP_APN="lpwa.vodafone.com"
|
||||||
|
CONFIG_EXAMPLE_MQTT_TEST_TOPIC="/ci/esp-modem/pppos-client"
|
||||||
CONFIG_ESP_SYSTEM_PANIC_PRINT_HALT=y
|
CONFIG_ESP_SYSTEM_PANIC_PRINT_HALT=y
|
||||||
CONFIG_ESP32_PANIC_PRINT_HALT=y
|
CONFIG_ESP32_PANIC_PRINT_HALT=y
|
||||||
|
Reference in New Issue
Block a user