Search in sources :

Example 1 with MqttConnection

use of org.openmuc.framework.lib.mqtt.MqttConnection in project OpenMUC by isc-konstanz.

the class MqttLogger method connect.

/**
 * Connect to MQTT broker
 */
private void connect() {
    MqttSettings settings = createMqttSettings();
    MqttConnection connection = new MqttConnection(settings);
    connection.setSslManager(sslManager);
    mqttWriter = new MqttWriter(connection, getId());
    if (settings.isSsl()) {
        if (isLoggerReady()) {
            logger.info("Connecting to MQTT Broker");
            mqttWriter.getConnection().connect();
        } else {
            logger.info("Writer is not ready yet");
        }
    } else {
        logger.info("Connecting to MQTT Broker");
        mqttWriter.getConnection().connect();
    }
}
Also used : MqttConnection(org.openmuc.framework.lib.mqtt.MqttConnection) MqttWriter(org.openmuc.framework.lib.mqtt.MqttWriter) MqttSettings(org.openmuc.framework.lib.mqtt.MqttSettings)

Example 2 with MqttConnection

use of org.openmuc.framework.lib.mqtt.MqttConnection in project OpenMUC by isc-konstanz.

the class MqttLoggerTest method connect.

// @BeforeAll
static void connect() {
    String packageName = MqttLogger.class.getPackage().getName().toLowerCase();
    System.setProperty(packageName + ".host", "localhost");
    System.setProperty(packageName + ".port", "1883");
    System.setProperty(packageName + ".username", "guest");
    System.setProperty(packageName + ".password", "guest");
    System.setProperty(packageName + ".topic", "device/data");
    System.setProperty(packageName + ".maxFileCount", "2");
    System.setProperty(packageName + ".maxFileSize", "1");
    System.setProperty(packageName + ".maxBufferSize", "1");
    String pid = MqttLogger.class.getName();
    MqttLoggerSettings settings = new MqttLoggerSettings();
    PropertyHandler propertyHandler = new PropertyHandler(settings, pid);
    MqttSettings Mqttsettings = new MqttSettings(propertyHandler.getString(MqttLoggerSettings.HOST), propertyHandler.getInt(MqttLoggerSettings.PORT), propertyHandler.getString(MqttLoggerSettings.USERNAME), propertyHandler.getString(MqttLoggerSettings.PASSWORD), propertyHandler.getBoolean(MqttLoggerSettings.SSL), propertyHandler.getInt(MqttLoggerSettings.MAX_BUFFER_SIZE), propertyHandler.getInt(MqttLoggerSettings.MAX_FILE_SIZE), propertyHandler.getInt(MqttLoggerSettings.MAX_FILE_COUNT), propertyHandler.getInt(MqttLoggerSettings.CONNECTION_RETRY_INTERVAL), propertyHandler.getInt(MqttLoggerSettings.CONNECTION_ALIVE_INTERVAL), propertyHandler.getString(MqttLoggerSettings.PERSISTENCE_DIRECTORY));
    MqttConnection connection = new MqttConnection(Mqttsettings);
    MqttWriter mqttWriter = new MqttWriter(connection, "mqttlogger");
    mqttWriter.getConnection().connect();
}
Also used : MqttConnection(org.openmuc.framework.lib.mqtt.MqttConnection) MqttWriter(org.openmuc.framework.lib.mqtt.MqttWriter) PropertyHandler(org.openmuc.framework.lib.osgi.config.PropertyHandler) MqttSettings(org.openmuc.framework.lib.mqtt.MqttSettings)

Aggregations

MqttConnection (org.openmuc.framework.lib.mqtt.MqttConnection)2 MqttSettings (org.openmuc.framework.lib.mqtt.MqttSettings)2 MqttWriter (org.openmuc.framework.lib.mqtt.MqttWriter)2 PropertyHandler (org.openmuc.framework.lib.osgi.config.PropertyHandler)1