Search in sources :

Example 1 with LoraCommand

use of org.eclipse.hono.adapter.lora.LoraCommand in project hono by eclipse.

the class LoraProviderTestBase method testGenerateCommandMessage.

/**
 * Verifies that command messages are formatted correctly.
 */
@Test
public void testGenerateCommandMessage() {
    final CommandEndpoint commandEndpoint = new CommandEndpoint();
    commandEndpoint.setPayloadProperties(Map.of("py-property", "my-property-value"));
    commandEndpoint.setUri("https://my-lns.io/{{deviceId}}/command");
    final LoraCommand command = provider.getCommand(commandEndpoint, TEST_DEVICE_ID, Buffer.buffer("bumlux".getBytes(StandardCharsets.UTF_8)), "2");
    assertThat(command.getUri()).isEqualTo("https://my-lns.io/" + TEST_DEVICE_ID + "/command");
    assertCommandFormat(command.getPayload());
}
Also used : CommandEndpoint(org.eclipse.hono.util.CommandEndpoint) LoraCommand(org.eclipse.hono.adapter.lora.LoraCommand) Test(org.junit.jupiter.api.Test)

Example 2 with LoraCommand

use of org.eclipse.hono.adapter.lora.LoraCommand in project hono by eclipse.

the class JsonBasedLoraProvider method getCommand.

@Override
public LoraCommand getCommand(final CommandEndpoint commandEndpoint, final String deviceId, final Buffer payload, final String subject) {
    Objects.requireNonNull(commandEndpoint);
    Objects.requireNonNull(deviceId);
    Objects.requireNonNull(payload);
    Objects.requireNonNull(subject);
    if (Strings.isNullOrEmpty(commandEndpoint.getUri())) {
        throw new IllegalArgumentException("command endpoint uri is empty");
    }
    final JsonObject commandPayload = getCommandPayload(payload, deviceId, subject);
    commandEndpoint.getPayloadProperties().forEach(commandPayload::put);
    return new LoraCommand(commandPayload, commandEndpoint.getFormattedUri(deviceId));
}
Also used : JsonObject(io.vertx.core.json.JsonObject) LoraCommand(org.eclipse.hono.adapter.lora.LoraCommand)

Aggregations

LoraCommand (org.eclipse.hono.adapter.lora.LoraCommand)2 JsonObject (io.vertx.core.json.JsonObject)1 CommandEndpoint (org.eclipse.hono.util.CommandEndpoint)1 Test (org.junit.jupiter.api.Test)1