DEV Community

Fastbee
Fastbee

Posted on

ESP32/ESP8266: Debug Missing MQTT Commands with MQTTX

Reproduce remote-control failures in a Docker test environment. Use MQTTX as the device first, then repeat the checks on an ESP32 or ESP8266.

Cover Image

Short answer MQTT telemetry and control commands use separate topics. First verify the device's downlink subscription and observe a fresh command arriving. Then check a separate reported state value. This tells you whether to investigate command delivery, firmware execution, or the return path.

For Developers with Docker and MQTT basics who need to diagnose remote control on an ESP32 or ESP8266.
Edition The examples use FastBee Community Edition v2 topic, authentication, and payload conventions. MQTTX simulates the device before the hardware check.

1. Prepare a Docker test environment

Deploy the Community Edition on a reachable test host using the installation guide. The platform includes an MQTT broker. Open the console and check that the product and device views are available, then inspect the running containers. Use a test network and dedicated device credentials. Community Edition Docker deployment

docker ps
Enter fullscreen mode Exit fullscreen mode

Have MQTTX and a test ESP32 or ESP8266 available. Switch between MQTTX and the board one at a time when using the same test device identity. Use a server address reachable from the client.

2. Separate the control request from reported output

Create an MQTT product and add these two Boolean properties to its Thing Model. Publish the model and product, create a device under that product, and record the real product ID, device number, user ID, and MQTT credentials. After changing the model, republish it and reconnect an already connected client. Product configuration · Thing Model properties

Identifier Access Purpose
switch Read/write The console uses it to request on or off.
output_state Read-only The device uses it to report simulated or observed output.

Check the timestamp and latest log entry when you inspect output_state. An earlier 1 can belong to a previous test. The control button shows the value requested for this test.

3. Connect MQTTX and establish a baseline

Use MQTT 3.1.1 and the documented simple authentication mode on the test network. Enter the test host in MQTTX and use the configured TCP port, 1883 by default. Set the Client ID to S&DEVICE_NUM&PRODUCT_ID&USER_ID, replacing all three placeholders with actual values. Fill in the device's MQTT credentials. If device authorization codes are enabled, format the password as specified in the protocol guide. MQTT authentication, topics, and payloads

Replace the placeholders in the topics as well. Wait for the downlink subscription to succeed, then send device information and the initial property values. SUBSCRIBE and PUBLISH identify the operation. Enter only the path as the topic.

SUBSCRIBE  /PRODUCT_ID/DEVICE_NUM/function/get
PUBLISH    /PRODUCT_ID/DEVICE_NUM/info/post
PUBLISH    /PRODUCT_ID/DEVICE_NUM/property/post
Enter fullscreen mode Exit fullscreen mode

Publish this JSON to the full /info/post topic first. Replace the example userId value of 1 with the numeric ID of your test user.

{
  "rssi": -43,
  "firmwareVersion": 1.2,
  "status": 3,
  "userId": 1,
  "longitude": 0,
  "latitude": 0,
  "summary": {"name": "MQTTX simulator", "chip": "virtual"}
}
Enter fullscreen mode Exit fullscreen mode

Then publish the initial properties to the full /property/post topic. The property payload is an array. Boolean values are strings, "0" or "1". Leave Retain disabled for this exercise so a subscriber does not see a message retained from an earlier test.

[
  {"id":"switch","value":"0","remark":"baseline"},
  {"id":"output_state","value":"0","remark":"simulated output off"}
]
Enter fullscreen mode Exit fullscreen mode

Confirm that the device view shows output_state as off and note its timestamp. If the state is missing, check the device's product, the reported identifier, the data type, and the logs before testing commands.

4. Run three tests to isolate the fault

