mtconnect / cppagent

C++ Agent toolkit - Pre-built binaries, visit: https://github.com/mtconnect/cppagent/releases Docker images available at https://hub.docker.com/repositories/mtconnect
http://mtcup.org/
Apache License 2.0
143 stars 91 forks source link

Agent cannot parse json asset #477

Open robot-ranger opened 4 months ago

robot-ranger commented 4 months ago

Unless Im doing it wrong, It looks like the agent is expecting xml for assets. I tried sending the following with a curl command:

{
    "TaskArchetype": {
        "assetId": "LoadCnc",
        "Priority": 2,
        "TaskType": "MATERIAL_LOAD",
        "Coordinator": {
            "collaboratorId": "cnc1",
            "CollaboratorType": "CNC"
        },
        "Collaborators": {
            "Collaborator": {
                "collaboratorId": "r1",
                "CollaboratorType": "ROBOT"
            }
        },
        "SubTaskRefs": [
            {
                "order": "1",
                "value": "OpenDoor"
            },
            {
                "order": "2",
                "value": "MoveIn"
            },
            {
                "order": "3",
                "value": "ReleasePart"
            },
            {
                "order": "4",
                "value": "CloseChuck"
            },
            {
                "order": "5",
                "value": "MoveOut"
            },
            {
                "order": "6",
                "value": "CloseDoor"
            }
        ]
    }
}

curl -X POST "http://192.168.1.1:5000/asset/load-cnc-1?device=mxi_m001&type=TaskArchetype" -H "Content-Type: application/json" -d @load-cnc.json

but got:

<?xml version="1.0" encoding="UTF-8"?>
<MTConnectError xmlns:m="urn:mtconnect.org:MTConnectError:2.3"
    xmlns="urn:mtconnect.org:MTConnectError:2.3"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="urn:mtconnect.org:MTConnectError:2.3 /schemas/MTConnectError_2.3.xsd">
    <Header creationTime="2024-07-10T03:26:52Z" sender="0cfa26291d8b" instanceId="1720580135"
        version="2.3.0.16" deviceModelChangeTime="2024-07-10T02:55:35.142034Z" bufferSize="16384" />
    <Errors>
        <Error errorCode="INVALID_REQUEST">Could not parse Asset.</Error>
        <Error errorCode="INVALID_REQUEST">: Cannot parse asset</Error>
    </Errors>
</MTConnectError>

We had eliminated xml in favor of json response docs from the agent. Can we add json parser capability to cppagent's assets?

wsobel commented 4 months ago

This will need to be added as a feature. We do not have a json entity parser at the moment. I can add one, but it will be a lot of work with a full test suite.

I can start working on it soon.