Hello,
When a new immutable device is created using the web API on a TagoCore, is it possible to also assign the Encoder Stack & Payload Parser? Or, is there any method other than having to log in to the TagoCore and select them manually?
Thank you!
Hello,
When a new immutable device is created using the web API on a TagoCore, is it possible to also assign the Encoder Stack & Payload Parser? Or, is there any method other than having to log in to the TagoCore and select them manually?
Thank you!
Yes, it is possible to assign the Encoder Stack & Payload Parser when creating a new device using the API. This can be achieved by using a Connector. A Connector is a feature that simplifies the management of device payload parsers and allows developers to showcase their products to others.
When you create a device using a Connector, the payload parser of the Connector is automatically assigned to the device. This means that you don’t have to manually select the payload parser for each device.
Here are the steps to create a Connector:
1. Access the following link: https://admin.tago.io/connectors
2. Click on the “Create your own connector” button located at the top right.
3. On the next page, click on the “Add connector” button at the top right.
4. In the modal that appears, provide a name and select the network server for your connector.
5. On the connector’s page, enter a description and an image URL.
6. Click on the “Payload Parser” tab in the top menu.
7. Insert JavaScript (NodeJS) code that decodes the data received from your device into a TagoIO compatible format.
8. Ensure that your code does not exceed 64kB and click on the “Save” button.
Once you have created the connector, you can use it to create devices. The payload parser of the connector will be automatically assigned to the devices created using it. This way, you can avoid having to manually select the payload parser for each device.
Here is an example of how to create a device with a specific connector using the TagoIO API:
POST /device
Content-Type: application/json
Authorization: YOUR-TOKEN-HERE
{
"name": "My Device",
"connector": "connector-id-here",
...
}
Hey Mateus,
Thanks for your response! I’m looking to specifically do this in TagoCore rather than Tago.io. I don’t see a way of adding device connectors in TagoCore currently, so is there another way to accomplish this?
Hi Jeffrey,
It’s possible to create a device with an encoder and parser using the following examples:
To create a new device:
curl --location 'http://localhost:8888/device' \--header 'Content-Type: application/json' \--header 'token: 303125d9-b63f-429c-9a84-3fe5f7940701' \--data '{ "name": "Test", "type": "mutable", "payload_parser": "/path/to/parser.js", "encoder_stack": [ "f22e91922b1882fecc0028a0e49fb194:network-everynet-encoder" ]}'
To update an existing device:
curl --location --request PUT 'http://localhost:8888/device/710161439e79b1955b109327' \--header 'Content-Type: application/json' \--header 'token: 303125d9-b63f-429c-9a84-3fe5f7940701' \--data '{ "payload_parser": "/path/to/parser.js", "encoder_stack": [ "f22e91922b1882fecc0028a0e49fb194:network-everynet-encoder" ]}'
Unfortunately, there’s currently no straightforward method to obtain the encoder stack ID. This ID is a combination of the plugin ID and the encoder name. I recommend creating a device with the required encoders and using the API to retrieve the information.