Compare commits

..

16 Commits

Author SHA1 Message Date
469f953b28 esp_modem: updated package version to 0.1.19 2022-08-18 15:59:48 +04:00
381eb314dc Merge pull request #93 from gabsuren/feature/websocket_json_example
websocket: updated example to show how to transfer json data
2022-08-15 14:50:48 +02:00
1ffc20c8e3 Merge pull request #105 from gabsuren/websocket/version_change_03
esp_websocket_client: upgraded package version to 0.0.3 (IDFGH-7986)
2022-08-05 12:37:40 +02:00
5c245dbdb5 esp_websocket_client: Upgraded version to 0.0.3 2022-08-05 10:21:41 +04:00
134a9a9eee Revert "bugfix: mdns IPv6 address convert error"
This reverts commit 238ee96783.
2022-08-04 15:52:40 +04:00
010f98ca80 Merge pull request #99 from gabsuren/bugfix/fix_ci_build
CI: Fix build issues
2022-07-29 11:10:11 +02:00
6e4e4fab1d CI: Fix build issues 2022-07-28 22:47:53 +04:00
b6852a0588 Merge pull request #96 from gjc13/bugfix/aa-bit-receive
fix(mdns): ignore authoritative flag on reception (IDFGH-7891)
2022-07-25 08:26:10 +02:00
415e04a55f fix(mdns): ignore authoritative flag on reception 2022-07-22 22:25:08 +08:00
3456781494 websocket: updated example to show json data transfer 2022-07-21 16:04:58 +04:00
d1129f3d19 esp_err_to_name (IDFGH-7793) (#78)
fix(esp-modem): Use err_to_name to log error message on error
2022-07-18 17:08:15 +02:00
973837dd66 Merge pull request #92 from david-cermak/feat/mdns_explicit_deps
feat(mdns): Define explicit dependencies on esp-wifi
2022-07-18 17:05:44 +02:00
36de9afe0c feat(mdns): Define explicit dependencies on esp-wifi 2022-07-18 09:49:03 +02:00
0d5081b841 Merge pull request #81 from lcj446068124/bugfix/mdns_ipv6_convert_error
bugfix: mdns IPv6 address convert error (IDFGH-7772)
2022-07-15 08:13:06 +02:00
85c7282641 Merge pull request #91 from Lapshin/feature/bump-versions
Bump asio/mdns/esp_websocket_client versions
2022-07-15 07:13:35 +02:00
238ee96783 bugfix: mdns IPv6 address convert error
In this fix, we manually convert esp_ip_addr_t to ip_addr_t.
2022-07-14 23:40:08 +08:00
20 changed files with 103 additions and 16 deletions

View File

@ -23,7 +23,7 @@ jobs:
container: espressif/idf:${{ matrix.idf_ver }}
steps:
- name: Checkout esp-protocols
uses: actions/checkout@master
uses: actions/checkout@v3
with:
path: esp-protocols
- name: Build ${{ matrix.example }} with IDF-${{ matrix.idf_ver }} for ${{ matrix.idf_target }}

View File

@ -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
)

View File

@ -11,9 +11,10 @@ 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}
"src/esp_modem_dte.cpp"
"src/esp_modem_dce.cpp"
@ -34,12 +35,14 @@ idf_component_register(SRCS "${srcs}"
PRIV_INCLUDE_DIRS private_include
REQUIRES ${dependencies})
set_target_properties(${COMPONENT_LIB} PROPERTIES
CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON
CXX_EXTENSIONS ON
)
if(${target} STREQUAL "linux")
# This is needed for ESP_LOGx() macros, as integer formats differ on ESP32(..) and x64
set_target_properties(${COMPONENT_LIB} PROPERTIES COMPILE_FLAGS -Wno-format)

View File

@ -7,3 +7,4 @@ endif()
idf_component_register(SRCS "ap_to_pppos.c"
${NETWORK_DCE}
INCLUDE_DIRS ".")
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")

View File

@ -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);

View File

@ -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);
}

View File

@ -1,4 +1,4 @@
version: "0.1.18"
version: "0.1.19"
description: esp modem
url: https://github.com/espressif/esp-protocols/tree/master/components/esp_modem
dependencies:

View File

@ -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)

View File

@ -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;
}

View File

@ -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

View File

@ -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; \
}

View File

@ -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")

View File

