Ubidots Developer Guides
Help CenterAPI ReferenceData APICommunity
  • Welcome to our Dev Guides
  • ⚡️ Getting Started
    • What is Ubidots?
    • Devices, Variables, and Dots
    • Technical FAQs
    • Business FAQs
  • 🧩Integration Guides
    • Industrial IoT
      • Advantech
      • Amplified Engineering
      • AWS
      • Azimut
      • Balena
      • Bivocom
      • CESVA
      • Controllino
      • Digital Communications Technologies (DCT)
      • Everactive
      • Golioth
      • Kepware
      • Kunbus
      • Monnit
      • MultiTech
      • NCD.io
      • Node-RED
      • Omicron IoT
      • Red Lion
      • Robustel
      • Senquip
      • Sielco
      • Siemens
      • Strega
      • vNode
      • WAGO
      • Weintek
      • YuDash
    • Cellular
      • Blues Wireless
      • Digi International
      • Hologram
      • Monogoto
      • Particle
      • Quectel
      • Soracom
    • LoRaWAN
      • AonChip
      • Chirpstack
      • Decentlab
      • Helium
      • ioThings
      • LORIOT
      • Milesight
      • MOKOSmart
      • RAKwireless
      • Sagemcom
      • Seeed Studio
      • Senet
      • The Things Industries
        • The Things Stack
        • The Things Network
    • Sigfox
      • Digital Matter
      • McThings
      • Sigfox
      • Suntech
      • Thinxtra
      • UnaBiz
    • Satellite
      • Swarm
    • Dev Kits
      • Adafruit
      • Advantech
      • AloriumTech
      • Arduino
      • Blues Wireless
      • DFRobot
      • Dragino
      • Electric Imp
      • Espressif Systems
      • McThings
      • Microchip Technology
      • Onion
      • Particle
      • Pycom
      • RAKwireless
      • Raspberry Pi
      • Seeed Studio
      • Sodaq
      • STMicroelectronics
      • Texas Instruments
      • Thinxtra
      • Verse Technology
    • Weather
      • Weather Plugins
      • Ambient Weather
    • Tools
      • Gambit Communications
      • PubNub
  • 📊Dashboards & Widgets
    • HTML Canvas
      • 3rd party packages
      • Preload Dashboard data
      • Built-in library
        • Properties
        • Methods
        • Listening events
        • API
      • Examples
        • Basics
        • Create an LCD screen with the HTML Canvas
        • Interacting with dashboard data
        • Change header's custom style
        • Adding real time using Socket.IO
        • Delete Variable data from a Device
        • Delete Variable data from Groups or Types of Devices
        • Navigation through Dashboard
        • Using a React library
      • Code editor
        • HTML Tab
        • CSS Tab
        • JavaScript Tab
    • Custom UI
      • Paragraph
      • Input combo
        • Text
        • Numeric
        • Numeric with buttons
        • Date
        • Time
        • Toggle
        • Dropdown
        • Multiple selection dropdown
      • Button
    • Custom Style
      • Dashboards
      • Widgets
    • Line chart
    • Pages
      • Getting started
      • Development
      • API
        • Page creation
        • Publish
  • 🤖UbiFunctions
    • Getting Started
      • Creating an UbiFunction
      • Coding an UbiFunction
      • Testing an UbiFunction
      • Authentication
      • Execution Time
      • Logs
    • Runtimes
      • Python
      • NodeJS
      • Custom Runtimes
    • Invocation
      • Time-based Trigger
      • HTTPS
      • MQTT Publish
      • Ubidots Event
    • Advanced
      • Account Token
      • Execution time
      • Raw Functions
      • CORS Policy
      • Async Execution
      • DaaS (Decoder as a Service)
      • Developing and Managing UbiFunctions with Ubidots CLI
    • Examples
    • Specs and Limits
    • Storage
      • File Storage API
      • Mutiple files
  • 🧩Plugins
    • What is a plugin?
    • Public vs. Private
    • Public plugins
      • Cron
      • Webhook
    • Private Plugins
      • Cron
      • Webhook
      • Widget
      • Device
    • Plugins development
      • Getting started
      • Cron
      • Webhook
      • Widget
      • Device
      • view.xml
      • view_widget.xml
    • Plugins deployment
      • Cron and Webhook
      • Widget
      • Device
    • Using the plugins
      • Cron and Webhook
      • Widget
      • Device
  • 📈SYNTHETIC VARIABLES
    • Getting started
      • Creating synthetic variables
      • Synthetic Variables' editor
    • Expressions
      • Mathematical
      • Date range
      • Rolling
      • Special functions
    • Specs and limits
    • Examples
      • Mathematical
      • Date range
      • Rolling
      • Special functions
  • ⌨️Developer tools
    • Javascript SDK
      • Overview
      • Getting started
      • Ubidots class
        • Get methods
        • Filter methods
        • Ubidots objects
          • Entity object
          • Paginator
      • Examples
    • CLI
      • Overview
      • Installing
      • Usage
      • SDK for UbiFunctions
  • 🏗️Apps
    • App builder
      • Custom sidebar
