Ubidots Community

Multiple variable read for HTML for Valve Status

We have 16 valves status (ON / OFF) to be displayed on dashboard.

We first used status widgets of Ubidots, but found following limitations:

  1. Ubidots status widgets are too large. It took full dashboard page for 16 valves!
  2. It shows device name with every valve.
  3. Even with “auto play” sometimes, the status was not refreshed smoothly.
    Effectively, customer discarded above. And we moved to custom HTML widget…

We developed custom HTML widget. We have 16 valves with API labels: (valve01 to valve16).
Valve names are as per customer requirement.

  1. We use CSS to make smaller status LEDs (ON / OFF / UNKNOWN).
  2. We are reading each variable separately using GET API. We use device token and variable API labels. The variable API labels are stored in array in our javascript.
  3. But the process is too slow and we are making 16 calls to Ubidots. Each valve takes 3-5 seconds to get updated…

How can we read all 16 valves (last value) in single HTTP API call?

  1. We don’t want to store variable ID in the HTML page.

  2. We can only manage to store device ID (and list of valve API labels ) stored in CSS file.
    Because, we will need to copy/paste dashboard for every new device we create for customer.

  3. We use “/values?page size=1” to get last value.

The valve status are updated every 1 minute by our IoT device. Customer wants “realtime” update.

Basically, single API call to get last value for list of variable API labels (not variable IDs)!

I can foresee following option: In API 2.0, we could see to get “all variable list”. In this case, we fetch all variables. Filter the variable IDs using API labels. And then make a last Value call using list of variable IDs that we want.

Please suggest most efficient and fast response option for same…

regards,
Sunand Mittal

  1. On further investigation, I found that below call provide last value of variables also!
    https://industrial.api.ubidots.com/api/v2.0/variables/” -X <device_token>

  2. So, I can parse the results, find my relevant valves and update in HTML LED status.

There would be some overhead as we will get lastValue of ALL variables (approx 40 variables in our case). And we will use only 16 variables. Also, many other information.

Is there option to get only relevant keys under “results”?

Thanks,
Sunand Mittal
YuDash Systems

Hello, @Sunand

I hope this note finds you well,

You can retrieve the last value of several variables using the raw series endpoint by setting the limit to one as follows, in this example I’m making the request using curl but this of cause can be done using javaScript inside the HTML Canvas:

curl -X POST 'https://industrial.api.ubidots.com/api/v1.6/data/raw/series' \
 -H 'Content-Type: application/json' \
 -H 'X-Auth-Token: <Your token>' \
 -d '{
  "variables": [<var_id1>, <var_id2>,<var_id3>],
  "columns": ["value.value", "timestamp"],
  "join_dataframes": false,
  "limit": 1
}'

For more information, you can check our API documentation for that endpoint. I’ll be attentive to your comments.

Regards,

-Santiago