def updateDittoFeature(self, mqttClient, deviceInfo, executionResult):
        """Creates or updates the feature on ditto which represents this software module.
    
        Parameters
        ----------
        mqttClient : paho.mqtt.client
            The mqtt client that has the connection to the local mosquitto provided by the edge device.
        executionResult : Object
            Result of the script execution.
        """

        dittoRspTopic = "{}/{}/things/twin/commands/modify".format(
            deviceInfo.namespace, deviceInfo.deviceId)
        value = {}
        # See https://vorto.eclipseprojects.io/#/details/com.bosch.iotsuite.generic:Executor:1.0.0
        value["definition"] = ["com.bosch.iotsuite.generic:Executor:1.0.0"]
        value["properties"] = {}
        value["properties"]["status"] = {
            "files": self.files,
            "executionResult": executionResult,
            "executedAt": str(datetime.now())
        }
        path = "/features/" + self.featureId
        rsp = DittoResponse(dittoRspTopic, path, None)
        rsp.value = value
        mqttClient.publish("e", rsp.toJson(), qos=1)
Ejemplo n.º 2
0
    def register(self, mqttClient, deviceInfo):
        """Registers this agent as a feature in IoT-THings
    
        Parameters
        ----------
        mqttClient : paho.mqtt.client
            The mqtt client that has the connection to the local mosquitto provided by the edge device.
        deviceInfo : DeviceInfo
            Information of this device in the context of its subscription.
        """

        dittoRspTopic = "{}/{}/things/twin/commands/modify".format(
            deviceInfo.namespace, deviceInfo.deviceId)
        value = {}
        value["definition"] = ["org.example:PerformanceTest:2.0.0"]
        value["properties"] = {}
        value["properties"]["status"] = {
            "agentName": self.name,
            "agentVersion": self.version
        }
        path = "/features/" + self.featureId
        rsp = DittoResponse(dittoRspTopic, path, None)

        rsp.value = value
        mqttClient.publish("e", rsp.toJson(), qos=1)
Ejemplo n.º 3
0
def aknowledge(cmd, value=None):
    status = 200
    mosquittoTopic = "command///res/" + str(
        cmd.getRequestId()) + "/" + str(status)
    # print("======== Sending aknowledgement for ditto requestId: %s =============" %(cmd.getRequestId()))
    aknPath = cmd.path.replace(
        "inbox", "outbox"
    )  # # "/features/manually-created-lua-agent/outbox/messages/install"
    rsp = DittoResponse(cmd.dittoTopic, aknPath, status)
    rsp.prepareAknowledgement(cmd.dittoCorrelationId)
    if value:
        rsp.value = value

    client.publish(mosquittoTopic, rsp.toJson())
    print("======== Aknowledgement sent on topic " + mosquittoTopic +
          " =============")