forked from espressif/esp-protocols
Compare commits
8 Commits
mdns-v1.0.
...
websocket-
Author | SHA1 | Date | |
---|---|---|---|
5c245dbdb5 | |||
134a9a9eee | |||
010f98ca80 | |||
6e4e4fab1d | |||
b6852a0588 | |||
415e04a55f | |||
d1129f3d19 | |||
973837dd66 |
@ -1,4 +1,4 @@
|
||||
idf_component_register(SRCS "connect.c" "stdin_out.c" "addr_from_stdin.c"
|
||||
INCLUDE_DIRS "include"
|
||||
PRIV_REQUIRES esp_netif driver esp_eth
|
||||
PRIV_REQUIRES esp_netif driver esp_eth esp_wifi vfs
|
||||
)
|
||||
|
@ -11,7 +11,7 @@ else()
|
||||
src/esp_modem_uart.cpp
|
||||
src/esp_modem_term_uart.cpp
|
||||
src/esp_modem_netif.cpp)
|
||||
set(dependencies driver)
|
||||
set(dependencies driver esp_event esp_netif)
|
||||
endif()
|
||||
|
||||
set(srcs ${platform_srcs}
|
||||
|
@ -22,11 +22,13 @@ static EventGroupHandle_t event_group = NULL;
|
||||
static const int CONNECT_BIT = BIT0;
|
||||
static const int GOT_DATA_BIT = BIT2;
|
||||
|
||||
static esp_err_t mqtt_event_handler(esp_mqtt_event_handle_t event)
|
||||
static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data)
|
||||
{
|
||||
ESP_LOGD(TAG, "Event dispatched from event loop base=%s, event_id=%d", base, event_id);
|
||||
esp_mqtt_event_handle_t event = event_data;
|
||||
esp_mqtt_client_handle_t client = event->client;
|
||||
int msg_id;
|
||||
switch (event->event_id) {
|
||||
switch ((esp_mqtt_event_id_t)event_id) {
|
||||
case MQTT_EVENT_CONNECTED:
|
||||
ESP_LOGI(TAG, "MQTT_EVENT_CONNECTED");
|
||||
msg_id = esp_mqtt_client_subscribe(client, "/topic/esp-pppos", 0);
|
||||
@ -59,7 +61,6 @@ static esp_err_t mqtt_event_handler(esp_mqtt_event_handle_t event)
|
||||
ESP_LOGI(TAG, "MQTT other event id: %d", event->event_id);
|
||||
break;
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static void on_ppp_changed(void *arg, esp_event_base_t event_base,
|
||||
@ -200,11 +201,17 @@ void app_main(void)
|
||||
/* Wait for IP address */
|
||||
xEventGroupWaitBits(event_group, CONNECT_BIT, pdTRUE, pdTRUE, portMAX_DELAY);
|
||||
/* Config MQTT */
|
||||
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
|
||||
esp_mqtt_client_config_t mqtt_config = {
|
||||
.broker.address.uri = BROKER_URL,
|
||||
};
|
||||
#else
|
||||
esp_mqtt_client_config_t mqtt_config = {
|
||||
.uri = BROKER_URL,
|
||||
.event_handle = mqtt_event_handler,
|
||||
};
|
||||
#endif
|
||||
esp_mqtt_client_handle_t mqtt_client = esp_mqtt_client_init(&mqtt_config);
|
||||
esp_mqtt_client_register_event(mqtt_client, ESP_EVENT_ANY_ID, mqtt_event_handler, NULL);
|
||||
esp_mqtt_client_start(mqtt_client);
|
||||
xEventGroupWaitBits(event_group, GOT_DATA_BIT, pdTRUE, pdTRUE, portMAX_DELAY);
|
||||
esp_mqtt_client_destroy(mqtt_client);
|
||||
|
@ -26,7 +26,11 @@ struct MqttClientHandle {
|
||||
explicit MqttClientHandle(const std::string &uri)
|
||||
{
|
||||
esp_mqtt_client_config_t config = { };
|
||||
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0)
|
||||
config.broker.address.uri = uri.c_str();
|
||||
#else
|
||||
config.uri = uri.c_str();
|
||||
#endif
|
||||
client = esp_mqtt_client_init(&config);
|
||||
esp_mqtt_client_register_event(client, MQTT_EVENT_ANY, mqtt_event_handler, this);
|
||||
}
|
||||
|
@ -1,2 +1,3 @@
|
||||
idf_component_register(INCLUDE_DIRS include
|
||||
idf_component_register(SRCS "esp_err_to_name.c"
|
||||
INCLUDE_DIRS include
|
||||
REQUIRES esp_netif_linux esp_event_mock)
|
||||
|
@ -0,0 +1,14 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: Franz Hoepfinger
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
|
||||
|
||||
static const char esp_unknown_msg[] = "ERROR";
|
||||
|
||||
const char *esp_err_to_name(int code)
|
||||
{
|
||||
return esp_unknown_msg;
|
||||
}
|
@ -25,3 +25,11 @@ typedef int esp_err_t;
|
||||
#define ESP_ERR_NOT_FOUND 0x105
|
||||
#define ESP_ERR_NOT_SUPPORTED 0x106
|
||||
#define ESP_ERR_TIMEOUT 0x107
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
const char *esp_err_to_name(int code);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -22,7 +22,7 @@
|
||||
action; \
|
||||
} catch (::esp_modem::esp_err_exception& e) { \
|
||||
esp_err_t err = e.get_err_t(); \
|
||||
ESP_LOGE(TAG, "%s: Exception caught with ESP err_code=%d", __func__, err); \
|
||||
ESP_LOGE(TAG, "%s: Exception caught with ESP err_code=%d %s", __func__, err, esp_err_to_name(err)); \
|
||||
ESP_LOGE(TAG, "%s", e.what()); \
|
||||
action; \
|
||||
}
|
||||
|
@ -9,5 +9,5 @@ endif()
|
||||
idf_component_register(SRCS "esp_websocket_client.c"
|
||||
INCLUDE_DIRS "include"
|
||||
REQUIRES lwip esp-tls tcp_transport http_parser
|
||||
PRIV_REQUIRES esp_timer)
|
||||
PRIV_REQUIRES esp_timer esp_event)
|
||||
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")
|
||||
|
@ -1,4 +1,4 @@
|
||||
version: "0.0.2"
|
||||
version: "0.0.3"
|
||||
description: esp websocket client
|
||||
dependencies:
|
||||
idf:
|
||||
|
@ -3499,7 +3499,7 @@ void mdns_parse_packet(mdns_rx_packet_t * packet)
|
||||
service = _mdns_get_service_item(name->service, name->proto, NULL);
|
||||
}
|
||||
} else {
|
||||
if (!parsed_packet->authoritative || record_type == MDNS_NS) {
|
||||
if (!header.flags.qr || record_type == MDNS_NS) {
|
||||
//skip this record
|
||||
continue;
|
||||
}
|
||||
|
Reference in New Issue
Block a user