October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk1 min

Can You Build a TCP-over-MQTT Proxy with an ESP32?

ESP-MQTT provides broker messaging, not a ready-made TCP proxy. Learn what custom software a TCP-over-MQTT tunnel needs and how to plan an ESP32 implementation.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Yes, but not with an MQTT client alone. An ESP32 can connect to an MQTT broker over TCP and exchange messages. To tunnel an arbitrary TCP connection through MQTT, you must also build software that packages the byte stream into MQTT messages and reconstructs it at the other end. Espressif’s MQTT example demonstrates broker messaging, not a ready-made TCP proxy.

What “MQTT over TCP” means—and what it does not

MQTT is a publish/subscribe messaging protocol. An MQTT client opens a network connection to a broker—often using TCP—and publishes or receives application messages through it. In this arrangement, TCP carries the MQTT protocol between the ESP32 and the broker; the messages carry application data.

As an Amazon Associate I earn from qualifying purchases.

A TCP proxy over MQTT is a different layer of software. It must accept or create a TCP connection at one end, split the stream into messages, send those messages through MQTT, then rebuild the ordered byte stream and deliver it to a TCP connection at the other end. The broker routes messages; it does not automatically forward arbitrary TCP connections.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Ordinary MQTT client:      ESP32 -- MQTT over TCP --> Broker <-- MQTT over TCP -- Other client

Custom TCP tunnel:         TCP app <-- local proxy -- ESP32 == framed MQTT messages == Broker
                                                                                   |
                                                        remote tunnel endpoint -- TCP app

The equal signs represent an application-level tunnel you would have to implement. The ESP32 MQTT client component supplies MQTT messaging, not the framing, stream reconstruction, or proxy endpoints.

#1 Best Overall
ESP-WROOM-32 ESP32 ESP-32S Development Board 2.4GHz Dual-Mode WiFi + Bluetooth Dual Cores Microcontroller Processor Integrated with Antenna RF AMP Filter AP STA Compatible with Arduino IDE (3PCS)
  • 2.4GHz Dual Mode WiFi + Bluetooth Development Board
  • Support LWIP protocol, Freertos
  • SupportThree Modes: AP, STA, and AP+STA
  • Ultra-Low power consumption, Compatible with Arduino IDE
  • ESP32 is a safe, reliable, and scalable to a variety of applications

What Espressif’s documentation supports

Espressif describes ESP-MQTT as an MQTT protocol client. Its current ESP-IDF stable documentation says ESP-MQTT supports MQTT v5.0 and notes that, starting with ESP-IDF v6.0, the component is no longer included in ESP-IDF itself; users should add the espressif/mqtt component.

Espressif’s MQTT TCP example, identified as ESP-IDF v5.5.0, demonstrates configuring an ESP32 MQTT client, connecting to a broker over TCP, handling connection status, and sending and receiving messages. It also requires network connectivity to be provisioned through Wi-Fi, Ethernet, or Thread. The example is a useful starting point for the broker-client portion of a project, but it does not demonstrate a transparent TCP tunnel. Its English page is marked as in progress and automatically translated.

Rank #2
ELEGOO 3PCS ESP-32 Dev Boards, ESP-WROOM-32, USB-C, WiFi Bluetooth 4.2
  • Dual-Core Performance Up to 240 MHz: Run sensor processing, wireless communication, automation logic and connected-device tasks on a 32-bit dual-core ESP32 platform designed for responsive embedded and IoT projects
  • Built-in Wi-Fi and Bluetooth 4.2: Connect to 2.4 GHz Wi-Fi networks or use Bluetooth Classic and BLE for wireless sensors, smart devices, remote controls, home automation and other connected projects
  • Flexible Power-Saving Modes: ESP32 power-management features support dynamic clock scaling and low-power operating modes, helping developers reduce energy use in compatible sensing, monitoring and connected-device applications, suitable for battery-powered Internet of Things (IoT) devices.
  • USB-C Programming with CP2102: Connect through USB-C for power, sketch uploads and serial monitoring, while GPIO, UART, SPI and I2C interfaces support sensors, displays, motor drivers and other modules (USB-C cable not included)
  • Over-the-Air Update Support: Configure OTA functionality through a compatible ESP-32 software framework to update deployed firmware over Wi-Fi without reconnecting the board by USB for every revision

Espressif’s ESP-AT MQTT examples likewise show MQTT messaging with an ESP32 and a broker, not general-purpose TCP forwarding. The older ESP-IDF v4.4 guide documents MQTT over TCP, TLS, WebSocket, and secure WebSocket. Its example ports—1883 for TCP, 8883 for TLS, 80 for WebSocket, and 443 for secure WebSocket—are version-specific examples, not universal requirements.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose the design that matches your goal

Goal or transport What it does What you must account for
MQTT messaging over TCP An ESP32 publishes and receives application messages through a broker connection. Broker reachability, credentials, client connection state, and the application’s message format.
MQTT over TLS MQTT uses a TLS-protected connection to the broker. Configure and verify certificates and authentication using the API and component version you deploy. A secure broker connection does not, by itself, define tunnel behavior.
MQTT over WebSocket or secure WebSocket MQTT is carried over WebSocket, sometimes useful where a network or service expects WebSocket traffic. Confirm that the broker and network permit the chosen transport, and verify supported configuration against your ESP-MQTT version.
TCP stream tunneled through MQTT Custom software maps bytes from a TCP stream to MQTT messages and reconstructs them at a remote endpoint. In addition to the MQTT transport, design framing, buffering, flow control, session identity, reconnect behavior, and access controls.

Use MQTT messaging if the devices only need to exchange defined commands, readings, or events; it avoids pretending those messages are a generic TCP connection. Consider a tunnel only when an application genuinely requires a byte stream and both tunnel endpoints can run the additional software. A tunnel built over MQTT should not be described as transparent until its behavior for connection setup, half-closed connections, errors, and reconnects is defined.

Rank #3
ELEGOO ESP-32 Super Starter Kit with Tutorial Compatible with Arduino IDE
  • Powerful ESP-32 Board: Unlock the world of Internet of Things (IoT) and advanced electronics with the heart of this kit: the ESP-32 board. It features a powerful dual-core processor, integrated Wi-Fi and Bluetooth 4.2, making it perfect for building connected, smart devices that communicate with your phone or the cloud. It's fully compatible with the Arduino IDE for easy programming.
  • Super Starter Kit: This kit contains over 35 different modules and electronic components, including sensors, displays, motors, and input devices. From LEDs and buttons to an OLED screen, servo motor, and keypad, you have everything needed to explore a vast range of projects in one box.
  • Step by Step Online Tutorial: Jump right in with our detailed, beginner-friendly tutorial. Access 30+ projects with complete code, clear circuit diagrams, and step-by-step instructions. Learn the fundamentals of electronics, coding, and how to utilize the ESP-32's unique capabilities without any prior experience.
  • Hands-on Learning for All Skill Levels: Perfect for students, makers, engineers, and hobbyists. Start with basic circuits and coding, then progress to intermediate and advanced IoT applications. Build practical projects like weather stations, smart home controllers, remote-controlled devices, and interactive gadgets. The skills you learn are the foundation for real-world innovation.
  • Quality & Great Support: Elegoo is committed to quality. We provide a clear, detailed tutorial guide, refined code, and a well-organized component kit. All modules are carefully selected for reliability and ease of use. Our dedicated technical support team and active online community are ready to help you succeed in your learning journey.

How to design a TCP stream carried in MQTT

TCP presents an ordered byte stream, not a sequence of application messages. A read can return part of a logical message, several logical messages, or any other available chunk. MQTT publishes discrete payloads. Your tunnel therefore needs its own protocol to associate messages with a connection and place each payload’s bytes correctly.

Define a frame format

One reasonable design is to include a protocol version, connection identifier, direction, sequence number, frame type, and byte payload in each tunnel message. Control frames can represent opening a connection, acknowledging it, reporting an error, and closing it; data frames carry bytes. This is a design example, not a format supplied by Espressif.

Rank #4
ESP-WROOM-32 ESP32 ESP-32S Development Board 2.4GHz Dual-Mode WiFi + Bluetooth Dual Cores Microcontroller Processor Integrated with Antenna RF AMP Filter AP STA Compatible with Arduino IDE (1 PCS)
  • 2.4GHz Dual Mode WiFi + Bluetooth Development Board
  • Support LWIP protocol, Freertos;ESP32 is a safe, reliable, and scalable to a variety of applications
  • SupportThree Modes: AP, STA, and AP+STA
  • Ultra-Low power consumption, Compatible with Arduino IDE
  • 1PCS 30Pin ESP32 Development Board 2.4GHz WiFi Dual Cores Microcontroller Integrated with Antenna RF Low Noise Amplifiers Filters

