Hello everyone!
I couldn’t find a similar solution, so I decided to ask a question over here.
Let’s suppose that I would like to implement the following solution with OpenEMS:
I have implemented a device, that takes 2 values from the API and writes them to the channel: ArrayVoltage and LoadPower.
The values are shown in the component in the UI.
In the UI, I have a button that would trigger a POST request to the physical device’s API (for example some change in the device’s settings).
I tried to implement it using only my implementation of the device, but the POST request is being triggered around 60 times, which obviously is not what I want to achieve.
For the reference, here is my code.
I belive that the reason or it is that I implemented it badly, since I don’t fully understand the workflow of the device implementation (in which order the functions are being triggered? Are ChannelValues being pulled continuously?).
Do I think correctly, that instead of implementing a device, I should implement a controller, that would handle sending a POST request to the physical device? What’s the difference between the handleEvent method in the device’s implementation and the run method in the controller’s implementation?
your Component is subscribed to the Event Topic “TOPIC_CYCLE_BEFORE_PROCESS_IMAGE”
This event by default is triggered once per second. If you call your send() method within handleEvent() this of course will be called over and over again.
OpenEMS has the benefit of providing plenty of “Natures” for different device types (smart meters, electrical storage systems, charging stations, CHPs, etc.). You can leverage most of the benefits by implementing the correct interface and provide the expected channels for that type of device.
There are other concepts for storing configurations (Apache Felix ConfigAdmin) and there are concepts for initializing components with that configuration (Bundle Activators).
You described “how you want to do something” instead of describing “what you want to do”.
Hello Simon,
thank you very much for your answer! Correct me if I understand it wrong, but if my Component is subscribed to the Event Topic "TOPIC_CYCLE_BEFORE_PROCESS_IMAGE” and receiveChannelValues() is triggered in the NewDevice.java, while writing values to the channels, does that mean the whole thing is being triggered also once per second?
And answering your question: I would like to have a button in the UI that can send the command to the field device that has Edge running. The command would be for example Switch on/off the device.
Hi Simon,
thank you very much for your help! Can I have one more question about the controller itself?
What are the references to: ConfigurationAdmin and ComponentManager? What does these two things do?
Also, does the Controller always have to have a reference to the device?
Thanks again, your help is being priceless.
your device does not require any reference to the ComponentManager if you simply implement the DigitalOutput interface. The FixDigitalOutput Controller will work with your Device without additional software.
You do need a reference to the ConfigurationAdmin if you plan to bind a ModbusBridge or other OSGi Component. This may depend on your particular use case. The ConfigurationAdmin is used to update the reference filter for that OSGi component. In OSGi you do not instantiate Components by yourself since the framework manages the life-cycle ( 4 Life Cycle Layer - OSGi Core 7). References are used to access other components.
Just as a note:
Out of your questions I guess you try to re-implement or circumvent concepts that already exist in OpenEMS.
If your device is an EV-Charging Station, Smart Meter or an Electrical Storage System you can ignore all of my suggestions since there are other ways to integrate them. It’ll be really helpful if you disclose what kind of device you are planning to integrate - and why.