Troubleshooting
Why Flux mqtt.publish fails with Dialer.Dial in InfluxDB
Short answer
Dialer.Dial called on an error dependency means the Flux runtime executing the task supplied no working network dialer, so mqtt.publish fails before any TCP connection to the broker. Correct the script, 1883 is the MQTT listener and 18083 the EMQX dashboard port, publish each point once with range(start: -task.every) via mqtt.to, and if the same error returns, publish with Telegraf outputs.mqtt instead of Flux.
On this page
Dialer.Dial called on an error dependency is raised inside the Flux runtime, before any TCP connection to your broker exists: the mqtt.publish() call asked the runtime for a network dialer and received one that only returns an error, so no MQTT CONNECT, authentication or topic check ever happened. Fix the script first — 18083 is the EMQX dashboard port, not MQTT's 1883 — quote the password as a string, and publish each point once with range(start: -task.every) through mqtt.to() instead of per-row mqtt.publish(). If the corrected task still returns the same error, your build supplies no dialer to tasks at all, and the decision is to publish with Telegraf outputs.mqtt or an external bridge rather than keep editing Flux.
Where the request stops #
The run log shows runtime error @9:8-22:6: map: failed to evaluate map function: Dialer.Dial called on an error dependency. Read the position: the failure is inside the map function, while Flux evaluated mqtt.publish() for a row. The function requested a network dialer from the runtime's dependencies and got a stub that returns an error, so the request died inside the influxd process. Nothing left the host.
| Hop | What runs there | Where a failure here shows up |
|---|---|---|
| Task scheduler | fires the script every 1m | task run log |
| Flux runtime | evaluates map(), calls mqtt.publish() per row, requests a dialer |
this error |
| InfluxDB host network | DNS for the broker name, routing, firewall | not reached yet |
| Broker listener | TCP accept, MQTT CONNECT, authentication, ACL | not reached yet |
Treat the error as hop 2. Clear it first, then prove hops 3 and 4 with tools that have nothing to do with Flux.
Point the broker URL at an MQTT listener #
The failing script publishes to tcp://miservidor:18083. That port is not an MQTT listener by default:
| Port | What normally answers | Usable as the broker address |
|---|---|---|
| 1883 | MQTT over plain TCP | yes: tcp://miservidor:1883 |
| 8883 | MQTT over TLS | only with the TLS scheme documented for your Flux version |
| 18083 | the EMQX dashboard over HTTP, unless remapped | no |
Plain 1883 carries credentials and payloads unencrypted, so on a shared plant network prefer the TLS listener.
Prove hops 3 and 4 from the InfluxDB host itself, not your workstation. Test the socket with Test-NetConnection -ComputerName miservidor -Port 1883 in PowerShell, or nc -zv miservidor 1883 on Linux. Then subscribe with the task's own account, passing the password with -P: mosquitto_sub -h miservidor -p 1883 -t dataInflux/prueba -u publicador -v. If the socket test or the subscriber fails, the fault is at hop 3 or 4 and no script change will fix it.
Fix the script before you retest #
Four defects in the posted task break it independently of the dialer:
- Typographic quotes. Every string is wrapped in curly quotes; Flux parses straight
"only. Disable smart quotes in the editor you paste from. - The password literal.
password: 02342321223113"is an unquoted digit run with a stray closing quote. The parameter takes a string, and an unquoted digit run parses as a number the moment it appears — the leading zero already makes it invalid. Quote it, then move it into the InfluxDB secrets store so it never sits in the task body. - The query window.
range(start: -1h)withevery: 1mre-sends an hour of history on every run. - The client ID.
clientid: "mqttx"collides with any other client using that ID. The MQTT specification requires a broker to disconnect the existing connection when a new CONNECT presents the same client ID, so duplicate IDs disconnect each other in a loop. Give the task its own ID.
Worked example, with the arithmetic: measurement medida receives one point every 10 s, which is 6 points per minute and 6 × 60 = 360 points per hour. The window is 60 min and the run interval is 1 min, so a point written at time t stays inside range(start: -1h) for 60 ÷ 1 = 60 consecutive runs. Publishes per hour: 360 points × 60 runs = 21,600 messages, of which 360 carry new data. With range(start: -task.every) the window equals the interval, each point lands in exactly one run, and the same hour produces 360 messages — 21,600 ÷ 360 = one sixtieth of the traffic.
Check: the task saves in the editor with no parse error before anything else is tested.
Replace per-row mqtt.publish with mqtt.to #
map() evaluates its function once per row, so mqtt.publish() inside it opens a connection per row under one client ID. mqtt.to() is the output-stage form: it takes the whole stream and publishes one message per row, serializing each row itself, so it has no message parameter and the payload is not the bare string that string(v: r._value) produced. Watch the subscriber before pointing a consumer at the topic.
import "experimental/mqtt"
import "influxdata/influxdb/secrets"
option task = {name: "EnvioDataToMqtt", every: 1m, offset: 0m}
from(bucket: "recepcionDatos")
|> range(start: -task.every)
|> filter(fn: (r) => r._measurement == "medida" and r._field == "value")
|> mqtt.to(
broker: "tcp://miservidor:1883",
topic: "dataInflux/prueba",
clientid: "influx-task-envio",
username: "publicador",
password: secrets.get(key: "mqtt-pass"),
qos: 0,
)
The bucket, measurement, topic and account above are the illustrative values from the failing task; substitute your own. The mqtt package is documented as experimental and subject to change, so confirm the full parameter list on the mqtt.to() page for your Flux version.
Check: the task saves, the run completes, and the subscriber prints exactly one message per new point.
What the same error from mqtt.to decides #
If the corrected task still returns Dialer.Dial, the runtime executing tasks on that instance provides no usable MQTT dialer — a documented condition, not a guess. GitHub issue #24329 records mqtt.publish and mqtt.to both failing with this message, and the Flux documentation for the experimental mqtt package warns that the functions can still be imported in InfluxDB OSS and Enterprise but do not successfully publish to an MQTT broker. Write down influxd version next to the exact error text, then decide:
| Observation | What it proves | Decision |
|---|---|---|
Same error from mqtt.to() after the fixes |
the runtime gives tasks no MQTT dialer | stop editing the script; publish outside Flux |
mqtt.to() passes the dialer and fails on connect or auth |
hops 3 and 4 | re-run the socket and subscriber checks on the InfluxDB host |
| InfluxDB is a hosted service and the broker name is private to your LAN | the service cannot route to the broker | publish from a host inside that network, over TLS if the endpoint must be public |
The first row is the common outcome; take it rather than cycling script variants.
Publish outside the Flux runtime #
The durable shape is the one covered in publishing InfluxDB v2 bucket data to MQTT: a collector outside Flux queries the bucket and owns the MQTT connection. Run Telegraf on a host that reaches both the InfluxDB query API and the broker, and let its outputs.mqtt plugin hold the broker URL, client ID, credentials and QoS. The bucket-reading half of that pipeline is the pattern shown for reading a local InfluxDB bucket with Telegraf; point the output at your broker instead of a cloud service. Where a flow tool suits the plant better, querying InfluxDB over an MQTT bridge flow does the same job with Node-RED. Both keep MQTT out of the Flux runtime, so the dialer question never arises again.
Prove the pipeline end to end #
- Keep
mosquitto_sub -h miservidor -p 1883 -t dataInflux/prueba -u publicador -vrunning on a host that reaches the broker, passing the password with-P. - Write one test point to measurement
medida, fieldvalue, in bucketrecepcionDatos. - Wait for the next run and open the run log: status success, no Dialer.Dial text.
- Confirm exactly one message for the test point arrives on
dataInflux/prueba, and that the next run does not deliver it again. - Check the broker's client list for the task's client ID, with no repeated takeover disconnects in the broker log.
The same proof closes the Telegraf fallback; only the client ID in the last line changes.
Questions asked
Does the Dialer.Dial error mean the broker rejected my credentials or topic?
No. Credential and topic-ACL checks happen after a TCP connection and an MQTT CONNECT packet, and this error is raised before any socket exists, so the broker never saw the request. A genuine refusal looks different: with the same account, mosquitto_sub either fails during CONNECT or connects and then receives nothing on a topic the ACL blocks.
Why does port 18083 never work as the MQTT broker address?
18083 is the default HTTP port of the EMQX dashboard, not an MQTT listener, so a client connecting to it never completes the MQTT handshake. Use the listener confirmed in the broker configuration: 1883 for plain TCP, 8883 for TLS. Only a deliberately remapped listener would serve MQTT on 18083, and the configuration is where that shows.
How do I keep the MQTT password out of the task script?
Store it in the InfluxDB secrets store instead of the task body. In the script, import "influxdata/influxdb/secrets" and pass password: secrets.get(key: "mqtt-pass"), using your own secret key. The task definition and run logs then hold only the reference, never the value. Keep it a string in any case: unquoted digits parse as a number, and a leading zero makes that number invalid.
How many times does one point get sent with a one-hour window and one-minute runs?
Up to 60 times. A point stays inside a rolling 60-minute window for 60 one-minute runs, so at one point every 10 seconds, 360 real points become 360 × 60 = 21,600 messages per hour. Setting the window to the run interval with range(start: -task.every) sends each point exactly once: 360 messages for 360 points.