Dashboard input n00b

Hi guys!

I need a hint! :slight_smile:

On the dashboard I have a “Input text box” and a “Boolean button”. How to send this info to the device, that is CUSTOM HTTP?

I’ve tried something with Analysis and downlink, but I have some mixed filings there.

All the best,
Viorel

Hi @viorel.gheorghe
There should be a way to do this directly using the action (Post data to endpoint using HTTP) but to be honest I never figured out how that worked. Here is the approach I used in Analysis with Node JS, it uses scope so make sure that the data update directly triggers it to run, such as Actions > Variable > “variable_name” is Anything > Run Analysis. It should be easily scalable to multiple variables. Let me know if this helps or if you have other questions :+1:

//You can maybe remove some of these Tago requirements.
const { Utils, Account, Analysis, Device, Services } = require("@tago-io/sdk");
const axios = require("axios");

async function httpPost(context, scope) {

  //Create the environment
  const env_vars = Utils.envToJson(context.environment);

  //Make sure there is an account token
  if (!env_vars.account_token){
    throw 'Missing account_token environment var';
  }

  //Create an account object
  const account = new Account({ token: env_vars.account_token });

  //Get the name of the scope (caller)
  const {origin} = scope[0]

  //Get the token of the caller
  const device_token = await Utils.getTokenByName(account, origin);

  //Create device
  const device = new Device({ token: device_token })

  //Get data from device
  var data_name = await device.getData({
    query: "last_item",
    variable: "data_name"
  });

  //Log the data you just got
  context.log("Data: " + data_name[0].value)

  axios.post('http://127.0.0.1:0000/', {
    data: data_name[0].value
  })
  
}

module.exports = new Analysis(httpPost);

@andreas.gudmundsson, thank you!

Some sleep is required, and then let’s try this properly:)

All the best!

Later edit:

Playing with these Analysis made me seeing my lesser knowledge of Node JS :slight_smile:

My question needs some editing. From the device I make a GET HTTP request in order to see the value of the variables I want.

In my case I realize that I didn’t needed to send back to the device anything because is not helpful.

So it is best to make a GET HTTP request and read the variable of the input form.

Hi again,
Don’t worry! I found that playing around with the provided snippets (create an extra analysis that you don’t use so you can reference snippets whenever), regularly going back to improve old scripts and referencing the community & JS Documentation will help you achieve you goals and learn a lot. Once you’ve established a base of working scripts you can improve them over time and essentially use them as templates. If there are any general tasks you have difficulty with I’d be happy to share some of my templates.

Back to the topic; I just want to confirm a few things… What kind of device is it? The device wants to access the data you have stored within the Tago bucket using an HTTP GET request? Reference the API Documentation for overall details. Here’s a sample…

Request header MUST include: “Device-Token”
GET https://api.tago.io/data?variable[]=variableNameA&variable[]=variableNameB&query=last_item
You can then parse the most recent value of variableNameA out of result[0] and variableNameB out of result[1]

Two things to keep in mind. With this method, your device will not know when the value is updated. This method also relies on you hard coding the device token into the request header. I have several solutions for both of these but it gets exponentially more difficult so I won’t cover it unless you need it :sweat_smile:

Hi Andreas,

I have an Arduino zero with GPRS, GPS and SMS sending/receiving capabilities. This is used to monitor an container and to send to TAGO: temp & humidity, location and if it’s full.

In case the container is full, from TAGO gets its designation number, location from the device and:

  • sends an SMS from its own modem (to have redundancy, GPRS might be with issues) with designation number & location
  • send an email with the same thing.

From sending the data from the device I use REST POST HTTP.

In order to know the “designation number” that can be changed by the customer, my idea is to use REST GET HTTP.

So at a 5minutes interval I make a POST & GET HTTP. It is my solution so far.

BTW for GET function something makes me wonder. I have on dashboard an “input form” and a “toggle button”.
I want the last value posted to those. If i use the following syntax I get from the button last 5 states :frowning:
variable[]=variable_one&qty=1&variable[]=variable_two&qty=1

All the best!

Unfortunately I’m not very knowledgeable with Arduino, I know a thing or two about modems though :wink: From a quick search it seems like you can run NodeJS on Arduino. If it’s an option, the easiest approach may be to directly access the Tago SDK via Node on the Arduino… It would basically let the device stay connected to Tago and be notified of any changes and update in (almost) real time instead of asking every 5 minutes. If leaving the connection open or wasting data is a concern, you could have polling done this way too.

Using the API is definitely simpler if intervals are sufficient though! Make sure you have error checking (retry/alerts) in case a device loses connection :slight_smile:

I think you should only have the &qty=1 a single time at the end of the query:

variable[]=variable_one&variable[]=variable_two&qty=1

Unrelated to the Tago implementation, is the MSISDN you send the SMS to constant? I’m interested in GPRS, I haven’t used it before but I believe it’s being phased out soon along with 2G/3G?

I’ll try the idea with &qty=1. I have to finish a 48h continuous operation test.

NodeJS is not my first programming language, but I think in my particular operation it will be a problem.

In my case in order to obtain something from the modem/GPS device I have to use AT-commands. Sometimes I can make this in transparent mode, but usually if I want GPS info, the connection have to be put on hold. Is something to test :slight_smile:

I just need a little MVP to check if the hardware and software even in rough style works.

The MSISDN has been handled at this time automatically by the modem beautifully. GPRS is dying,
but we have in Romania a lot of mobile POS running on EDGE, and they will not be changed that fast.

For safety the modem has CAT M1 & NB-IOT bands. The programming has taken CAT M1 as backup connection, since we do not know how long the situation will last.