![MQTT command and state flow: the console sends commands to MQTTX, and MQTTX reports output state to the platform

The arrows show the logical message directions. Both the command and state report travel through the MQTT broker.

Set switch to on in the device control view. MQTTX should receive an array like this on /function/get. The platform generates the remark, so check the id and value.

[{"id":"switch","value":"1","remark":"test command"}]
Enter fullscreen mode Exit fullscreen mode
Test What to do What to look for
1. Simulate a missing subscription Unsubscribe from the downlink, keep the client connected, and send a new on request. MQTTX receives no command for this attempt. Subscribe again and issue a fresh command to verify delivery.
2. Simulate delivery without execution Observe the new command, then publish a freshoutput_state="0" on the uplink. The downlink asks for on, and the device reports that the output is still off for this test.
3. Simulate execution and reporting Issue a fresh on request, then publishoutput_state="1" after it arrives. You can see the command, the new uplink state, and the console update in the same test.

Publish this payload to the full /property/post topic for test 2:

[{"id":"output_state","value":"0","remark":"simulated output did not change"}]
Enter fullscreen mode Exit fullscreen mode

Publish this payload to the same topic for test 3:

[{"id":"output_state","value":"1","remark":"simulated output is on"}]
Enter fullscreen mode Exit fullscreen mode

If your control view sends commands only when the requested value changes, send off and then on. Use the message timestamp to identify the latest on command. If MQTTX published the state but the console does not update, check the uplink topic, property ID, value type, and state logs. These tests simulate device behavior manually.

5. Repeat the checks on an ESP32 or ESP8266

Disconnect MQTTX before connecting the board. Use serial logs to track the connection, subscription, incoming command, and reported state. On an ESP32, follow the MQTT settings of the firmware you are running. On an ESP8266, use a client that implements the same topic and payload conventions. For general-purpose input/output (GPIO) testing, use an onboard LED or a low-voltage test circuit and check the pin assignment and active level for your board. Device-side MQTT configuration

Use this sequence in the firmware:

  1. Verify that the downlink subscription is active after each connection.
  2. Parse incoming arrays, find the switch entry, and accept the documented "0" and "1" values.
  3. Set the output, read whatever state feedback is available, and publish it as output_state. A GPIO readback confirms the pin or driver state. An external actuator needs its own feedback signal.
  4. Run one on test and one off test in sequence. Wait for the report before sending the next command, and compare serial logs, uplink messages, and console timestamps.

Check three pieces of evidence. A new downlink message shows the client received the command. A fresh uplink state shows what the device reported. The property update in the console shows that the platform processed that report.

Frequently asked questions

Does MQTT PUBACK confirm that the device acted?

PUBACK acknowledges QoS 1 delivery on one MQTT hop. To verify the action, check a fresh application-level output-state report from the device and make sure it belongs to the current test.

Why can the device publish telemetry but receive no MQTT commands?

Publishing and subscribing can use different topics and permissions. Confirm that the downlink subscription succeeded, that the topic uses the correct product ID and device number, and that the command was sent after subscribing. Check for another client using the same Client ID.

Does a command marked as sent mean the device executed it?

The send record shows that the platform issued the request. Check the device's command log and a fresh output-state report to see what happened on the device. For an external actuator, verify its feedback signal.

Why does the board still fail after the MQTTX test passes?

Compare connection and subscription settings first. Then check that firmware restores subscriptions after reconnecting, parses the array and string Boolean values, and uses the GPIO pin and active level for that board.

<!--
Publishing metadata and structured data
{"title":"ESP32/ESP8266: Debug Missing MQTT Commands with MQTTX","description":"Use MQTTX to reproduce missing MQTT commands on an ESP32 or ESP8266. Check downlink subscriptions, payload parsing, output state, and the return path."}

{
  "@context": "https://schema.org",
  "@graph": [
    {
      "@type": "TechArticle",
      "headline": "ESP32/ESP8266: Debug Missing MQTT Commands with MQTTX",
      "description": "Use MQTTX to reproduce missing MQTT commands on an ESP32 or ESP8266. Check downlink subscriptions, payload parsing, output state, and the return path.",
      "inLanguage": "en-US"
    },
    {
      "@type": "FAQPage",
      "mainEntity": [
        {
          "@type": "Question",
          "name": "Does MQTT PUBACK confirm that the device acted?",
          "acceptedAnswer": {
            "@type": "Answer",
            "text": "PUBACK acknowledges QoS 1 delivery on one MQTT hop. To verify the action, check a fresh application-level output-state report from the device and make sure it belongs to the current test."
          }
        },
        {
          "@type": "Question",
          "name": "Why can the device publish telemetry but receive no MQTT commands?",
          "acceptedAnswer": {
            "@type": "Answer",
            "text": "Publishing and subscribing can use different topics and permissions. Confirm that the downlink subscription succeeded, that the topic uses the correct product ID and device number, and that the command was sent after subscribing. Check for another client using the same Client ID."
          }
        },
        {
          "@type": "Question",
          "name": "Does a command marked as sent mean the device executed it?",
          "acceptedAnswer": {
            "@type": "Answer",
            "text": "The send record shows that the platform issued the request. Check the device's command log and a fresh output-state report to see what happened on the device. For an external actuator, verify its feedback signal."
          }
        },
        {
          "@type": "Question",
          "name": "Why does the board still fail after the MQTTX test passes?",
          "acceptedAnswer": {
            "@type": "Answer",
            "text": "Compare connection and subscription settings first. Then check that firmware restores subscriptions after reconnecting, parses the array and string Boolean values, and uses the GPIO pin and active level for that board."
          }
        }
      ]
    }
  ]
}
-->
Enter fullscreen mode Exit fullscreen mode

Top comments (0)