mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-03 03:31:41 +03:00
ci(mqtt): use QoS=1 for control messages in SSL test
SSL test relies on the device receiving a control message during the test, which was being sent with QoS=0. Send the control message with QoS=1 to avoid failures due to poor network connection.
This commit is contained in:
@@ -46,7 +46,7 @@ static void send_binary(esp_mqtt_client_handle_t client)
|
|||||||
esp_partition_mmap(partition, 0, partition->size, ESP_PARTITION_MMAP_DATA, &binary_address, &out_handle);
|
esp_partition_mmap(partition, 0, partition->size, ESP_PARTITION_MMAP_DATA, &binary_address, &out_handle);
|
||||||
// sending only the configured portion of the partition (if it's less than the partition size)
|
// sending only the configured portion of the partition (if it's less than the partition size)
|
||||||
int binary_size = MIN(CONFIG_BROKER_BIN_SIZE_TO_SEND, partition->size);
|
int binary_size = MIN(CONFIG_BROKER_BIN_SIZE_TO_SEND, partition->size);
|
||||||
int msg_id = esp_mqtt_client_publish(client, "/topic/binary", binary_address, binary_size, 0, 0);
|
int msg_id = esp_mqtt_client_publish(client, "/topic/binary", binary_address, binary_size, 1, 0);
|
||||||
ESP_LOGI(TAG, "binary sent with msg_id=%d", msg_id);
|
ESP_LOGI(TAG, "binary sent with msg_id=%d", msg_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,6 +69,8 @@ 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");
|
||||||
|
esp_mqtt_client_subscribe(client, "/topic/binary", 1);
|
||||||
|
|
||||||
msg_id = esp_mqtt_client_subscribe(client, "/topic/qos0", 0);
|
msg_id = esp_mqtt_client_subscribe(client, "/topic/qos0", 0);
|
||||||
ESP_LOGI(TAG, "sent subscribe successful, msg_id=%d", msg_id);
|
ESP_LOGI(TAG, "sent subscribe successful, msg_id=%d", msg_id);
|
||||||
|
|
||||||
@@ -126,7 +128,8 @@ static void mqtt_app_start(void)
|
|||||||
const esp_mqtt_client_config_t mqtt_cfg = {
|
const esp_mqtt_client_config_t mqtt_cfg = {
|
||||||
.broker = {
|
.broker = {
|
||||||
.address.uri = CONFIG_BROKER_URI,
|
.address.uri = CONFIG_BROKER_URI,
|
||||||
.verification.certificate = (const char *)mqtt_eclipseprojects_io_pem_start
|
.verification.certificate = (const char *)mqtt_eclipseprojects_io_pem_start,
|
||||||
|
.verification.skip_cert_common_name_check = true
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ from pytest_embedded import Dut
|
|||||||
|
|
||||||
event_client_connected = Event()
|
event_client_connected = Event()
|
||||||
event_stop_client = Event()
|
event_stop_client = Event()
|
||||||
|
event_client_connected_to_topic_binary = Event()
|
||||||
event_client_received_correct = Event()
|
event_client_received_correct = Event()
|
||||||
event_client_received_binary = Event()
|
event_client_received_binary = Event()
|
||||||
message_log = ''
|
message_log = ''
|
||||||
@@ -36,14 +37,15 @@ def mqtt_client_task(client): # type: (mqtt.Client) -> None
|
|||||||
# The callback for when a PUBLISH message is received from the server.
|
# The callback for when a PUBLISH message is received from the server.
|
||||||
def on_message(client, userdata, msg): # type: (mqtt.Client, tuple, mqtt.client.MQTTMessage) -> None
|
def on_message(client, userdata, msg): # type: (mqtt.Client, tuple, mqtt.client.MQTTMessage) -> None
|
||||||
global message_log
|
global message_log
|
||||||
|
global event_client_connected_to_topic_binary
|
||||||
global event_client_received_correct
|
global event_client_received_correct
|
||||||
global event_client_received_binary
|
global event_client_received_binary
|
||||||
if msg.topic == '/topic/binary':
|
if msg.topic == '/topic/binary':
|
||||||
binary, bin_size = userdata
|
binary, bin_size = userdata
|
||||||
print('Receiving binary from esp and comparing with {}, size {}...'.format(binary, bin_size))
|
print('Receiving binary from esp and comparing with {}, size {}...'.format(binary, bin_size))
|
||||||
with open(binary, 'rb') as f:
|
with open(binary, 'rb') as f:
|
||||||
bin = f.read()
|
binary_reference = f.read()
|
||||||
if bin[:bin_size] == msg.payload[:bin_size]:
|
if binary_reference[:bin_size] == msg.payload[:bin_size]:
|
||||||
print('...matches!')
|
print('...matches!')
|
||||||
event_client_received_binary.set()
|
event_client_received_binary.set()
|
||||||
return
|
return
|
||||||
@@ -53,9 +55,13 @@ def on_message(client, userdata, msg): # type: (mqtt.Client, tuple, mqtt.client
|
|||||||
raise ValueError('Received binary (saved as: {}) does not match the original file: {}'.format(recv_binary, binary))
|
raise ValueError('Received binary (saved as: {}) does not match the original file: {}'.format(recv_binary, binary))
|
||||||
|
|
||||||
payload = msg.payload.decode()
|
payload = msg.payload.decode()
|
||||||
if not event_client_received_correct.is_set() and payload == 'data':
|
if (
|
||||||
client.subscribe('/topic/binary')
|
event_client_connected_to_topic_binary.is_set()
|
||||||
client.publish('/topic/qos0', 'send binary please')
|
and not event_client_received_correct.is_set()
|
||||||
|
and payload == 'data'
|
||||||
|
):
|
||||||
|
client.publish('/topic/binary', 'send binary please', qos=1)
|
||||||
|
client.subscribe('/topic/binary', qos=1)
|
||||||
if msg.topic == '/topic/qos0' and payload == 'data':
|
if msg.topic == '/topic/qos0' and payload == 'data':
|
||||||
event_client_received_correct.set()
|
event_client_received_correct.set()
|
||||||
message_log += 'Received data:' + msg.topic + ' ' + payload + '\n'
|
message_log += 'Received data:' + msg.topic + ' ' + payload + '\n'
|
||||||
@@ -117,6 +123,19 @@ def test_examples_protocol_mqtt_ssl(dut): # type: (Dut) -> None
|
|||||||
except pexpect.TIMEOUT:
|
except pexpect.TIMEOUT:
|
||||||
print('ENV_TEST_FAILURE: Cannot connect to AP')
|
print('ENV_TEST_FAILURE: Cannot connect to AP')
|
||||||
raise
|
raise
|
||||||
|
try:
|
||||||
|
dut.expect(r'MQTT_EVENT_CONNECTED', timeout=120)
|
||||||
|
# SSL example subscribes to topics /topic/binary, /topic/qos0, and /topic/qos1
|
||||||
|
# We do not want to introduce any logs related to /topic/binary, so we will
|
||||||
|
# wait for all three MQTT_EVENT_SUBSCRIBED to be processed
|
||||||
|
for i in range(3):
|
||||||
|
dut.expect(r'MQTT_EVENT_SUBSCRIBED, msg_id=(\d+)')
|
||||||
|
|
||||||
|
event_client_connected_to_topic_binary.set()
|
||||||
|
|
||||||
|
except pexpect.TIMEOUT:
|
||||||
|
print('ENV_TEST_FAILURE: Client cannot connect to the broker {}:{}.'.format(broker_url, broker_port))
|
||||||
|
raise
|
||||||
print('Checking py-client received msg published from esp...')
|
print('Checking py-client received msg published from esp...')
|
||||||
if not event_client_received_correct.wait(timeout=30):
|
if not event_client_received_correct.wait(timeout=30):
|
||||||
raise ValueError('Wrong data received, msg log: {}'.format(message_log))
|
raise ValueError('Wrong data received, msg log: {}'.format(message_log))
|
||||||
|
|||||||
Reference in New Issue
Block a user