Class ControllerApiMqttImpl
java.lang.Object
io.openems.edge.common.component.AbstractOpenemsComponent
io.openems.edge.controller.api.mqtt.ControllerApiMqttImpl
- All Implemented Interfaces:
OpenemsComponent
,Controller
,ControllerApiMqtt
,org.osgi.service.event.EventHandler
public class ControllerApiMqttImpl
extends AbstractOpenemsComponent
implements ControllerApiMqtt, Controller, OpenemsComponent, org.osgi.service.event.EventHandler
-
Nested Class Summary
Nested classes/interfaces inherited from interface io.openems.edge.controller.api.Controller
Controller.ChannelId
Nested classes/interfaces inherited from interface io.openems.edge.controller.api.mqtt.ControllerApiMqtt
ControllerApiMqtt.ChannelId
Nested classes/interfaces inherited from interface io.openems.edge.common.component.OpenemsComponent
OpenemsComponent.ChannelId
-
Field Summary
Modifier and TypeFieldDescriptionprotected static final String
protected ComponentManager
protected io.openems.edge.controller.api.mqtt.Config
Fields inherited from interface io.openems.edge.controller.api.mqtt.ControllerApiMqtt
TOPIC_CHANNEL_LAST_UPDATE, TOPIC_CHANNEL_PREFIX, TOPIC_EDGE_CONFIG
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected static String
createTopicPrefix
(io.openems.edge.controller.api.mqtt.Config config) Creates the topic prefix in either format.protected void
Handles @Deactivate of implementations.void
handleEvent
(org.osgi.service.event.Event event) protected void
Log an info message including the Component ID.protected void
Log a warn message including the Component ID.protected boolean
publish
(String subTopic, String message, int qos, boolean retained, org.eclipse.paho.mqttv5.common.packet.MqttProperties properties) Publish a message to a topic.protected boolean
Publish a message to a topic.void
run()
Executes the Controller logic.Methods inherited from class io.openems.edge.common.component.AbstractOpenemsComponent
_channel, activate, activate, addChannel, addChannels, addChannels, alias, channels, getComponentContext, id, isEnabled, logDebug, logError, modified, removeChannel
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.openems.edge.controller.api.Controller
_setRunFailed, getRunFailed, getRunFailedChannel
Methods inherited from interface io.openems.edge.common.component.OpenemsComponent
_channel, _getChannelAs, alias, channel, channel, channels, debugLog, getComponentContext, getState, getStateChannel, hasFaults, id, isEnabled, serviceFactoryPid, servicePid
-
Field Details
-
COMPONENT_NAME
- See Also:
-
componentManager
-
config
protected io.openems.edge.controller.api.mqtt.Config config
-
-
Constructor Details
-
ControllerApiMqttImpl
public ControllerApiMqttImpl()
-
-
Method Details
-
createTopicPrefix
Creates the topic prefix in either format.- topic_prefix/edge/edge_id/
- edge/edge_id/
- Parameters:
config
- theConfig
- Returns:
- the prefix
-
deactivate
protected void deactivate()Description copied from class:AbstractOpenemsComponent
Handles @Deactivate of implementations. Prints log output.- Overrides:
deactivate
in classAbstractOpenemsComponent
-
run
Description copied from interface:Controller
Executes the Controller logic.- Specified by:
run
in interfaceController
- Throws:
OpenemsError.OpenemsNamedException
- on error
-
logInfo
Description copied from class:AbstractOpenemsComponent
Log an info message including the Component ID.- Overrides:
logInfo
in classAbstractOpenemsComponent
- Parameters:
log
- the Logger instancemessage
- the message
-
logWarn
Description copied from class:AbstractOpenemsComponent
Log a warn message including the Component ID.- Overrides:
logWarn
in classAbstractOpenemsComponent
- Parameters:
log
- the Logger instancemessage
- the message
-
handleEvent
public void handleEvent(org.osgi.service.event.Event event) - Specified by:
handleEvent
in interfaceorg.osgi.service.event.EventHandler
-
publish
Publish a message to a topic.- Parameters:
subTopic
- the MQTT topic. The global MQTT Topic prefix is added in front of this stringmessage
- the message- Returns:
- true if message was successfully published; false otherwise
-
publish
protected boolean publish(String subTopic, String message, int qos, boolean retained, org.eclipse.paho.mqttv5.common.packet.MqttProperties properties) Publish a message to a topic.- Parameters:
subTopic
- the MQTT topic. The global MQTT Topic prefix is added in front of this stringmessage
- the message; internally translated to a UTF-8 byte arrayqos
- the MQTT QOSretained
- the MQTT retained parameterproperties
- theMqttProperties
- Returns:
- true if message was successfully published; false otherwise
-