Send simulation results to influxDB

Hey there,
I am currently looking into the simulation via the Simulator App ( openems/io.openems.edge.simulator at develop · OpenEMS/openems · GitHub). The simulation is working fine but now I am wondering if it is possible to directly send the resulting data to my influxDB.
Simply adding the following lines to the simulation.json file did not work for me:

"components":[
...
    {
                  "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"
                     }
                  ]
               }
]

Is this simply not intended or am I doing something wrong?

Best,

Finn

Whats your Purpose or Use-Case on doing so?

At the moment I am just playing around and want to know whether it works. At some point I thought it could be useful to test custom ess controllers.

I have not been using the Simulator App for a very long time. Glad it’s still of some use :slight_smile:

The thing with the Simulator is, that it only works properly with Components that follow certain technical requirements. For example they are not allowed to use native clock, but have to use the simulated one from ClockProvider. This seems to be a problem with the current Influx implementation, as it just uses

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

→ see openems/io.openems.edge.timedata.influxdb/src/io/openems/edge/timedata/influxdb/TimedataInfluxDbImpl.java at develop · OpenEMS/openems · GitHub

You could try to adjust this; I am not sure if further issues arise afterwards.

Regards,
Stefan

1 Like

Hi Stefan,

Using the ClockProvider is going in the right direction, thank you for the hint. Additionally, to prevent division by zero, the cycleTime needs to be adjusted. By addressing this, data is successfully written to the database. Unfortunately, the data, particularly the time period, is not consistent. I’ll attempt to fix this when I have time and will share my results.

Best,
Finn

So simply generating the timestamp as follows works (inside TimedataInfluxDB):
var timestamp = this.componentManager.getClock().millis();

Unfortunately, the deletion of the InfluxDB inside the SimulatorApp seems to delete the component without writing the remaining data. openems/io.openems.edge.simulator/src/io/openems/edge/simulator/app/SimulatorAppImpl.java at develop · OpenEMS/openems · GitHub

A first workaround is to simply not delete it and delete it manually afterwards:

if (factoryPid.startsWith("Core.") //
					|| factoryPid.startsWith("Controller.Api.") //
					|| factoryPid.startsWith("Predictor.") //
					// Ess.Power exists by default. We don't delete it, but will overwrite the
					// configuration later. Delete request for this component does not work for some
					// unknown reason.
					|| factoryPid.equals("Ess.Power")
					|| factoryPid.equals("Timedata.InfluxDB")) {
				continue;
			}

So you are saying because of if (++this.cycleCount >= this.config.noOfCycles()) { the data is not written in the end? A proper solution would be possibly to run the logic inside collectAndWriteChannelValues() once in the deactivate()-method.

openems/io.openems.edge.timedata.influxdb/src/io/openems/edge/timedata/influxdb/TimedataInfluxDbImpl.java at develop · OpenEMS/openems · GitHub

Hi Stefan,
thanks for your input but this doesn’t seem to be the issue. The behavior is really strange.

  • When the database does not get deleted, all the data is written.
  • When the database gets deleted and ‘executeCycleTwice’ is set to true, slightly more than the first half of the data is written to the database.
  • When the database gets deleted and ‘executeCycleTwice’ is set to false, no data is written at all.
  • When the database gets deleted and ‘executeCycleTwice’ is set to false but I am running in debug mode with a breakpoint inside collectAndWriteChannelValues() the datapoints are written as long as the break point is set. After removing the break point a only few more data points are written.

In every case this.influxConnector.write(point) is executed.

When talking about executeCycleTwice I am referring to the simulation.json file:

"clock":{
               "start":"2025-06-16T00:00:00.00Z",
               "end":"2025-06-24T00:00:00.00Z",
               "timeleapPerCycle":900000,
               "executeCycleTwice": false
            }

I am currently using InfluxV2 so I’ll test V1 at some point. If you have any other ideas please let me know :slight_smile:

Sending the Thread to sleep before deleting all the components (inside SimulatorEdgeAppImpl) doesn’t help either.

Sorry, no clue why it is like this.