Hi,
I am trying to create an analysis using device.sendData()
without success, even with a simple code based on the snippet Operate data from device
:
/*
* Analysis Example
* Operate data from devices
*
* Read information from a variable generated by devices,
* run a simple calculation in real-time, and create a new variable with the output.
*
* Instructions
* To run this analysis you need to add a device token to the environment variables,
* To do that, go to your device, then token and copy your token.
* Go the the analysis, then environment variables,
* type device_token on key, and paste your token on value
*/
const { Analysis, Device, Utils } = require("@tago-io/sdk");
// The function myAnalysis will run when you execute your analysis
async function myAnalysis(context) {
// reads the values from the environment and saves it in the variable env_vars
const env_vars = Utils.envToJson(context.environment);
if (!env_vars.device_token) {
return context.log("Missing device_token environment variable");
}
const device = new Device({ token: env_vars.device_token, region: "usa-1" });
// Multiplies the water_level value by 2 and inserts it in another variable
const obj_to_save = {
variable: "water_level_double",
value: 10,
};
try {
await device.sendData(obj_to_save);
context.log("Successfully Inserted");
} catch (error) {
context.log("Error when inserting:", error);
}
}
module.exports = new Analysis(myAnalysis);
// To run analysis on your machine (external)
// module.exports = new Analysis(myAnalysis, { token: "YOUR-TOKEN" });
I got the device token from:
Any obvious thing I missed? Thanks