Overview

In this section, we’ll use the groov Manage REST API to interact with a digital channel.

Reading the State of a Digital Channel

The state of a digital channel can be read with the /api/v1/io/{device}/modules/{moduleIndex}/channels/{channelIndex}/digital/status endpoint.

In addition to the groov EPIC processor’s address and the API key, this endpoint also needs the module and channel indexes. They are specified directly in the URL endpoint.

For example, reading channel 4 on module 1, the request is:

curl -k -H apiKey:3KbLb7yZRxnTBP49nEmobDkrpmPkFoBo https://opto-01-02-03/manage/api/v1/io/local/modules/1/channels/4/digital/status

The response looks like:

{
    "modelType": "DigitalChannelRead",
    "moduleIndex": 1,
    "channelIndex": 4,
    "state": true,
    "onLatchState": false,
    "offLatchState": false,
    "featureType": 0,
    "featureValue": 0,
    "qualityDetail": 0,
    "counterActive": false
}

Turning a Digital Output On and Off

To turn a digital channel on or off, we need to use the PUT command, specify the content type as JSON, and pass in the value we wish to set.

The PUT command is set with -X PUT.

The Content-Type is set with -H "Content-Type: application/json".

To turn the channel off, we need to send this JSON object:

{
    "value": false
}

To do that, we use the -d flag and format the object correctly for the command line, like -d "{ \"value\": false}".

Put all together, the request is:

curl -k -X PUT  -H apiKey:3KbLb7yZRxnTBP49nEmobDkrpmPkFoBo  -H "Content-Type: application/json" https://opto-01-02-03/manage/api/v1/io/local/modules/1/channels/4/digital/state -d "{ \"value\": false}"

This request will not have a response object.

Next Step

Continue to reading and writing an analog channel.