BallAerospace / COSMOS

Ball Aerospace COSMOS
https://ballaerospace.github.io/cosmos-website/
Other
360 stars 127 forks source link

Unable to Use Curl With COSMOS 5.0.5 #1764

Closed schuuust closed 1 year ago

schuuust commented 1 year ago

Hello,

I am trying to use curl commands to communicate with Cosmos 5. However, most curl commands hang after reporting a successful upload. For example:

curl -X POST 'localhost:2900/cosmos-api/api' -H 'Authorization: <pw> -H 'Content-Length: 107' -H 'Content-Type: application/json-rpc' --data-raw '{"jsonrpc": "2.0", "method": "tlm", "params": ["INST", "HEALTH_STATUS", "TEMP1"], "id": 2}' -v

 Rebuilt URL to: localhost:2900/
    Trying 127.0.0.1...
 TCP_NODELAY set
 Connected to localhost (127.0.0.1) port 2900 (#0)
 POST / HTTP/1.1
 Host: localhost:2900
 User-Agent: curl/7.58.0
 Accept: */*
 Authorization: <pw>
 Content-Length: 107
 Content-Type: application/json-rpc

upload completely sent off: 77 out of 77 bytes

This command hangs until it is manually exited. Variants of this command (different methods or targets) hang similarly, while other variants (removing 'cosmos-api/api' and similar adjustments) return a BadRequest error. Other curl commands, such as curl localhost:2900, are able to reach the server normally and return HTML code.

I am using the following:

Thank you!

schuuust commented 1 year ago

Update:

I realized the command hangs due to an error in the command. If the 'Content-Length' header specifies a length greater than the actual content, it will cause the command to hang as it expects more data to eventually go through.

Here is the command I am using now:

curl http://localhost:2900 -H 'Content-Type: application/json-rpc' --data-raw '{"jsonrpc": "2.0", "method": "cmd", "params": ["INST", "PARAMS", {"VALUE1": 5, "VALUE2": 5, "VALUE3": 5, "VALUE4": 5, "VALUE5": 5}], "id": 1}' -v -k

It generates the following error message:

*   Trying 127.0.0.1:2900...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 2900 (#0)
> POST / HTTP/1.1
> Host: localhost:2900
> User-Agent: curl/7.68.0
> Accept: */*
> Content-Type: application/json-rpc
> Content-Length: 141
> 
* upload completely sent off: 141 out of 141 bytes
* Mark bundle as not supporting multiuse
< HTTP/1.1 400 Bad Request
< Accept-Ranges: bytes
< Content-Length: 303
< Content-Type: application/xml
< Date: Wed, 03 Aug 2022 16:02:44 GMT
< Server: MinIO
< Vary: Origin
< 
<?xml version="1.0" encoding="UTF-8"?>
* Connection #0 to host localhost left intact
<Error><Code>BadRequest</Code><Message>An error occurred when parsing the HTTP request POST at &#39;/tools/base/index.html&#39;</Message><Resource>/tools/base/index.html</Resource><RequestId></RequestId><HostId>651740be-f9f8-4204-b027-9e9ae2b8d6ce</HostId></Error>

Adding "POST" to the command generates the following error:

<Error><Code>BadRequest</Code><Message>An error occurred when parsing the HTTP request POST at &#39;/tools/base/index.html&#39;</Message><Resource>/tools/base/index.html</Resource><RequestId></RequestId><HostId>651740be-f9f8-4204-b027-9e9ae2b8d6ce</HostId></Error>* Could not resolve host: POST
* Closing connection 1
curl: (6) Could not resolve host: POST

Is there something I am missing in the curl syntax?

schuuust commented 1 year ago

Update: Figured out the proper syntax

curl POST 'http://localhost:2900/cosmos-api/api' --header 'Authorization: <password>' --data-raw '{"jsonrpc": "2.0","method": "<cmd/tlm>","params": ["<target_name>","<command>",{"<command_parameters>"}],"id": 0,"keyword_params": {"scope": "DEFAULT"}}'

This example sends the "START" command to the default "EXAMPLE" target: curl POST 'http://localhost:2900/cosmos-api/api' --header 'Authorization: <password>' --data-raw '{"jsonrpc":"2.0","method":"cmd","params":["EXAMPLE","START",{}],"id":5,"keyword_params":{"scope":"DEFAULT"}}'