rest API : can't send commands with more than 1 parameter

Hi everyone !

I am currently working on an Android app where I am trying to send a command with the Tango rest API. Until now, I have sent commands with only 0 or 1 parameters and I didn't experience any problem. However, I now need to send a command which has two parameters (and perhaps more later), and the command isn't received by my device server.

When I send the command, I receive a failure with the following JSON response :
{"errors":[{"reason":"TangoApi_CANNOT_EXECUTE_COMMAND","description":"Cannot execute command SetVoltage on SAGA_NG_001\/Laser_NG\/1","severity":"PANIC","origin":"Connection.command_inout()"},{"reason":"COMMAND_TO_EQUIPMENT_FAILED","description":" - result = 3\n","severity":"ERR","origin":"EquipmentLaser_NG::psSetVoltage"}],"quality":"FAILURE","timestamp":1624269539928}
{"reason":"TangoApi_CANNOT_EXECUTE_COMMAND","description":"Cannot execute command SetVoltage on SAGA_NG_001\/Laser_NG\/1","severity":"PANIC","origin":"Connection.command_inout()"}
{"reason":"COMMAND_TO_EQUIPMENT_FAILED","description":" - result = 3\n","severity":"ERR","origin":"EquipmentLaser_NG::psSetVoltage"}

I send the command with the following uri : "http://<ipAddress>:8844/tango/rest/rc4/hosts/127.0.0.1/20000/devices/SAGA_NG_001/Laser_NG/1/commands/SetVoltage"

I don't see in the previous JSON response what is the reason for the command to not be able to be executed.

Here are some points that could be importants :
  • I am using rest server rc4-0.1. I tried to switch to the rest server 1.22 by replacing the .jar file but I haven't been able to make it work.
  • If I send the same commands, but with no or one parameter, they are also not received by the device. I don't understand this behaviour, as I think that the device should receive the command and throw an error while parsing the parameters (because there are some missing parameters). However, when I put no or one parameter, I don't receive the previous JSON response, but instead of that I get a failure with no JSON and the following message : "java.io.EOFException: No content to map to Object due to end of input".
  • I think that the problem is linked to the commands who take 2 parameters, not to the parameters itself.

Do you have any idea about the reason of my problem ?

Best regards,
Nicolas Mienné
Thales Group.
Edited 2 years ago
Hi Nicolas,

I think you need to send an array when you want multiple input arguments, the same you would do it in pure Tango.

What was the problem with 1.22 exactly I wonder? That should work as you said - just replacing the jar

Cheers,
Edited 2 years ago
Hi Igor, thank you for your quick answer.

  • The arguments I give are in a JSON array format : "[0,7]".
  • When I tried to use the 1.22 API with the new jar, I did see at uri "http://<ipAddress>:8844/tango/rest/v11/hosts" :
  • {"rc4":"http://<ipAddress>:8844/tango/rest//rc4","v10":"http://<ipAddress>:8844/tango/rest//v10","v11":"http://<ipAddress>:8844/tango/rest//v11"}
    With the old jar, there was only the "rc4" key, so the new jar is successfully launched. However, when I go to "http://<ipAddress>:8844/tango/rest/rc4/hosts", I have the following error, and I have the same issue with "v10" and "v11" :
    {"errors":[{"reason":"No Tango host was specified","description":"","severity":"","origin":"org.tango.web.server.providers.TangoDatabaseProvider.filter(TangoDatabaseProvider.java:69)"}],"quality":"FAILURE","timestamp":1624028816045}
    My TANGO_HOST environment variable is correctly set and I also give the tango host in parameter when I launch the jar. Here is my bat command for launching the jar :
    start java -jar -DTANGO_HOST=127.0.0.1:20000 rest-server-1.22.jar test

[edit] : in order to run the 1.22 jar, I needed to update my Java Runtime. I installed the OpenJDK11.

Cheers,
Nicolas
Edited 2 years ago
OK, I see

Since some version rest-server does not have any default hosts, so you have to specify one in the URL e.g. "http://<ipAddress>:8844/tango/rest/v11/hosts/localhost;port=20000". Please note port matrix parameter, you need this to specify non-default Tango host port in v1.0&v1.1 or using old syntax "http://<ipAddress>:8844/tango/rest/rc4/hosts/localhost/20000" for rc4

Commands should work when you pass an array. Are you able to execute those commands without REST api?
Edited 2 years ago
Indeed, with the url formatted as you said, I am able to browse my Tango database in v1.1 using Firefox. However it seems that the API I use for the REST communication can't parse the response from the new version. After sending the command, in rc4 I get no error, in v11 I get :
com.google.gson.JsonParseException: The JsonDeserializer org.tango.web.server.v10.readers.CommandInOutBodyReader$CommandInOutDeserializer@49413e18 failed to deserialize json object &quot;EnergyMeter&quot; given the type class org.tango.rest.v10.entities.CommandInOut
For your second question : yes, these commands work with non-REST API and also on AtkPanel
Edited 2 years ago
Could you please specify which Tango type is used for the input argument of your command?
The command takes a DevVarUShortArray. I tried all the following syntaxes to give the parameters, which all result to the same issue :
"[0,1]", "0,1", "{0,1}", "(0,1)"
Hi,

I have tested against TangoTest DevVarUShortArray command and it works.

Request

PUT http://localhost:10001/tango/rest/v11/hosts/localhost/devices/sys/tg_test/1/commands/DevVarUShortArray
Accept: application/json
Authorization: Basic dGFuZ28tY3M6dGFuZ28=

{
"host":"localhost:10000",
"device":"sys/tg_test/1",
"name":"DevVarUShortArray",
"input":[0,1]
}


Response:

HTTP/1.1 200
Cache-Control: private
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Date: Wed, 23 Jun 2021 19:26:45 GMT
Keep-Alive: timeout=20
Connection: keep-alive

{
"host": "localhost:10000",
"device": "sys/tg_test/1",
"name": "DevVarUShortArray",
"input": [
0,
1
],
"output": [
0,
1
]
}

Response code: 200; Time: 2121ms; Content length: 107 bytes


Please note the correct argument - is an object, see device commands
Thank you for your answer.

I couldn't find the documentation of the REST API from the gitHub repository, the link at the end of your message helped me a lot.

I have been able to reproduce with a REST client the issue I had in V11 with my Android app (the com.google.gson.JsonParseException) : it is the response we get when "host" and "name" parameters are missing.

With the REST client I use for testing, I've been able to succesfully send the command with 2 parameters. I'll let you know if this also works with my Android app, but I'm pretty confident that it will work smile
Nicolas
I couldn't find the documentation of the REST API from the gitHub repository, the link at the end of your message helped me a lot.
Hi, the documentation is here: https://tango-controls.readthedocs.io/projects/rest-api/en/latest/

All the best, Piotr
 
Register or login to create to post a reply.