Skip to content

Commit

Permalink
Fix for configuration send topic. (#46)
Browse files Browse the repository at this point in the history
Version upped to 2.6.10.
  • Loading branch information
luxa94e authored and Nikola Antic committed Jul 13, 2018
1 parent 4e59f57 commit 238f6f1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

group 'com.wolkabout'

version '2.6.9'
version '2.6.10'

apply plugin: 'java'
apply plugin: 'maven-publish'
Expand Down
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ repositories {
}
dependencies {
compile 'com.wolkabout:wolk:2.6.9'
compile 'com.wolkabout:wolk:2.6.10'
}
```

Expand All @@ -33,7 +33,7 @@ Maven
<dependency>
<groupId>com.wolkabout</groupId>
<artifactId>wolk</artifactId>
<version>2.6.9</version>
<version>2.6.10</version>
<type>pom</type>
</dependency>
```
Expand Down
13 changes: 8 additions & 5 deletions src/main/java/com/wolkabout/wolk/protocol/JsonProtocol.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@

public class JsonProtocol extends Protocol {

private static final String P2D_ACTUATOR_SET = "p2d/actuator_set/d/";
private static final String ACTUATOR_SET = "p2d/actuator_set/d/";
private static final String ACTUATOR_GET = "p2d/actuator_get/d/";
private static final String ACTUATOR_STATUS = "d2p/actuator_status/d/";

private static final String CONFIGURATION_SET = "p2d/configuration_set/d/";
private static final String CONFIGURATION_GET = "p2d/configuration_get/d/";
private static final String CONFIGURATION_SEND = "d2p/configuration_get/d/";

private static final String SENSOR_READING = "d2p/sensor_reading/d/";

public JsonProtocol(MqttClient client, ActuatorHandler actuatorHandler, ConfigurationHandler configurationHandler) {
Expand All @@ -41,13 +44,13 @@ public JsonProtocol(MqttClient client, ActuatorHandler actuatorHandler, Configur

@Override
protected void subscribe() throws Exception {
client.subscribe(P2D_ACTUATOR_SET + client.getClientId() + "/r/#", new IMqttMessageListener() {
client.subscribe(ACTUATOR_SET + client.getClientId() + "/r/#", new IMqttMessageListener() {
@Override
public void messageArrived(String topic, MqttMessage message) throws Exception {
final HashMap<String, Object> actuation = JsonUtil.deserialize(message, HashMap.class);
final Object value = actuation.get("value");

final String reference = topic.substring((P2D_ACTUATOR_SET + client.getClientId() + "/r/").length());
final String reference = topic.substring((ACTUATOR_SET + client.getClientId() + "/r/").length());
final ActuatorCommand actuatorCommand = new ActuatorCommand();
actuatorCommand.setCommand(ActuatorCommand.CommandType.SET);
actuatorCommand.setReference(reference);
Expand Down Expand Up @@ -110,11 +113,11 @@ public void publish(Collection<Reading> readings) {
@Override
public void publish(Map<String, String> values) {
final ConfigurationCommand configurations = new ConfigurationCommand(ConfigurationCommand.CommandType.SET, values);
publish(CONFIGURATION_GET + client.getClientId(), configurations);
publish(CONFIGURATION_SEND + client.getClientId(), configurations);
}

@Override
public void publish(ActuatorStatus actuatorStatus) {
publish("d2p/actuator_status/d/" + client.getClientId() + "/r/" + actuatorStatus.getReference(), actuatorStatus);
publish(ACTUATOR_STATUS + client.getClientId() + "/r/" + actuatorStatus.getReference(), actuatorStatus);
}
}

0 comments on commit 238f6f1

Please sign in to comment.