Send 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/{dmdl}/{fwver}/{mid}
    • Data
      • JSON Data

Legends

  • {key}
    • Domain Key
  • {did}
    • Device ID
  • {dmdl}
    • Device Model
  • {fwver}
    • Firmware Version
  • {mid}
    • Message ID

📘

QOS

MQTT QOS (Quality Of Service) should be always 2

Examples

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/device_model/fw_version/1000';

payload = '{
    "latitude": 32.779167,
    "longitude": -96.808891,
    "temperature": 26,
    "humidity": 77,
    "precipitation": 0,
    "wind": 11
}'

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/device_model/fw_version/1000"

payload = "{
    "latitude": 32.779167,
    "longitude": -96.808891,
    "temperature": 26,
    "humidity": 77,
    "precipitation": 0,
    "wind": 11
}"

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

payload = '{
  "latitude": 32.779167,
  "longitude": -96.808891,
  "temperature": 26,
  "humidity": 77,
  "precipitation": 0,
  "wind": 11
}'

topic = "/your_domain_key/device/your_device_id/msgs/device_model/fw_version/1000"

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 = {
        "latitude": 32.779167,
        "longitude": -96.808891,
        "temperature": 26,
        "humidity": 77,
        "precipitation": 0,
        "wind": 11
};

var topic = "/your_domain_key/device/your_device_id/msgs/device_model/fw_version/1000"

var clientId = "DEV_your_device_id";

var message = new Paho.MQTT.Message(JSON.stringigy(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>

Receiving Messages

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

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


Worth Seeing