Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MQTT Sensors Not Receiving Data #818

Closed
dkaser opened this issue Feb 21, 2024 · 3 comments
Closed

MQTT Sensors Not Receiving Data #818

dkaser opened this issue Feb 21, 2024 · 3 comments
Labels

Comments

@dkaser
Copy link

dkaser commented Feb 21, 2024

What happened

I have configured a MQTT server and associated sensors in my moonraker configuration. However, the sensors do not receive data.

Symptoms:

  • MQTT data is not displayed in the frontend (Fluidd).
  • MQTT measurements are not available via the Moonraker API:
curl http://127.0.0.1:7125/server/sensors/info?sensor=esp32_temp
{"result": {"id": "esp32_temp", "friendly_name": "Enclosure Temperature", "type": "mqtt", "values": {}}}
curl http://127.0.0.1:7125/server/sensors/measurements?sensor=esp32_temp
{"result": {"esp32_temp": {}}}

Troubleshooting performed:

  • Verified that moonraker is connected to the broker (EMQX).
    • moonraker states are being published to the broker
    • EMQX shows that the moonraker client is subscribed to the sensor (esphome/3d-printer/sensor/3d_printer_light_bme280_temperature/state
  • Verified that EMQX is sending state updates for the sensor
    • "TCP Packets Sent" for the moonraker client increases at the frequency of the sensor.
  • Verified that the moonraker client has permission to the MQTT topic
    • Configured separate MQTT client with identical settings (server, port, credentials, MQTT version, subscriptions). This MQTT client shows the state updates.
    • Compared the standalone client to the moonraker client in EMQX, they appear identical aside from client ID/IP.
  • Tried MQTT protocol v3.1.1 and v5; both experience the problem.

Client

Mainsail, Fluidd, Other

Browser

Other or N/A

How to reproduce

  1. Configure MQTT and sensor (see sample configuration below)
  2. Attempt to view sensor data via frontend or API

Additional information

MQTT/sensor configuration:

[mqtt]
address: a.b.c.d
port: 1883
username: {secrets.mqtt.username}
password: {secrets.mqtt.password}
enable_moonraker_api: False
instance_name: moonraker
publish_split_status: True
mqtt_protocol: v5
status_objects:
  webhooks
  extruder
  heater_bed
  print_stats

[sensor esp32_temp]
type: mqtt
name: Enclosure Temperature
state_topic: esphome/3d-printer/sensor/3d_printer_light_bme280_temperature/state
@dkaser dkaser added the bug Something isn't working label Feb 21, 2024
@Arksine Arksine added user help request and removed bug Something isn't working labels Feb 22, 2024
@Arksine
Copy link
Owner

Arksine commented Feb 22, 2024

You need to configure the state_response_template per the documentation. The template is used to set/update fields exposed by the sensor.

@dkaser
Copy link
Author

dkaser commented Feb 24, 2024

OK. I tried that and it worked.

It might be worth clarifying in the documentation that state_response_template is a required parameter. The MQTT topics that I was collecting are numeric, so I interpreted this statement as meaning that I didn't need the option:

The default is the payload.

In contrast, state_topic says:

This parameter must be provided.

@Arksine
Copy link
Owner

Arksine commented Feb 24, 2024

You are correct here, there shouldn't be a default and I missed that when I reviewed the contribution. I have made this change in 0850c16.

@Arksine Arksine added the resolved Issue is resolved label Mar 9, 2024
@Arksine Arksine closed this as completed Mar 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants