Troubleshooting
Why mqtt.to() runs without errors but publishes nothing
Short answer
A success status and an Explorer table prove only that the Flux stream produced rows; mqtt.to() fails silently, so isolate the fault hop by hop. Confirm the row entering the sink has balance, the four peak columns and the type tag, test TCP to the broker from the database's own runtime, publish with the real credentials, and keep a subscriber on the exact topic.
On this page
- Why does the task report success when nothing arrives?
- What does the table in Explorer prove?
- Is the row entering mqtt.to() complete?
- Can the join hand mqtt.to() an empty stream?
- Can the InfluxDB runtime reach the broker?
- Why do wrong credentials raise no error?
- In what order do I run the checks?
- Questions asked
A task status of success and a table in Explorer prove one thing only: the Flux stream produced rows. They prove nothing about whether mqtt.to() dialed the broker, logged in, or published. On InfluxDB v2.5.1 the sink fails silently, and the reported case returned its table with a redacted username and password, no error, and an empty service journal. Stop re-reading the status and work the path hop by hop: the row entering the sink, TCP reachability from the database's own runtime, the broker login with the real credentials, and a subscriber connected to the exact topic before the next run. In a rebuilt setup, the most likely fault is the redacted credential pair still sitting in the re-created task.
Why does the task report success when nothing arrives? #
Because success only means the Flux script finished without an execution error; on v2.5.1 a failed connect or login inside mqtt.to() does not fail the run, so the status says nothing about delivery.
The script sets option task = {name: "Send Electricity Balance", every: 1h}, so the scheduler runs it once an hour and records success when the execution returns without an error. The sink's side effects (the TCP connection, the MQTT login, the publish) sit outside what that status reports. The reported journal check, journalctl -u influxdb.service --since "10 minutes ago", showed nothing at all around the failing runs, so at that release's default logging the sink does not announce its failures there either.
Decision: treat success-with-no-message as a fault to find by test, not by re-reading the status or the journal.
What does the table in Explorer prove? #
It proves the stream reaching the sink had rows and columns; the display ends at the query result, and nothing in it reports whether the broker accepted a connection, a login or a publish.
Two Explorer runs were reported. Without the sink line, the expected table came back. With the sink line and the redacted credentials, the same table came back, still with no error. Invalid credentials produced no visible failure, which settles the question: an Explorer table is never a delivery receipt. The display also cannot distinguish a sink that ran and failed quietly from any other outcome, so Explorer clears hop one and nothing more.
When the sink does surface a named transport error instead of silence, that is the other failure mode: start from why Flux mqtt.publish fails with Dialer.Dial in InfluxDB. This article covers the opposite case, where nothing at all surfaces.
Is the row entering mqtt.to() complete? #
Count the columns on the row that enters the sink: it must carry balance plus the four suffixed peak columns and the type tag, five value columns in total, or the query is at fault, not the transport.
Run the script in Explorer with the mqtt.to() line removed; the table you get is exactly the stream the sink would receive, so audit it column by column. The names are not arbitrary. Each branch keeps the fields offpeak, peak_generated and peak_used, calls last(), folds the three fields into columns with pivot(rowKey: ["_time"], columnKey: ["_field"], valueColumn: "_value"), and drops _start, _stop, billing and _measurement. The join then suffixes every column present on both sides with the branch name, peak_used_billed, peak_used_current, peak_generated_billed, peak_generated_current, which is exactly why valueColumns lists those four names. The first map() adds balance; the second stamps _time with now(). The offpeak columns survive the join as well, but valueColumns leaves them out of the message.
Worked example with invented meter readings in kWh: the billed branch's last points are peak_used 1200 and peak_generated 800; the current branch's last points are peak_used 1235 and peak_generated 812. After the join the row carries peak_used_billed 1200, peak_used_current 1235, peak_generated_billed 800 and peak_generated_current 812, and the map computes balance as -(1235) - 1200 + (812 - 800) = -2435 + 12 = -2423. That -2423 kWh is the value the message must carry. A missing column or a null balance is a query fault; stop there and leave the broker alone.
Can the join hand mqtt.to() an empty stream? #
Yes, and it fails two different ways: a branch with no rows makes join error out, while two non-empty branches whose type values never match join to zero rows with no error at all.
billed keeps billing == "yes"; current keeps billing == "no"; both read meterreadings in the nodered bucket over range(start: -2y). Test each branch alone: it should return one pivoted row per timestamp with the three field columns and a usable type value. On the Flux line behind that release, join() needs type information from both inputs, so an empty input table raises an error you would see in Explorer. Two non-empty branches with no matching type values produce the silent case, zero rows, so compare the actual type values on both sides before blaming the sink.
One quieter variant: pivot() groups on _time, so if a branch's three field points carry different timestamps they land on separate rows and the balance arithmetic meets nulls. The symptom is a row with an empty balance, not a missing row. Either way the fault is upstream: fix the filter, the time range or the field alignment, not the transport.
For the reported case this hop is already cleared, because Explorer returned the expected row, so the fault sits downstream.
Can the InfluxDB runtime reach the broker? #
Test from where the database actually runs: nc -vz 192.168.1.80 1883 must answer with a succeeded connection from that host or container, because a desktop on the same LAN proves nothing about the service's own network path.
nc -vz 192.168.1.80 1883
The script dials tcp://192.168.1.80:1883 from the database process, so if InfluxDB runs in a container or another network namespace, run the same test inside that namespace. If it fails, fix the broker's listener binding, the host or container routes, or a firewall rule on the path before changing anything in Flux. If it succeeds, transport is proven, and only transport: an open TCP connection says nothing about the MQTT login or the right to publish.
Why do wrong credentials raise no error? #
Because a rejected MQTT login is handled inside the sink without failing the Flux run: the reported run with the redacted placeholder pair still returned its table, raised no error, and left the journal empty.
The setup had been rebuilt after the original was lost, and the re-created task was pasted with the redacted placeholders still in its username and password parameters; the broker refused the login and nothing anywhere said so. That is the most likely fault in this situation, and the fix is one edit: restore the real pair in the task, then re-run it.
Prove the broker side independently. With a known-working MQTT client, connect using the same broker address and the real credentials; subscribe to growatt/balance first, then publish a test message to that same topic. If the client's publish is refused, the broker's permission rules for that user on that topic are the fault, not Flux. Keep the password out of shell history by passing it through the client's prompt or a protected file, and keep plain-text secrets out of the saved script wherever your release supports stored secrets.
Timing matters as well: a plain, non-retained MQTT message reaches only clients connected at the moment of publish, and the task publishes once per scheduled run. Open the subscriber before you trigger a manual run, or you will watch an empty topic and blame the task. Suspect the watcher too: the same silence appears in why an MQTT subscriber stops receiving after a broker restart, and it looks exactly like a task that publishes nothing.
In what order do I run the checks? #
Run them in data-path order, because each hop's result eliminates everything downstream of it: the stream entering the sink, TCP reachability, the broker login and publish right, and the subscriber's view, four tests, each decisive for its own hop.
- Open the Explorer table produced with the sink line removed (that table is the sink's input) and confirm at least one row carrying
balance,peak_used_current,peak_used_billed,peak_generated_current,peak_generated_billedandtype. Anything missing: fix the query and stop. - From the database's own runtime, run the TCP test from the previous section. It fails: fix the listener, the route or the firewall and stop.
- With a known-working client, connect with the real credentials and publish a test message to
growatt/balance. Refused: fix the credential pair or the topic permission and stop. - Subscribe to that exact topic, trigger a manual task run, and watch the message land while the subscriber is connected.
- All four pass and the scheduled task still publishes nothing: re-save the task's stored script with the real credential pair (the stored copy, not the one in your editor) and run it once more.
Decision for the reported case: the Explorer table clears the data path, so run the transport test; when it succeeds, the redacted credential pair in the re-created task is the fault. Restore it, keep a subscriber connected, run the task manually, and the balance message arrives on the first run. If a message must survive a missed subscriber, that is a broker retention question, covered in does an MQTT broker store historic data you can query.
Questions asked
How do I get alerted when the task succeeds but no message arrives?
Watch the topic, not the task status. Keep a small subscriber connected to the broker that expects one message per run, one hour in this script, and raises an alarm when two consecutive intervals pass with no publication. That watchdog catches the silent sink failure the run status cannot report.
Does the task script need the same import line as Explorer?
Yes. The saved task needs the experimental/mqtt import line at its top, exactly as Explorer does. Without it the run fails before any sink executes, and that failure does surface as an error. An unknown-import error points at the database build, not at the sink configuration, so check the import before the broker.
Why would the identical query stop working after a year?
The script text survived, but the environment around it was rebuilt. Four inputs changed: the host or container the database now runs in, the credential pair typed into the new task, the broker's listener and user permissions, and the monitoring client's session. Verify those four instead of rewriting a calculation that already returns the expected row.
Should I raise the database log verbosity to catch the sink failure?
You can, but not first. In the reported case the service journal showed nothing at default verbosity during the failing runs, while the hop tests identify the fault in minutes without a log change. Raise verbosity only after every hop test passes and the message still never arrives.