Accessing Channel Values changed via REST in Controller run() function

Hello.

I am trying to use “Controller.Symmetric.Balancing” with a variable setpoint.

I defined a Channel ‘SETPOINT’ which I set via the REST api.

The log shows a partial success:
[re.Cycle] INFO [ontroller.api.common.ApiWorker] [ctrlApiRest0] Set Channel [ctrlBalancing0/Setpoint] to Value [1000]

However I can’t access this Channel-Value in the run() method of the Controller.

This code produces ‘UNDEFINED’ when I set the Channelvalue via REST
this.logWarn(this.log, "DBG: " .concat(this.channel(ChannelId.SETPOINT).getNextValue().asString()));

but shows the expected value when I call
this.channel(ChannelId.SETPOINT).setNextValue(100);

I also can’t find a similar example anywhere in existing code.

Any help would be appreciated.
I am not sure if I shoulds ask questions in german or english.

Kind regards,
Christopher Mader

Hi Christopher,

Thanks for joining the OpenEMS Community. Both German and English are ok for me - but Englisch is generally a good choice for technical questions.

  1. What is your target? Do you want to provide:
    a) a setpoint for the output power of Energy Storage System? In this case you should directly write to ess0/SetActivePowerEquals (see APIs - Externe Schnittstellen :: FENECON Dokumente in the FENECON docs)
    b) for the target grid point (i.e. 0 by default for Balancing)? The Symmetric Balancing Schedule Controller has such a feature. See Accessing Channel Values changed via REST in Controller run() function

Maybe if you compare your code with the b) implementation, you are able find the issue in your code.

Regards,
Stefan

Good Morning Stefan,

Thank you very much for your swift answer on a sunday night.

I was looking for a solution to “b”, setting the target grid point, and your answer perfectly showed the way:

IntegerWriteChannel setSetpointChannel = this.channel(ChannelId.SETPOINT);
Optional setPointFromChannel = setSetpointChannel.getNextWriteValueAndReset();
this.logWarn(this.log, DBG: .concat( setPointFromChannel.orElse(0).toString() ));

This works as expected.

kind regards

1 Like