Search in sources :

Example 1 with KuraPayload

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);
    }
}
Also used : KuraPayload(org.eclipse.kura.message.KuraPayload) Date(java.util.Date) ComponentException(org.osgi.service.component.ComponentException)

Example 2 with KuraPayload

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);
    }
}
Also used : KuraPayload(org.eclipse.kura.message.KuraPayload) Date(java.util.Date) ComponentException(org.osgi.service.component.ComponentException) KuraException(org.eclipse.kura.KuraException)

Example 3 with KuraPayload

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"));
}
Also used : KuraPayload(org.eclipse.kura.message.KuraPayload) Test(org.junit.Test) AbstractRouterTest(org.eclipse.kura.camel.component.AbstractRouterTest)

Example 4 with KuraPayload

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;
}
Also used : KuraPayload(org.eclipse.kura.message.KuraPayload) Date(java.util.Date)

Example 5 with KuraPayload

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;
}
Also used : KuraPayload(org.eclipse.kura.message.KuraPayload)

Aggregations

KuraPayload (org.eclipse.kura.message.KuraPayload)32 KuraException (org.eclipse.kura.KuraException)12 Date (java.util.Date)9 IOException (java.io.IOException)7 Test (org.junit.Test)5 ComponentException (org.osgi.service.component.ComponentException)5 KuraInvalidMessageException (org.eclipse.kura.KuraInvalidMessageException)4 KuraResponsePayload (org.eclipse.kura.message.KuraResponsePayload)4 TestTarget (org.eclipse.kura.test.annotation.TestTarget)4 Exchange (org.apache.camel.Exchange)3 Processor (org.apache.camel.Processor)3 RouteBuilder (org.apache.camel.builder.RouteBuilder)3 ByteString (com.google.protobuf.ByteString)2 Map (java.util.Map)2 KuraInvalidMetricTypeException (org.eclipse.kura.KuraInvalidMetricTypeException)2 KuraPayloadProto (org.eclipse.kura.core.message.protobuf.KuraPayloadProto)2 KuraTopic (org.eclipse.kura.message.KuraTopic)2 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1