const { Account, Resources, Analysis, Device, Utils, Services } = require("@tago-io/sdk");
async function updateTag(context, scope) {
// Requires scope to know what device and what widget called it
if (!scope[0]) throw "Scope is missing";
// Read the stored account_token and make an account object
const env_vars = Utils.envToJson(context.environment);
const account = new Account({ token: env_vars.account_token });
const res = new Resources({ token: env_vars.account_token });
// Get the device id of the caller
const origin = scope[0].device;
const dd = scope.find(x => x.variable === 'downlink_data');
port = { value: 2 };
console.debug(`Device ID: ${scope[0].device}`);
const result = await Utils.sendDownlink(account, origin, {
payload: "ZwIBAmwW",
port: Number(port.value),
confirmed: false,
}).catch((error) => error);
console.log(result);
}
module.exports = new Analysis(updateTag);