Writing a register
A device register can be written, based on the protocol the device supports
To access the API you must provide the `bearer token`.
Writing to 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 response | Description |
---|---|
Unauthorized | The request was not successful because: 1.You are not authenticated. 2. You are not part of the organisation |
Device not found or not enabled | The device ID was not found in this organisation or not enabled |
Invalid checksum | The 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 limited | You have exceeded your plans rate limiting |
Writing to a Generic 16 register
Send a POST
request to the API endpoint /api/orgs/{org-slug}/generic16/write
with, for example, the body:
{
"channel": <device channel>,
"device": <device address>,
"address": <start memory address for write>,
"data": [<array of 16 bit values to write>]
}
Replace {org-slug}
with your organisations slug.
you can find your slug in the organisations settings page
This will return the Modbus response for the request, for example:
{
"data": [<value from register>]
}
Example:
curl -X 'POST' \
'https://iotsimhub.net/api/orgs/<org-slug>/generic16/write' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer <token>" \
-d '{ "channel": <channel>,
"device": <device>,
"address": <start address>,
"data": [<array of 16 bit values to write>]}'
API error codes
The endpoint will return errors in the format:
{
"errors": {
"details": <error response>
}
}
Error response | Description |
---|---|
Unauthorized | The request was not successful because: 1.You are not authenticated. 2. You are not part of the organisation |
Device not found or not enabled | The 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 limited | You have exceeded your plans rate limiting |
Register not found | The specified register was not found on the device |
Illegal data access | Attempt to read multiple non consecutive registers |