use of org.eclipse.kura.message.KuraPayload in project kura by eclipse.
the class Heater method doPublish.
/**
* Called at the configured rate to publish the next temperature measurement.
*/
private void doPublish() {
// fetch the publishing configuration from the publishing properties
String topic = (String) this.m_properties.get(PUBLISH_TOPIC_PROP_NAME);
Integer qos = (Integer) this.m_properties.get(PUBLISH_QOS_PROP_NAME);
Boolean retain = (Boolean) this.m_properties.get(PUBLISH_RETAIN_PROP_NAME);
String mode = (String) this.m_properties.get(MODE_PROP_NAME);
// Increment the simulated temperature value
float setPoint = 0;
float tempIncr = (Float) this.m_properties.get(TEMP_INCREMENT_PROP_NAME);
if (MODE_PROP_PROGRAM.equals(mode)) {
setPoint = (Float) this.m_properties.get(PROGRAM_SETPOINT_NAME);
} else if (MODE_PROP_MANUAL.equals(mode)) {
setPoint = (Float) this.m_properties.get(MANUAL_SETPOINT_NAME);
} else if (MODE_PROP_VACATION.equals(mode)) {
setPoint = 6.0F;
}
if (this.m_temperature + tempIncr < setPoint) {
this.m_temperature += tempIncr;
} else {
this.m_temperature -= 4 * tempIncr;
}
// Allocate a new payload
KuraPayload payload = new KuraPayload();
// Timestamp the message
payload.setTimestamp(new Date());
// Add the temperature as a metric to the payload
payload.addMetric("temperatureInternal", this.m_temperature);
payload.addMetric("temperatureExternal", 5.0F);
payload.addMetric("temperatureExhaust", 30.0F);
int code = this.m_random.nextInt();
if (this.m_random.nextInt() % 5 == 0) {
payload.addMetric("errorCode", code);
} else {
payload.addMetric("errorCode", 0);
}
// Publish the message
try {
this.m_cloudClient.publish(topic, payload, qos, retain);
s_logger.info("Published to {} message: {}", topic, payload);
} catch (Exception e) {
s_logger.error("Cannot publish topic: " + topic, e);
}
}
use of org.eclipse.kura.message.KuraPayload in project kura by eclipse.
the class BluetoothLe method doPublishKeys.
// --------------------------------------------------------------------
//
// Private Methods
//
// --------------------------------------------------------------------
protected static void doPublishKeys(String address, Object key) {
KuraPayload payload = new KuraPayload();
payload.setTimestamp(new Date());
payload.addMetric("key", key);
try {
m_cloudClient.publish(m_topic + "/" + address + "/keys", payload, 0, false);
} catch (Exception e) {
s_logger.error("Can't publish message, " + "keys", e);
}
}
use of org.eclipse.kura.message.KuraPayload in project kura by eclipse.
the class TypeConverterTest method testFromMap.
@Test
public void testFromMap() {
final KuraPayload result = getCamelContext().getTypeConverter().convertTo(KuraPayload.class, Collections.singletonMap("foo", "bar"));
assertNotNull(result);
assertNotNull(result.getTimestamp());
assertEquals("bar", result.getMetric("foo"));
}
use of org.eclipse.kura.message.KuraPayload in project kura by eclipse.
the class PayloadFactory method create.
public KuraPayload create(final String key, final Object value) {
final KuraPayload result = new KuraPayload();
result.setTimestamp(new Date());
result.addMetric(key, value);
return result;
}
use of org.eclipse.kura.message.KuraPayload in project kura by eclipse.
the class PayloadFactory method create.
public KuraPayload create(final Date timestamp) {
final KuraPayload result = new KuraPayload();
result.setTimestamp(timestamp);
return result;
}
Aggregations