Ejemplo n.º 1
0
def publish_async(topic: str, message: bytes,
                  qos: QOS) -> concurrent.futures.Future:
    request = PublishToIoTCoreRequest()
    request.topic_name = topic
    request.payload = message
    request.qos = qos
    operation = ipc_client.new_publish_to_iot_core()
    operation.activate(request)
    future = operation.get_response()
    return future
def publish_results_to_iot_core (message):
    # Publish highest confidence result to AWS IoT Core
    global ipc_client
    request = PublishToIoTCoreRequest()
    request.topic_name = inference_result_topic
    request.payload = bytes(json.dumps(message), "utf-8")
    request.qos = QOS.AT_LEAST_ONCE
    operation = ipc_client.new_publish_to_iot_core()
    operation.activate(request)
    future = operation.get_response()
    future.result(10)
Ejemplo n.º 3
0
def publishMessage_mqtt(mqtt_topic, payload):
    try:

        message = json.dumps(payload)
        qos = QOS.AT_LEAST_ONCE

        request = PublishToIoTCoreRequest()
        request.topic_name = mqtt_topic
        request.payload = bytes(message, "utf-8")
        request.qos = qos
        operation = ipc_client.new_publish_to_iot_core()
        operation.activate(request)
        future = operation.get_response()
        future.result(TIMEOUT)

    except Exception as e:
        logging.info(
            "Publish MQTT Message Error : {0}, topic : {1}, payload : {2}".
            format(str(e), mqtt_topic, message))
Ejemplo n.º 4
0
ipc_client = client.GreengrassCoreIPCClient(connection)

opcUAclient = Client("opc.tcp://localhost:4840/freeopcua/server/")

try:
    opcUAclient.connect()
    val = opcUAclient.get_node("ns=2;i=2")

    while True:
        dataValue = val.get_data_value().Value
        value = float(dataValue.Value)
        topic = "OPCUAServer1/test/myVariable"
        qos = QOS.AT_LEAST_ONCE

        request = PublishToIoTCoreRequest()
        request.topic_name = topic
        request.payload = bytes('{"value": "' + str(value) + '"}', "utf-8")
        request.qos = qos
        operation = ipc_client.new_publish_to_iot_core()
        operation.activate(request)
        future = operation.get_response()
        future.result(TIMEOUT)

        variant = Variant(double_value=value)
        siteWiseTopic = "/testvariable/opcua"

        try:
            print("Appending IoTSiteWiseEntry to stream")
            streamClient.append_message(
                stream_name,
                Util.validate_and_serialize_to_json_bytes(