This FAQ will explain what cURL is, and how it can be used to retrieve/modify information regarding the BB-400 IO status.

cURL

cURL or ‘Client URL’ is a command line tool used to receive or modify data from the server. cURL is available on Linux and the latest version of Windows 10.  

http://www.brainboxes.com/files/pages/support/faqs/bb-400-faqs/logos/curl-logo.png

The BB-400 can listen to the REST commands (GET and POST) to control the IO lines; cURL is a useful way to send such requests. 

 

GET requests

GET commands can be used to receive the IO line status of the BB-400.

Syntax:

 cURL GET commands are sent using the following format:

$ curl [URL]

where URL stands for Uniform Resource Locator, and is the unique path/identifier to the resource. An example of a URL is the IP address of the BB-400 followed by a colon ( : ) and the port number the REST API server is running on. The URL for our BB-400 is: 192.168.0.85:9000, and this URL will be used to send cURL commands in the Linux window. It should be noted that GET requests do not explicitly contain the word "GET". 

The following cURL commands used on the Linux command line provide examples of how to obtain the IO line status, please modify the URL to match your BB-400's URL.

1. To get the IO lines status

$ curl 192.168.0.85:9000/io

Output:

{
    "inputs": [
        1,
        0,
        0,
        0,
        0,
        0,
        0,
        0
    ],
    "outputs": [
        0,
        1,
        1,
        1,
        1,
        1,
        1,
        1
    ]
}

2. To get the input state of the IO lines

$ curl http://192.168.0.85:9000/io/inputs

Output:

[
    1,
    0,
    0,
    0,
    0,
    0,
    0,
    0
]

3. To get the input state of a selected IO line

$ curl http://192.168.0.85:9000/io/inputs/0

Output:

1

4. To get the output states of the IO lines

$ curl http://192.168.0.85:9000/io/outputs

Output:


[
    0,
    1,
    1,
    1,
    1,
    1,
    1,
    1
]

5. To get the output state of a selected IO line

$ curl http://192.168.0.85:9000/io/outputs/0

Output:

0

POST requests

POST requests can be used to modify data, and in this example the POST commands will be used to set the IO lines of the BB-400. The cURL commands for POST requests are more complicated than the previously shown GET requests, and you will notice that they explicitly contain the word "POST" in the command.  

1. To set the output states of the IO lines

$ curl -X POST -d [1,1,1,1,1,1,1,1] http://192.168.0.85:9000/io/outputs

The "-d" option sends a POST request to the URL using data, which in this case is an array. The POST command sets the output line status but does not return an output within the command line. To see the status code of the request, add the "-i" option, as shown below:

 

$ curl -i -X POST -d [1,1,1,1,1,1,1,1] http://192.168.0.85:9000/io/outputs

Output:

HTTP/1.0 200 OK
Server: BaseHTTP/0.6 Python/3.5.3
Date: Mon, 12 Nov 2018 13:53:09 GMT
Content-type: application/json

2. To set the output state of a selected IO line

$ curl -i -X POST -d 0 http://192.168.0.85:9000/io/outputs/0

Output:

HTTP/1.0 200 OK
Server: BaseHTTP/0.6 Python/3.5.3
Date: Mon, 12 Nov 2018 13:57:21 GMT
Content-type: application/json

   

This FAQ has provided examples of cURL commands that can be used to retrieve information regarding the IO line status using GET and to modify the IO line status using POST commands.