use of org.opensmartgridplatform.simulator.protocol.mqtt.spec.SimulatorSpec in project open-smart-grid-platform by OSGP.
the class Simulator method getSimulatorSpec.
private SimulatorSpec getSimulatorSpec(final String jsonPath) throws IOException {
final SimulatorSpec simulatorSpec;
if (jsonPath != null) {
File jsonFile = new File(jsonPath);
if (!jsonFile.exists()) {
final ClassPathResource jsonResource = new ClassPathResource(jsonPath);
if (jsonResource.exists()) {
jsonFile = jsonResource.getFile();
} else {
throw new IllegalArgumentException(String.format("Could not find file or class path resource %s", jsonPath));
}
}
simulatorSpec = new ObjectMapper().readValue(jsonFile, SimulatorSpec.class);
} else {
simulatorSpec = new SimulatorSpec(Default.BROKER_HOST, Default.BROKER_PORT);
}
LOG.info("Simulator spec: {}", simulatorSpec);
return simulatorSpec;
}
use of org.opensmartgridplatform.simulator.protocol.mqtt.spec.SimulatorSpec in project open-smart-grid-platform by OSGP.
the class MqttDeviceSteps method startPublishingClient.
private void startPublishingClient(final String host, final int port, final String topic, final String payload, final Map<String, String> parameters) {
final SimulatorSpec spec = new SimulatorSpec(host, port);
spec.setStartupPauseMillis(2000);
final Message message = new Message(topic, payload, 10000);
final Message[] messages = { message };
spec.setMessages(messages);
MqttClientSslConfig mqttClientSslConfig = null;
final boolean mqttSslEnabled = ReadSettingsHelper.getBoolean(parameters, PlatformDistributionAutomationKeys.MQTT_SSL_ENABLED, PlatformDistributionAutomationDefaults.MQTT_SSL_ENABLED);
if (mqttSslEnabled) {
final String truststoreLocation = ReadSettingsHelper.getString(parameters, PlatformDistributionAutomationKeys.MQTT_SSL_TRUSTSTORE_LOCATION, PlatformDistributionAutomationDefaults.MQTT_SSL_TRUSTSTORE_LOCATION);
final String truststorePassword = ReadSettingsHelper.getString(parameters, PlatformDistributionAutomationKeys.MQTT_SSL_TRUSTSTORE_PASSWORD, PlatformDistributionAutomationDefaults.MQTT_SSL_TRUSTSTORE_PASSWORD);
final String truststoreType = ReadSettingsHelper.getString(parameters, PlatformDistributionAutomationKeys.MQTT_SSL_TRUSTSTORE_TYPE, PlatformDistributionAutomationDefaults.MQTT_SSL_TRUSTSTORE_TYPE);
final ResourceLoader resourceLoader = new DefaultResourceLoader();
final Resource trustStoreResource = resourceLoader.getResource(truststoreLocation);
mqttClientSslConfig = MqttClientSslConfigFactory.getMqttClientSslConfig(trustStoreResource, truststorePassword, truststoreType);
}
final SimulatorSpecPublishingClient publishingClient = new SimulatorSpecPublishingClient(spec, mqttClientSslConfig);
publishingClient.start();
}
Aggregations