예제 #1
0
def updateLastOperation(cmd, status, message, swModule=None):
    print(">>> sending sup update " + status + " with message: " + message)
    pth = "/features/{}/properties/status/lastOperation".format(cmd.featureId)

    dittoRspTopic = "{}/{}/things/twin/commands/modify".format(
        deviceInfo.namespace, deviceInfo.deviceId)
    rsp = DittoResponse(dittoRspTopic, pth, None)
    rsp.prepareSupResponse(cmd.getRolloutsCorrelationId(), status, message,
                           swModule)
    if status == "FINISHED_SUCCESS":
        print("======== Done =============")
        print(rsp.toJson())
    client.publish("e", rsp.toJson(), qos=1)
예제 #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)
    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)
def sendResponse(cmd):
    mr = cmd.getMeasurementData()
    print("Responding to : {},{}".format(mr.id, mr.serialNumber))
    pth = "/features/{}/properties/status/response".format(agent.featureId)

    dittoRspTopic = "{}/{}/things/twin/commands/modify".format(
        deviceInfo.namespace, deviceInfo.deviceId)
    rsp = DittoResponse(dittoRspTopic, pth)
    rsp.prepareMeasurementResponse(mr)
    client.publish("e", rsp.toJson(), qos=1)
예제 #5
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 +
          " =============")