Reading a register

A device register can be read, based on the protocol the device supports

To access the API you must provide the `bearer token`.

See API Authentication

Reading a Modbus register

Send a POST request to the API endpoint /api/orgs/{org-slug}/modbus with, for example, the body:

{
  "modbus_type": <"rtu" | "tcp">,
  "channel": <device channel>,
  "raw": [<array of bytes for the Modbus request>]
}

raw is an array containing the Modbus request.

Replace {org-slug} with your organisations slug.

You can find your slug:
  • in the organisations settings page
  • from the organisations API

This will return the Modbus response for the request, for example:

{
  "data": [<array of bytes for the Modbus response>]
}

Example:

curl -X 'POST' \
'https://iotsimhub.net/api/orgs/<org-slug>/modbus' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer <token>" \
-d '{ "modbus_type: <"rtu" | "tcp">,
"channel": <channel>,
"data": [<Modbus data>] }'

API error codes

The endpoint will return errors in the format:

{
  "errors": {
    "details": <error response>
  }
}
Error responseDescription
UnauthorizedThe request was not successful because:
1.You are not authenticated.
2. You are not part of the organisation
Device not found or not enabledThe device ID was not found in this organisation or not enabled
Invalid checksumThe passed Modbus packet failed the checksum verification
Invalid protocol request: ...A read request was made to a device with the incorrect protocol
Your request has been rate limitedYou have exceeded your plans rate limiting
TCP Protocol invalidThe data packet was not valid a Modbus TCP data packet

Reading a Generic 16 bit register

Send a POST request to the API endpoint /api/orgs/{org-slug}/generic16/read with, for example, the body:

{
  "channel": <device channel>,
  "device": <device address>,
  "address": <start memory address for read>,
  "length": <number of registers to read>
}

Replace {org-slug} with your organisations slug.

you can find your slug in the organisations settings page

This will return the response for the request, for example:

{
  "data": [<array of 16 bit values read from start address>]
}

Example:

curl -X 'POST' \
'https://iotsimhub.net/api/orgs/<org-slug>/generic16/read' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer <token>" \
-d '{ "channel": <channel>,
"device": <device>,
"address": <start address>,
"length": <number of registers to read>}'

API error codes

The endpoint will return errors in the format:

{
  "errors": {
    "details": <error response>
  }
}
Error responseDescription
UnauthorizedThe request was not successful because:
1.You are not authenticated.
2. You are not part of the organisation
Device not found or not enabledThe device ID was not found in this organisation or not enabled
Invalid protocol request: ...A read request was made to a device with the incorrect protocol
Your request has been rate limitedYou have exceeded your plans rate limiting
Register not foundThe specified register was not found on the device
Illegal data accessAttempt to read multiple non consecutive registers