Powered by GitBook
On this page
  • Overview
  • Registering for an event
  • Available events
  • receivedToken
  • selectedDashboardDateRange
  • isRealTimeActive
  • dashboardRefreshed
  • selectedDevices
  • selectedDeviceObjects
  • selectedDashboardObject
  • selectedFilters
  • ready
  • Events relation with the class' properties

Was this helpful?

Export as PDF
  1. Dashboards & Widgets
  2. HTML Canvas
  3. Built-in library

Listening events

Access dashboard settings via event handlers

Overview

A event is an action that takes place in a dashboard at load time or triggered by other specific actions.

Registering for an event

You can register an event handler for any of the events above in the following way:

// Event handler registration
ubidots.on('<event>', eventHandler);

// Event handler definition
function eventHandler(args){
    // event handler's logic
};

or

// Event handler definition and registration
ubidots.on('<event>', function(data){
    // event handler's logic
});

The event handler function's arguments must match the event signature.

Available events

You can register event handlers for the following events:

Event
Triggered

receivedToken

At dashboard load time, when the token information is being retrieved.

selectedDashboardDateRange

Whenever the dashboard's date range is changed via GUI or a calling to the corresponding method.

isRealTimeActive

Whenever the dashboard's real time setting is changed via GUI or a calling to the corresponding method

dashboardRefreshed

When a user clicks the refresh button in the dashboard.

selectedDevices selectedDeviceObjects selectedDevice [DEPRECATED] selectedDeviceObject [DEPRECATED]

When the selected device in a dynamic dashboard is changed via GUI or a calling to the corresponding method.

selectedDashboardObject

At dashboard load time, when the dashboard information is being retrieved.

selectedFilters

After changing the dashboard's filters configuration

ready

At dashboard load time, after all other events have been triggered.

receivedToken

Handler argument: token: string ⇒ The user's default token.

Signature

function eventHandler(token) { }

Important note: The retrieved token inherits the users pemissions, either if it's an account admin, in which case it will have all permissions over the account resources accesible through the API, or an End-user, where access will be limited to its configured permissions.

selectedDashboardDateRange

Handler argument: timeframe: Object ⇒ The dashboard's timeframe.

{
    start: <start-timestamp>,
    end: <end-timestamp>
}

Signature

function eventHandler(timeframe) { }

isRealTimeActive

Handler argument: rt: Bool ⇒ The dashboard's real time update setting.

Signature

function eventHandler(rt) { }

dashboardRefreshed

Handler argument: None

Signature

function eventHandler() { }

selectedDevices

Handler argument: deviceIds: [string] ⇒ String array of the id's of the currently selected devices in a dynamic dashboard

Signature

function eventHandler(deviceIds) { }

selectedDeviceObjects

Handler argument: deviceObjects: [Objects] ⇒ Object array of the device objects of the currently selected devices in a dynamic dashboard

Signature

function eventHandler(deviceObjects) { }

selectedDashboardObject

Handler argument: dashboardObject: Object ⇒ dashboard object

Signature

function eventHandler(dashboardObject) { }

selectedFilters

Handler argument: dashboardFilters: [[Object]] ⇒ Array of arrays containing the filter objects. Each nested array corresponds to a filter configured on the dashboard.


[
   [
      {
         "type":"value",
         "value":"60",
         "variables":"~temperature",
         "lookup":"lte",
         "negate":false
      },
      {
         "type":"value",
         "value":"30",
         "variables":"~temperature",
         "lookup":"gte",
         "negate":false
      }
   ],
   [
      {
         "type":"value",
         "value":"60",
         "variables":"~humidity",
         "lookup":"lte",
         "negate":false
      },
      {
         "type":"value",
         "value":"30",
         "variables":"~humidity",
         "lookup":"gte",
         "negate":false
      }
   ]
]

Signature

function eventHandler(dashboardFilters) { }

ready

Handler argument: None

Signature

function eventHandler() { }

Events relation with the class' properties

Each of the events mentioned above is related to a property within the Ubidots class that can be used to retrieve exactly the same data as an alternative to setting an event handler and waiting for the event:

Ubidots class property
Associated event

dashboardDateRange

selectedDashboardDateRange

dashboardObject

selectedDashboardObject

deviceObject

selectedDeviceObject

selectedDevice

selectedDevice

selectedDeviceObjects

selectedDeviceObjects

selectedDevices

selectedDevices

token

receivedToken

realTime

isRealTimeActive

For example, you can configure an event to retrieve data from the selected device each time the dashboard's device picker is used, as shown below:

ubidots.on('selectedDeviceObject', function(device) {
    // Do something with the currently selected device data.
    // const deviceId = device.id;
    // const deviceLabel = device.label;
});

This way, everytime that the device picker is used, the logic within the event will be executed. As an alternative to this, if you don't require to perform an action upon the event triggering but only require the data of the currently selected device, you can just access the property related to the event as:

const deviceId = ubidots.selectedDevice;
PreviousMethodsNextAPI

Last updated 1 month ago

Was this helpful?

📊