FAQs
Contents
- cURL
- 1. To get the IO lines status
- 2. To get the input state of the IO lines
- 3. To get the input state of a selected IO line
- 4. To get the output states of the IO lines
- 5. To get the output state of a selected IO line
- 6. To get the counts of the IO lines
- 1. To set the output states of the IO lines
- 2. To set the output state of a selected IO line
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.
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 localhost:9000/path
The 9000 is the default port number the REST API server is running on.
The following cURL commands used on the Linux command line provide examples of how to obtain the IO line status. It should be noted that GET requests do not explicitly contain the word “GET”.
1. To get the IO lines status
$ curl localhost:9000/io
Output:
{
"counts":[
3,
3,
3,
2,
4,
1,
1,
2
],
"inputs":[
1,
1,
1,
1,
1,
1,
1,
1
],
"outputs":[
0,
0,
0,
0,
0,
0,
0,
0
]
}
2. To get the input state of the IO lines
$ curl localhost:9000/io/inputs
Output:
[
1,
0,
0,
0,
0,
0,
0,
0
]
3. To get the input state of a selected IO line
$ curl localhost:9000/io/inputs/0
Output:
1
4. To get the output states of the IO lines
$ curl localhost:9000/io/outputs
Output:
[
0,
1,
1,
1,
1,
1,
1,
1
]
5. To get the output state of a selected IO line
$ curl localhost:9000/io/outputs/0
Output:
0
6. To get the counts of the IO lines
$ curl localhost:9000/io/counts
Counts:
[
3,
3,
3,
2,
4,
1,
1,
2
]
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 in the previously shown GET requests.
1. To set the output states of the IO lines
$ curl -X POST -d [1,1,1,1,1,1,1,1] localhost: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 localhost: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.
Related FAQs
- How do I use Python to control the IO over REST on the BB-400
- How do I use Python to control the IO over WebSockets on my BB-400
- How to communicate using ASCII TCP between the BB-400 and a Linux or Windows system
- How to communicate with the REST API on the BB-400 using cURL commands
- How to communicate with the REST server on the BB-400 through PowerShell on Windows
- How to use the REST API on the BB-400 with the web application POSTMAN
- Using REST in Node-RED to Control IO
- What digital I/O lines does the BB-400 have?
- What is a Container?