Use this Topic to Publish data to one or more variables of a Device

To send data to one or more variables, please Publish to the following Topic with the following parameters:

Topic

/v1.6/devices/<device_label>
FieldValueRequired
Hostindustrial.api.ubidots.comYes
Port1883/8883 (Non-TLS/TLS)Yes
UsernameYour Ubidots TokenYes
PasswordAny character or leave blankNo
Quality of Service0 or 1No

Payload

The accepted message payloads for different cases are as follows:

{"temperature": 27}
{
  "temperature": 27,
  "humidity": 55,
  "pressure": 78
}
{
  "temperature": {
    "value": 10,
    "timestamp": 1634311791000,
    "context": {
      "status": "cold"
    }
  }
}
{
  "temperature": {
    "value": 10,
    "timestamp": 1634311791000,
    "context": {
      "status": "cold"
    }
  },
  "humidity": {
    "value": 90,
    "timestamp": 1634311791000,
    "context": {
      "status": "High humidity"
    }
  },
  "pressure": {
    "value": 78,
    "timestamp": 1634311791000,
    "context": {
      "status": "Normal"
    }
  }
}
{
  "position": {
    "value": 1, 
    "context": {
      "lat": "6.5423", 
      "lng": "-70.5783"
    }
  }
}

📘

timestamp and context

The timestamp and context parameters are optional.

🚧

Timestamp Format

All timestamps must be in milliseconds. You can easily convert dates to timestamp values here.

Sending location data

You may use the context key to send location data. Ubidots will automatically recognize location data when using these variable labels:

  • position
  • location
  • gps

There are 3 ways to send location data:

{
  "position": {
    "value": 1, 
    "context": {
      "lat": "6.5423", 
      "lng": "-70.5783"
    }
  }
}
// Since the "value" of a dot is mandatory, this option will set the variable value to "1".

{
  "position": {
      "lat": "6.5423", 
      "lng": "-70.5783"
    }
}
// Since the "value" of a dot is mandatory, this option will set the variable value to  "1".

{
  "position": {
      "latitude": "6.5423", 
      "longitude": "-70.5783"
    }
}

👍

Location Data

You have a lot of ways to include longitude and latitude when sending your dots to Ubidots. Please refer to this documentation.

Examples

📘

Note

All the bash examples from this section make use of the Eclipse Mosquitto library, if you wish to test them please install it using the official instructions.

Send a value to a single Variable
Update a variable and let Ubidots apply a timestamp equal to the reception time:

$ mosquitto_pub \
-h 'industrial.api.ubidots.com' \
-t '/v1.6/devices/weather-station' \
-u 'BBFF-Rfcgaxns6HlVb155WA0RhSY85xNDmB' \
-p 1883 \
-q 1 \
-m '{"temperature": 27}'

Send a value to multiple Variables
Update multiple Variables with a value and let Ubidots apply a timestamp equal to the reception time:

$ mosquitto_pub \
-h 'industrial.api.ubidots.com' \
-t '/v1.6/devices/weather-station' \
-u 'BBFF-Rfcgaxns6HlVb155WA0RhSY85xNDmB' \
-p 1883 \
-q 1 \
-m '{
  "temperature": 27,
  "humidity": 55,
  "pressure": 78
}'

Send a Dot to a single Variable
Update a variable with a complete Dot by specifying context and/or timestamp:

$ mosquitto_pub \
-h 'industrial.api.ubidots.com' \
-t '/v1.6/devices/weather-station' \
-u 'BBFF-Rfcgaxns6HlVb155WA0RhSY85xNDmB' \
-p 1883 \
-q 1 \
-m '{
  "temperature": {
    "value": 10,
    "timestamp": 1634311791000,
    "context": {
      "status": "cold"
    }
  }
}'

Send a Dot to multiple Variables
Update multiple variables with a complete Dot by specifying context and timestamp:

$ mosquitto_pub \
-h 'industrial.api.ubidots.com' \
-t '/v1.6/devices/weather-station' \
-u 'BBFF-Rfcgaxns6HlVb155WA0RhSY85xNDmB' \
-p 1883 \
-q 1 \
-m '{
  "temperature": {
    "value": 10,
    "timestamp": 1634311791000,
    "context": {
      "status": "cold"
    }
  },
  "humidity": {
    "value": 90,
    "timestamp": 1634314561000,
    "context": {
      "status": "High humidity"
    }
  },
  "pressure": {
    "value": 78,
    "timestamp": 1634387651000,
    "context": {
      "status": "Normal"
    }
  }
}'

Send location data
Update a position variable so that the Device displays its location:

$ mosquitto_pub \
-h 'industrial.api.ubidots.com' \
-t '/v1.6/devices/weather-station' \
-u 'BBFF-Rfcgaxns6HlVb155WA0RhSY85xNDmB' \
-p 1883 \
-q 1 \
-m '{
  "position": {
    "value": 1, 
    "context": {
      "lat": "6.5423", 
      "lng": "-70.5783"
    }
  }
}'
$ mosquitto_pub \
-h 'industrial.api.ubidots.com' \
-t '/v1.6/devices/weather-station' \
-u 'BBFF-Rfcgaxns6HlVb155WA0RhSY85xNDmB' \
-p 1883 \
-q 1 \
-m '{
  "position": {
      "lat": "6.5423", 
      "lng": "-70.5783"
    }
}'
$ mosquitto_pub \
-h 'industrial.api.ubidots.com' \
-t '/v1.6/devices/weather-station' \
-u 'BBFF-Rfcgaxns6HlVb155WA0RhSY85xNDmB' \
-p 1883 \
-q 1 \
-m '{
  "position": {
      "latitude": "6.5423", 
      "longitude": "-70.5783"
    }
}'

Send historical data to a Device (data logger):
Send multiple Dots per variable. Each Dot requires its own timestamp

$ mosquitto_pub \
-h 'industrial.api.ubidots.com' \
-t '/v1.6/devices/weather-station' \
-u 'BBFF-Rfcgaxns6HlVb155WA0RhSY85xNDmB' \
-p 1883 \
-q 1 \
-m '{
  "temperature": [
    {"value": 10,"timestamp": 1634336087000},
    {"value": 11,"timestamp": 1634336088765}
  ],
  "humidity": [
    {"value": 90,"timestamp": 1634336087000},
    {"value": 95,"timestamp": 1634336088765}
  ],
  "pressure": [
    {"value": 78,"timestamp": 1634336087000},
    {"value": 82,"timestamp": 1634336088765}
  ]
}'

📘

Same timestamp for multiple values

If the same timestamp is needed for multiple values, then Publishing data with a global timestamp might be a good idea to save payload space. For more instructions, please view Publish data with global timestamp.