@SA
Is there a way to list all the devices of a customer on a widget? Preferably with additional metadata that will be stored in an external dataset?
Thanks.
@SA
Is there a way to list all the devices of a customer on a widget? Preferably with additional metadata that will be stored in an external dataset?
Thanks.
@SA
Hi Aline,
Thanks for that, got that working. How can I show the output of this on a dashboard?
Thanks.
@Vitor Lima
@sanimesa
To show it in a dashboard, you need to create a device just to store this information. You can use the connector Custom HTTPs for that.
In your analysis, you can use the following code to access this device and store the information in it as variables.
const { Device } = require("@tago-io/sdk");
const device = new Device("YOUR-DEVICE-TOKEN");
device.deleteData({ variables: ["device_name"], qty: 10000 });
device.sendData([
{ variable: "device_name", value: "Name of the device 1" },
{ variable: "device_name", value: "Name of th..." },
]);
If you want to add directly from the device list you have in your script, you can use the map function to do it easier.
device.deleteData({ variables: ["device_name"], qty: 10000 });
device.sendData(
device_list.map((device_info) => {
return {
variable: "device_name",
value: device_info.name,
serie: device_info.id,
};
})
).then(context.log, context.log);
The map() method creates a new array populated with the results of calling a provided function on every element in the calling array.
@SA
@vitor That’s a great workaround, thanks!
@SA
@vitor I am trying to implement this including the last data received from the device and ran into a little problem.
My analysis gets reference to a ‘metadata’ device, where I intend to store the data.
Then, I am getting the deviceInfo using a tag, so far so good.
Now I need to getData from each of the devices, but how do I get a reference to each device without the token? Is that possible?
Thanks.
@Vitor Lima
Hi @sanimesa,
There is no way to get the data without the token. But if you have the Device ID, you can get the token using the account class.
Check this answer bellow from another thread. You can use the function getTokenByName using the device ID.
![]()
operateData - device_token of device which received the last data
Hi [@Pauwel](/u/pauwel), Yes, that is possible. In order to do that, you need to use the Utils.getTokenByName function from TagoIO’s sdk. Bellow is a quick code on how to do that. You will need to generate a Account-token and enter it in your environment variable instead. \*\* Steps to generate an account\_token: \*\* 1 - Enter the following link: [https://admin.tago.io/account/](https://admin.tago.io/account/) \*\* 2 - Select your Profile. \*\* 3 - Enter Tokens tab. \*\* 4 - Generate a new Token with Expires Never. \*\* 5 - Press the Copy Butto…
@SA
@vitor Stuck again. I am now able to achieve most of the design - use a metadata device to store the value. Grab the devices of interest by tag and then grab their most recent data. However, not sure how to pass these to the metadata device. I was planning to use a separator in the value field for passing the device name and the last update time, but dynamic table has no way of splitting and displaying these.
Any suggestions?
Thanks.
@Vitor Lima
Hi @sanimesa,
You can use two different variables to store your data. Just make sure that the data on both variables has the same serie, since this is used by the Dynamic Table to make the data show in same line.
example:
[{
variable: "device_name",
value: "Device #01",
serie: "5f32bf0ee664b7002cfbca33"
},{
variable: "device_lastdata",
value: 25,
unit: "C",
serie: "5f32bf0ee664b7002cfbca33"
}]
Result:
@Johannes Koller
Dear Tago! To show a list (or all) devices on a dashboard should be a standard widget (funcuality) which Tago provides. To develop analysis and workarrounds is not a recommended way. I look forward for that functionality.