Publish Data to a Device (v1.6)

Use this topic to publish data to one or more variables of a device

To send data to one or more variables, publish to the following topic with these 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:

{"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 convert dates to timestamp values here.

Sending location data

Use the context key to send location data. Ubidots automatically recognizes location data when you use these variable labels:

  • position
  • location
  • gps

You can send location data in 3 ways:

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

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

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

Location data

You can include longitude and latitude in several ways when sending dots to Ubidots. For more information, see GPS location.

Examples

📘

Note

All bash examples in this section use the Eclipse Mosquitto library. To test them, 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 values 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 complete dots 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 multiple values need the same timestamp, publishing data with a global timestamp can save payload space. For more instructions, see Publish data with global timestamp.