Choose explicit limits for frame and payload size. MQTT and the broker impose message-size limits that depend on their configuration and implementation. Keep frames below the smallest applicable limit, allowing room for your own metadata. If a TCP read returns more data than fits, split it across frames; if it returns less, send what is available or buffer it according to your latency and memory requirements.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Preserve stream order and apply backpressure

Reassemble data in the correct order for each tunnel connection. MQTT QoS controls delivery behavior for individual MQTT publications; it does not replace TCP stream semantics or automatically provide your tunnel with a correct flow-control design. Define what happens when messages are delayed, duplicated, lost after a session break, or received out of order.

Best Value
HiLetgo ESP-WROOM-32 ESP32 ESP-32S Development Board 2.4GHz Dual-Mode WiFi + Bluetooth Dual Cores Microcontroller Processor Integrated with Antenna RF AMP Filter AP STA for Arduino IDE
  • 2.4GHz Dual Mode WiFi + Bluetooth Development Board
  • Ultra-Low power consumption, works perfectly with the Arduino IDE
  • Support LWIP protocol, Freertos
  • SupportThree Modes: AP, STA, and AP+STA
  • ESP32 is a safe, reliable, and scalable to a variety of applications

Bound every queue. If the receiving TCP socket or the broker cannot keep up, the tunnel must slow the sender, buffer only up to a defined limit, or close the connection cleanly. Unbounded buffering can exhaust a microcontroller’s memory. The ESP32’s actual capacity depends on the chosen module, firmware, network conditions, and implementation; the cited examples do not establish tunnel throughput, latency, concurrency, or reliability.

Keep connection identity and recovery explicit

Give each tunnel connection a unique identifier and ensure both endpoints agree on which MQTT topics or messages belong to it. Define how identifiers are created, authorized, and retired. After a disconnect, do not assume that reconnecting the MQTT client restores the underlying TCP stream. Choose whether to discard and recreate the proxied connection, resume it using explicit sequence and session state, or report failure to the local application.

Protect the tunnel, not just the broker login

Restrict which clients may publish to and subscribe to tunnel topics, and authorize access to each proxied destination. Otherwise a client allowed to publish tunnel data could potentially try to reach services the tunnel host can access. Use TLS with certificate verification when the network threat model requires protection between the ESP32 and broker. If the broker should not be able to read tunnel contents, add a separately designed end-to-end encryption layer; TLS terminating at the broker does not provide that property.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

A practical implementation path

  1. Choose the ESP-IDF and MQTT component version. For ESP-IDF v6.0 and later, follow the current ESP-MQTT component instructions and add espressif/mqtt. For an older SDK, use documentation and APIs matching that release rather than copying current instructions unchanged.
  2. Prove ordinary broker messaging first. Provision Wi-Fi, Ethernet, or Thread, configure the broker connection, and verify that the ESP32 can publish and receive messages and handle connection-state events. Espressif’s MQTT TCP example is relevant to this stage.
  3. Choose the broker transport and security configuration. Use TCP, TLS, WebSocket, or secure WebSocket according to broker support and network requirements. Configure authentication and certificate verification as appropriate, checking the selected component’s API and the broker’s settings.
  4. Implement the remote endpoint and frame protocol. Decide how the other end accepts or initiates TCP connections, encodes control and data frames, identifies sessions, and handles size limits. MQTT alone does not supply this part.
  5. Test failure and load behavior on the actual deployment. Measure latency, throughput, memory use, and the number of simultaneous connections with the chosen ESP32 variant, broker configuration, network, and firmware. Test broker loss, network interruption, slow readers, oversized frames, and unauthorized destinations before relying on the tunnel.

What “cheap ESP32” can—and cannot—tell you

The project can use an ESP32 development board, but the cited documentation does not identify a particular retail model, establish a current price, or compare board costs. Nor does it establish the performance of a generic TCP-over-MQTT proxy. If selecting a board, check the exact ESP32 variant, exposed pins, USB interface, power requirements, and documentation for that board revision; then test the intended workload rather than inferring capacity from the word “ESP32.”

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.