---
title: "W5100S MQTT Yield 문의"
url: "https://maker.wiznet.io/forum/9452"
markdown_url: "https://maker.wiznet.io/forum/9452/md"
type: "Forum topic"
category: "Ethernet Chips"
author: "kcchang61"
created: "2024-09-05T08:13:31+09:00"
last_activity: "2024-10-17T16:03:20+09:00"
language: "ko"
tags: ["MQTT"]
views: 8
replies: 3
source: "WIZnet Makers forum (https://maker.wiznet.io/forum/)"
---

# W5100S MQTT Yield 문의

## Question

Asked by kcchang61 on 2024-09-05 in Ethernet Chips.

W5100S_EVB_Pico를 이용하여 AWS MQTT를 개발중입니다. 그런데 가입한 Topic을 수신하기 위해서는 mqtt_transport_yield 을 Call 해야 하는 것 같은데, 문제는 Topic이 없을때 이 함수가 무조건 10초를 잡아 먹기 때문에 Publish를 하지 못하는 현상이 나타납니다.

이 부분의 해결 방법이 없는지, 확인 부탁합니다.

## Replies

### Reply 1 by matthew, 2024-09-05

안녕하세요. 어떤 환경에서 어느 라이브러리를 사용하여 개발 중인지 알 수 있을까요?

### Reply 2 by TheoIm, 2024-09-12

The issue you're facing is that the `mqtt_transport_yield` function blocks for a significant amount of time (10 seconds) when there are no incoming messages on the subscribed topic, preventing you from publishing messages during this period.

To address this issue, you can modify the implementation to reduce the blocking time. Here are some approaches:

**Reduce the Timeout Duration**: Adjust the timeout value for the `mqtt_transport_yield` call to a shorter period. This will allow the function to return control more quickly, enabling you to perform other tasks such as publishing.

c

코드 복사

`int MQTTYield(MQTTClient* c, int timeout_ms) `

`{ `

`int rc = SUCCESSS; `

`Timer timer; `

`TimerInit(&timer); `

`TimerCountdownMS(&timer, timeout_ms); // Consider using a smaller timeout value `

`int cycle_timeout_ms = 100; // Adjust this value as needed `

`while (!TimerIsExpired(&timer)) { `

`if (cycle(c, &timer) == FAILURE) { `

`rc = FAILURE; `

`break; `

`} `

`// Adjust cycle timing to avoid blocking for too long `

`TimerCountdownMS(&timer, cycle_timeout_ms); `

`} `

`return rc; `

`}`

**Non-Blocking Calls**: If reducing the timeout is not sufficient, consider using non-blocking I/O or implementing a mechanism to check for messages without blocking. This may require modifying the MQTT library to support non-blocking operations.

**Background Task**: Offload the MQTT yield process to a background task or a separate thread, allowing the main thread to handle publishing. This way, the main thread remains responsive, and you can still receive messages in the background.

c

코드 복사

`// Example of running the yield in a separate thread `

`void* mqtt_yield_task(void* arg) { `

`MQTTClient* client = (MQTTClient*)arg; `

`while (1) { `

`MQTTYield(client, 100); // Run with a short timeout `

`} `

`return NULL; `

`} // In the main function, start the background task `

`pthread_t thread; `

`pthread_create(&thread, NULL, mqtt_yield_task, (void*)&client); // The main thread can now handle publishing`

**Manual Message Handling**: Instead of relying on `mqtt_transport_yield` for processing, you can implement manual message handling by periodically calling a non-blocking version of `cycle`. This allows you to control when and how long to check for messages.

If none of these options fully resolve the issue, you may need to delve deeper into the MQTT library to optimize or customize the behavior according to your specific needs.

### Reply 3 by pmjqpt, 2024-10-17

SSL_RECV_TIMEOUT 이 값을 변경해보세요. MQTT timeout 값만 변경해도 안되었는데 이 값 변경하니까 저는 해결되었습니다

---

Source: https://maker.wiznet.io/forum/9452
