These docs are for v3.0.2. Click to read the latest docs for v5.

Send Binary Using MQTT

  • The connection to the MQTT server is as below
    • Host: Your IP or Domain Name
    • Port: 1883 (default)
    • Client ID string should be formatted as "DEV_{DEVICE_ID}"
      • Example: DEV_ ESP8266-12123123
    • Username string should be formatted as DEV_{DOMAIN_KEY}
    • Password should be your API_KEY
    • MQTT Topic /{key}/device/{did}/msgs/bin/{dmdl}/{fwver}/{type}/{content-type}
      • type is your binary rule name
      • content-type is your binary data's content type (optional)
    • Data
      • Binary Data (byte[])

Legends

  • {key}
    • Domain Key
  • {did}
    • Device ID
  • {dmdl}
    • Device Model
  • {fwver}
    • Firmware Version
  • {type}
    • Binary Rule Name
  • {context-type} (optional)
    • Data MIME type

📘

Important

MQTT QOS (Quality Of Service) should be always 2

const mqtt = require('mqtt')

options={
  clientId: "DEV_your_device_id",
  username: "DEV_your_domain_key",
  password: "your_api_key",
  qos: 2,
  clean: true
};

const client = mqtt.connect('mqtt://your_host_or_ip', options)

topic = ' /your_domain_key/device/your_device_id/msgs/bin/device_model/fw_version/your_binary_rule';

payload = 'Your binary data'

client.on('connect', () => {
  client.publish(topic, payload)
})
import paho.mqtt.publish as publish

auth = {‘username’:”DEV_your_domain_key”, ‘password’:”your_api_key”}

clientid = "DEV_your_device_id"

topic = "/your_domain_key/device/your_device_id/msgs/bin/device_model/fw_version/your_binary_rule"

payload = "Your binary data"

publish.single(hostname="your_host_or_ip", auth=auth, topic=topic, payload=payload, qos=2, client_id=clientid)
require 'rubygems'
require 'mqtt'

payload = 'Your binary data'

topic = "/your_domain_key/device/your_device_id/msgs/bin/device_model/fw_version/your_binary_rule"

MQTT::Client.connect(
  :host => 'your_host_or_ip',
  :username => 'DEV_your_domain_key',
  :password => 'your_api_key',
  :qos => 2,
  :client_id => 'DEV_your_device_id'
) do |client|
  client.publish(topic, payload)
end
< script src = "mqttws31.js" >

var payload = "Your binary data";

var topic = "/your_domain_key/device/your_device_id/msgs/bin/device_model/fw_version/your_binary_rule"

var clientId = "DEV_your_device_id";

var message = new Paho.MQTT.Message(payload);
message.destinationName = topic;
message.qos = 2;

client = new Paho.MQTT.Client("your_host_or_ip", Number(80), "/mqtt", clientId);

// Called when the connection is made
function onConnect() {
	console.log(“Connected!”);
	client.send(message);
}

client.connect({
	onSuccess: onConnect,
	userName: “DEV_your_domain_key”,
	password: “your_api_key”
});


</script>

Examples

Receiving Messages

Data sent from from the platform to the device will be available at

Subscribe to MQTT Topic /{key}/device/{did}/cmds