@ -23,6 +23,7 @@
#include "esp_log.h"
#include "esp_websocket_client.h"
#include "esp_event.h"
#include <cJSON.h>
#define NO_DATA_TIMEOUT_SEC 5
@ -74,6 +75,19 @@ static void websocket_event_handler(void *handler_args, esp_event_base_t base, i
} else {
ESP_LOGW(TAG, "Received=%.*s", data->data_len, (char *)data->data_ptr);
}
// If received data contains json structure it succeed to parse
cJSON *root = cJSON_Parse(data->data_ptr);
if (root) {
for (int i = 0 ; i < cJSON_GetArraySize(root) ; i++) {
cJSON *elem = cJSON_GetArrayItem(root, i);
cJSON *id = cJSON_GetObjectItem(elem, "id");
cJSON *name = cJSON_GetObjectItem(elem, "name");
ESP_LOGW(TAG, "Json={'id': '%s', 'name': '%s'}", id->valuestring, name->valuestring);
}
cJSON_Delete(root);
}
ESP_LOGW(TAG, "Total payload length=%d, data_len=%d, current payload offset=%d\r\n", data->payload_len, data->data_len, data->payload_offset);
xTimerReset(shutdown_signal_timer, portMAX_DELAY);

View File

@ -6,6 +6,8 @@ import string
from threading import Event, Thread
import pytest
import sys
import json
import time
from SimpleWebSocketServer import SimpleWebSocketServer, WebSocket
from pytest_embedded import Dut
@ -81,8 +83,33 @@ def test_examples_protocol_websocket(dut):
def test_close(dut):
code = dut.expect(re.compile(b'WEBSOCKET: Received closed message with code=(\\d*)'))[0]
print('Received close frame with code {}'.format(code))
def test_json(dut, websocket):
json_string = """
[
{
"id":"1",
"name":"user1"
},
{
"id":"2",
"name":"user2"
}
]
"""
websocket.send_data(json_string)
data = json.loads(json_string)
match = dut.expect(re.compile(b'Json=([a-zA-Z0-9]*).*')).group(0).decode()[5:]
if match == str(data[0]):
print('Sent message and received message are equal')
else:
raise ValueError('DUT received string do not match sent string, \nexpected: {}\nwith length {}\
\nreceived: {}\nwith length {}'.format(data[0], len(data[0]), match, len(match)))
def test_recv_long_msg(dut, websocket, msg_len, repeats):
send_msg = ''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in range(msg_len))
for _ in range(repeats):
@ -121,6 +148,7 @@ def test_examples_protocol_websocket(dut):
test_echo(dut)
# Message length should exceed DUT's buffer size to test fragmentation, default is 1024 byte
test_recv_long_msg(dut, ws, 2000, 3)
test_json(dut, ws)
test_close(dut)
else:
print('DUT connecting to {}'.format(uri))

View File

@ -1,4 +1,4 @@
version: "0.0.2"
version: "0.0.3"
description: esp websocket client
dependencies:
idf:

View File

@ -10,7 +10,7 @@ if(${target} STREQUAL "linux")
set(srcs "mdns.c" ${MDNS_NETWORKING})
else()
set(dependencies lwip console esp_netif)
set(private_dependencies esp_timer)
set(private_dependencies esp_timer esp_wifi)
set(srcs "mdns.c" ${MDNS_NETWORKING} "mdns_console.c")
endif()

View File

@ -1,4 +1,4 @@
version: "1.0.4"
version: "1.0.5"
description: mDNS
dependencies:
idf:

View File

@ -20,6 +20,8 @@
#if CONFIG_ETH_ENABLED
#include "esp_eth.h"
#endif
#include "esp_wifi.h"
#ifdef MDNS_ENABLE_DEBUG
void mdns_debug_packet(const uint8_t * data, size_t len);
@ -3497,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;
}

View File

@ -338,11 +338,15 @@ size_t _mdns_udp_pcb_write(mdns_if_t tcpip_if, mdns_ip_protocol_t ip_protocol, c
}
memcpy((uint8_t *)pbt->payload, data, len);
ip_addr_t ip_add_copy;
ip_add_copy.type = ip->type;
memcpy(&(ip_add_copy.u_addr),&(ip->u_addr),sizeof(ip_add_copy.u_addr));
mdns_api_call_t msg = {
.tcpip_if = tcpip_if,
.ip_protocol = ip_protocol,
.pbt = pbt,
.ip = (ip_addr_t *)ip,
.ip = &ip_add_copy,
.port = port
};
tcpip_api_call(_mdns_udp_pcb_write_api, &msg.call);

View File

@ -1,2 +1,3 @@
idf_component_register(SRCS "main.c" "mdns_test.c"
INCLUDE_DIRS ".")
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")