-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from DerTomm/development
Merge development changes into master branch for 1.0.2 release
- Loading branch information
Showing
6 changed files
with
109 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...in/java/de/reitho/serialMqttBridge/plugins/MySensorsCustomSerialMqttTimestampAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package de.reitho.serialMqttBridge.plugins; | ||
|
||
public class MySensorsCustomSerialMqttTimestampAdapter implements MqttPublishPreprocessingPlugin { | ||
|
||
private String mqttTopicPath; | ||
private String mqttPublishMessage; | ||
|
||
/* ******************************************************************************************************************************************************************** | ||
* (non-Javadoc) | ||
* @see de.reitho.serialMqttBridge.plugins.MqttPreprocessingPlugin#getPluginName() | ||
*/ | ||
@Override | ||
public String getPluginName() { | ||
return "MySensors Serial to MQTT adapter plugin with timestamp addition"; | ||
} | ||
|
||
/* ******************************************************************************************************************************************************************** | ||
* (non-Javadoc) | ||
* @see de.reitho.serialMqttBridge.plugins.AbstractPreprocessorPlugin#getPluginDescription() | ||
*/ | ||
@Override | ||
public String getPluginDescription() { | ||
return "This plugin converts converts MySensors serial message format into topic and message for MQTT publishing (adding timestamp to payload)."; | ||
} | ||
|
||
/* ******************************************************************************************************************************************************************** | ||
* (non-Javadoc) | ||
* @see de.reitho.serialMqttBridge.plugins.AbstractPreprocessorPlugin#processMessage(java.lang.String) | ||
*/ | ||
@Override | ||
public boolean processSerialMessage(String message) throws Exception { | ||
|
||
if (message.length() == 0 || !message.contains(";")) { | ||
return false; | ||
} | ||
|
||
mqttTopicPath = ""; | ||
mqttPublishMessage = ""; | ||
|
||
String[] topicTokens = message.split(";"); | ||
for (int i = 0; i < topicTokens.length - 1; i++) { | ||
if (i > 0) { | ||
mqttTopicPath += "/"; | ||
} | ||
mqttTopicPath += topicTokens[i]; | ||
} | ||
|
||
mqttPublishMessage = topicTokens[topicTokens.length - 1]; | ||
|
||
// If message is of type V_TRIPPED (16): add timestamp to payload | ||
if (mqttTopicPath.endsWith("/16")) { | ||
mqttPublishMessage += ";" + System.currentTimeMillis(); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
/* ******************************************************************************************************************************************************************** | ||
* (non-Javadoc) | ||
* @see de.reitho.serialMqttBridge.plugins.AbstractMqttPreprocessorPlugin#getPublishTopic() | ||
*/ | ||
@Override | ||
public String getPublishTopic() { | ||
return mqttTopicPath; | ||
} | ||
|
||
/* ******************************************************************************************************************************************************************** | ||
* (non-Javadoc) | ||
* @see de.reitho.serialMqttBridge.plugins.AbstractMqttPreprocessorPlugin#getPublishMessage() | ||
*/ | ||
@Override | ||
public String getPublishMessage() { | ||
return mqttPublishMessage; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters