add EspThermometerParser
This commit is contained in:
@ -33,9 +33,13 @@ public abstract class AMessageParser {
|
|||||||
|
|
||||||
public void enqueue(List<ADataObject> itemList) throws HottisCommonException {
|
public void enqueue(List<ADataObject> itemList) throws HottisCommonException {
|
||||||
for (ADataObject ado : itemList) {
|
for (ADataObject ado : itemList) {
|
||||||
queue.enqueue(ado);
|
enqueue(ado);
|
||||||
logger.debug("message enqueued");
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void enqueue(ADataObject item) throws HottisCommonException {
|
||||||
|
queue.enqueue(item);
|
||||||
|
logger.debug("message enqueued");
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract public void execute(LocalDateTime timestamp, String msgPayload);
|
abstract public void execute(LocalDateTime timestamp, String msgPayload);
|
||||||
|
@ -0,0 +1,41 @@
|
|||||||
|
package de.hottis.measurementCollector;
|
||||||
|
|
||||||
|
import de.hottis.common.MyQueue;
|
||||||
|
import de.hottis.smarthomelib.ADataObject;
|
||||||
|
import de.hottis.smarthomelib.TemperatureDataObject;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author wn
|
||||||
|
*/
|
||||||
|
public class EspThermometerParser extends AMessageParser {
|
||||||
|
|
||||||
|
static final String TOPIC = "IoT/espThermometer2/+/measurement";
|
||||||
|
|
||||||
|
public EspThermometerParser(Properties config, MyQueue<ADataObject> queue) {
|
||||||
|
super(TOPIC, config, queue);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(LocalDateTime timestamp, String msgPayload) {
|
||||||
|
try {
|
||||||
|
// BueroBochum 22.93 2.486 1577
|
||||||
|
String[] payloadParts = msgPayload.split(" ");
|
||||||
|
if (payloadParts.length != 4) {
|
||||||
|
throw new MeasurementCollectorException("invalid number of parts in message: " + msgPayload);
|
||||||
|
}
|
||||||
|
String name = payloadParts[0];
|
||||||
|
double temperature = Double.parseDouble(payloadParts[1]);
|
||||||
|
|
||||||
|
TemperatureDataObject tdo = new TemperatureDataObject(timestamp, name, temperature);
|
||||||
|
|
||||||
|
enqueue(tdo);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Exception when esp thermometer message: ", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -27,7 +27,7 @@ public class MeasurementCollector {
|
|||||||
mqttReceiver.connect();
|
mqttReceiver.connect();
|
||||||
logger.debug("MqttReceiver started");
|
logger.debug("MqttReceiver started");
|
||||||
|
|
||||||
JmsTopic<ADataObject> queue = new JmsTopic<ADataObject>(config, JmsTopic.Mode.PRODUCER);
|
JmsTopic<ADataObject> queue = new JmsTopic<>(config, JmsTopic.Mode.PRODUCER);
|
||||||
queue.init();
|
queue.init();
|
||||||
|
|
||||||
MBusParser mbusParser = new MBusParser(config, queue);
|
MBusParser mbusParser = new MBusParser(config, queue);
|
||||||
@ -35,6 +35,11 @@ public class MeasurementCollector {
|
|||||||
mbusParser.registerConfiguredDataParsers();
|
mbusParser.registerConfiguredDataParsers();
|
||||||
mqttReceiver.registerParser(mbusParser);
|
mqttReceiver.registerParser(mbusParser);
|
||||||
logger.debug("MBusParser started");
|
logger.debug("MBusParser started");
|
||||||
}
|
|
||||||
|
EspThermometerParser espThermometerParser = new EspThermometerParser(config, queue);
|
||||||
|
espThermometerParser.init();
|
||||||
|
mqttReceiver.registerParser(espThermometerParser);
|
||||||
|
logger.debug("EspThermometerParser started");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user