IMD SolutionComputing LibraryShop main store

Troubleshooting

Why OpenEMS Simulator writes no data to InfluxDB

Edge computing and IIoT Published 6 min read By IMD Solution engineering team

Short answer

The Timedata.InfluxDB writer stamps points with the host clock, which the Simulator forbids, and the Simulator deletes it before queued writes drain. Read timestamps from the simulated clock, keep every cycleTime divisor nonzero, and retain the writer until the run's data is queried; that combination wrote every point in the reported case.

On this page
  1. Your configuration is not the fault
  2. The one rule the writer breaks
  3. Two faults, one empty bucket
  4. Take the timestamp from the simulated clock
  5. Keep every cycleTime divisor nonzero
  6. Retain the writer until the data is queried
  7. Worked example: the timestamp grid for an 8-day run at 15 minutes per cycle
  8. Acceptance checklist
  9. Questions asked

Adding the Timedata.InfluxDB component to simulation.json is the right idea, and the entry you wrote is valid. The bucket stays empty because of two faults elsewhere: TimedataInfluxDbImpl.java stamps every point with the host clock, which breaks the one rule the Simulator imposes on components, and the cleanup in SimulatorAppImpl.java deletes the writer before its queued writes drain. The cure is three changes — read time from the simulated clock, keep every cycleTime divisor nonzero, and retain the writer until the run's data is queried. In the reported case that combination wrote every point; any single change alone did not.

Your configuration is not the fault #

The reported test wrote to InfluxDB V2 with exactly this entry, and the component activated:

{
  "factoryPid": "Timedata.InfluxDB",
  "properties": [
    { "name": "id", "value": "influx0" },
    { "name": "url", "value": "http://ip:8086" },
    { "name": "org", "value": "organisation" },
    { "name": "apiKey", "value": "key" },
    { "name": "bucket", "value": "simul0" }
  ]
}

One caution before the first run: point url and bucket at a test destination. Simulated points carry simulated dates, and once they land in an operational bucket nothing in a trend distinguishes them from plant measurements.

If activation fails or the destination refuses the writes, solve that before touching timestamp logic: confirm the organization and bucket accept a write with the same apiKey, because a reachable server proves nothing about write permission. Where the credential itself is the confusion, the difference between the two kinds is sorted out in OpenEMS InfluxDB password versus API token in Docker.

The one rule the writer breaks #

The Simulator exists to run a complete OpenEMS Edge instance in simulated real time, and it imposes one hard condition on every component: never read the native clock; take time from the simulated clock that ClockProvider supplies. The timedata implementation on the develop branch breaks that condition in a single line of TimedataInfluxDbImpl.java:

var timestamp = System.currentTimeMillis() / cycleTime * cycleTime;

System.currentTimeMillis() is wall-clock time on the host. A run that models days of operation finishes in minutes of real time, so every point is stamped inside those few real minutes — the data lands on the run date, not the simulated dates, and a query over the simulated window returns nothing. The write succeeds; the timeline is wrong.

Two faults, one empty bucket #

  • Wrong timeline: the host-clock stamps above place the points outside the simulated dates, so a correct query finds nothing even though the writes land.
  • Lost tail: when the run ends, the Simulator's cleanup deletes the components it created, and deletion overtakes the writer's queued writes.

The reported case isolated the second fault with four runs against InfluxDB V2:

  • Writer retained past the end of the run: all data written.
  • Writer deleted, executeCycleTwice true: slightly more than the first half written.
  • Writer deleted, executeCycleTwice false: nothing written.
  • Deleted, false, with a breakpoint inside collectAndWriteChannelValues(): points appear while execution is paused, a few more after the breakpoint is removed.

In every one of those runs this.influxConnector.write(point) executed. The write call is not failing; completion is being raced by teardown. The cycle limit if (++this.cycleCount >= this.config.noOfCycles()) was suspected as the cutoff in the same case and ruled out, so do not chase it.

Take the timestamp from the simulated clock #

Replace the offending expression with the component manager's clock:

var timestamp = this.componentManager.getClock().millis();

This is the expression the reported case confirmed working. It reads time through the simulation-aware path, so points advance with the modeled window, and it removes the rounding from that expression entirely. Rebuild the timedata bundle with the project's normal build procedure and deploy it to the simulation host. Then check the unit and precision used when the point is assembled for the write request — a correct clock value still needs a matching representation in the request. Pass this stage only when stored timestamps track the configured simulation window; write activity alone proves nothing.

Keep every cycleTime divisor nonzero #

The old expression divides by cycleTime before multiplying by it, so a zero cycleTime throws before a single point exists — the reported case hit exactly this and had to adjust cycleTime before any data appeared. With the direct clock read the rounding is gone from that line, but the collection path can still divide by cycleTime elsewhere. Trace where the value comes from at runtime and give it a real nonzero interval in the intended units; do not paste an arbitrary constant to make an exception disappear. If a divisor can be zero during activation, skip that cycle's write and log it rather than divide. Keep three things distinct while doing this: the simulation's time advance (timeleapPerCycle), the collection cadence (cycleTime), and the write scheduling. Nudging one to silence an error changes when values are collected without fixing the other two.

Retain the writer until the data is queried #

The cleanup in SimulatorAppImpl.java already spares some components: its keep-condition matches factoryPid prefixes such as Core., Controller.Api. and Predictor.. For the diagnostic run, extend that condition so the component whose factoryPid is Timedata.InfluxDB is not deleted either. Let the run finish, query the full simulated period while the writer is still active, and delete the component by hand only after the queries show the expected records and the final simulated timestamp. Retention is the workaround the case verified. A deactivate-time flush of pending writes would be the proper upstream repair, but it was never tested in the reported case, so do not promise it.

Worked example: the timestamp grid for an 8-day run at 15 minutes per cycle #

Inputs, all from the clock block of the reported test's simulation.json:

"clock": {
  "start": "2025-06-16T00:00:00.00Z",
  "end": "2025-06-24T00:00:00.00Z",
  "timeleapPerCycle": 900000,
  "executeCycleTwice": false
}
  • Simulated window: 2025-06-16T00:00:00.00Z to 2025-06-24T00:00:00.00Z.
  • Advance per cycle: timeleapPerCycle 900000 ms.
  • executeCycleTwice false for this run.

Rule in words: the simulated window is the end minus the start, and the grid the timestamps must land on is that window divided by the per-cycle advance.

Arithmetic:

  1. Window: 2025-06-16 to 2025-06-24 is 8 days; 8 × 86,400 s = 691,200 s.
  2. Advance: 900,000 ms = 900 s, i.e. 15 minutes per cycle.
  3. Grid steps: 691,200 s ÷ 900 s = 768 steps.

Result: with the clock fix in place, stored timestamps advance through the simulated dates in quarter-hour steps — up to 768 grid positions. The grid is a reference, not a guaranteed point count: endpoint handling, repeated execution and the number of collected channels decide the actual records.

Decision: query the bucket over the simulated window and read the oldest and newest timestamps. They pass when both sit inside 2025-06-16 to 2025-06-24, the spacing matches the per-cycle advance, and the last grid position is present after the retained writer finishes. Fail — and rebuild before testing anything else — when the window is empty while points exist stamped on the host's run date, the whole run compressed into the real minutes it took.

Acceptance checklist #

  • The component activates with no configuration errors, and the destination accepts a manual write with the same url, org, apiKey and bucket.
  • The run targets a test bucket; modeled data never reaches the operational one.
  • No division-by-zero exception appears during the run.
  • A query over the configured simulated dates — not a dashboard's recent wall-clock range — returns the points.
  • Successive timestamps follow the simulator's advances with no gaps, repeats or host-time values.
  • The final grid position of the window is present after the run ends, writer still active.
  • The writer is deleted manually only after those queries pass.

Questions asked

Why does a breakpoint inside collectAndWriteChannelValues() make points appear?

Pausing there keeps the component alive while its queued writes drain, so points reach the database before cleanup deletes the writer. Remove the breakpoint and teardown wins the race again. The observation proves the write call executes; it says nothing about delivery. Use it once as a diagnostic, then fix retention instead of slowing the run.

Does the fix also work with InfluxDB V1?

The reported case ran InfluxDB V2, with url, org, apiKey and bucket, and never tested V1. The clock change only swaps the time source and leaves the write request untouched, so it should carry over, but that is an expectation, not a verified result. Run a short V1 test against a test bucket before relying on it.

Does the retention workaround belong on a production controller?

No. On a live Edge controller the timedata component is configured once and never deleted mid-run, so the teardown race exists only in the Simulator's cleanup. Keep the modified cleanup on the simulation host. If one machine serves both roles, give the simulation its own Edge instance pointed at its own test bucket.

Is exporting Simulator data to InfluxDB an intended feature?

The Simulator's readme describes a full simulation environment for an OpenEMS Edge instance and promises nothing about timedata export, so treat this setup as something you commission yourself. The reported case shows the export works once the writer obeys the clock rule and survives cleanup. Re-check both after every OpenEMS update, because a newer timedata implementation may fix or move the offending line.

Keep reading

  • Troubleshooting

    Telegraf MQTT consumer connects but writes no data to InfluxDB

    An empty 0 / 10000 output buffer with both the MQTT and InfluxDB connections up means no metrics are reaching Telegraf's parser. Prove live delivery with a second subscriber on a different client ID before touching parser or buffer settings: the two startup connections are independent events, and with qos = 0 and a non-persistent session, traffic published while Telegraf is offline is unrecoverable.

    Edge computing and IIoT

  • Troubleshooting

    Troubleshoot missing data in a Node-RED InfluxDB Grafana stack

    Work the chain in order: acquisition into Node-RED, the InfluxDB service and its storage mount, the write settings, then the Grafana query. In a 2.x stack most empty panels trace to a wrong token, bucket, URL or a controller clock that stamps points outside the panel's time range.

    Edge computing and IIoT

  • Troubleshooting

    Capture 1 ms PLC samples to InfluxDB without data loss

    Polling a live value at any rate cannot preserve 1 ms PLC samples, because acquisition timing then belongs to the reader. Run the sampling in the PLC's 1 ms task, publish each filled value-and-timestamp batch behind a counter such as buffer_id, and let Node-RED transfer a batch only when that counter changes. Write one database point per sample with its own timestamp, and size batches so the consumer always finishes before the next one completes.

    Edge computing and IIoT

Fix InfluxDB invalid boolean from a NAS write