Send Using UDP

  • Send the JSON Message (as byte array) Datagram packet
    • Host: Your IP or Hostname
    • Port: 5555
      • UDP Port can be configured in the platform
var udp = require('dgram');
var buffer = require('buffer');

var client = udp.createSocket('udp4');

var payload = {
  "header": {
    "key": "your_domain_key",
    "api": "your_api_key",
    "did": "your_device_id",
    "dmdl": "your_device_model",
    "fwver": "device_firmware_version",
    "mid": 1000
  },
  "data": {
    "latitude": 32.779167,
    "longitude": -96.808891,
    "temperature": 26,
    "humidity": 77,
    "precipitation": 0,
    "wind": 11
  }
};

var data = Buffer.from(JSON.stringify(payload));

client.send(data, 5555, 'your_host_or_ip', function(error){
  if(error){
    client.close();
  }else{
    console.log('Data sent !!!');
  }
});
import socket
import sys

# Create a UDP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

server_address = ('your_host_or_ip', 5555)
message = '{
  "header": {
    "key": "your_domain_key",
    "api": "your_api_key",
    "did": "your_device_id",
    "dmdl": "your_device_model",
    "fwver": "device_firmware_version",
    "mid": 1000
  },
  "data": {
    "latitude": 32.779167,
    "longitude": -96.808891,
    "temperature": 26,
    "humidity": 77,
    "precipitation": 0,
    "wind": 11
  }
}'

try:

    # Send data
    sent = sock.sendto(message, server_address)

finally:
    sock.close()
require 'socket'

payload = "{
  "header": {
    "key": "your_domain_key",
    "api": "your_api_key",
    "did": "your_device_id",
    "dmdl": "your_device_model",
    "fwver": "device_firmware_version",
    "mid": 1000
  },
  "data": {
    "latitude": 32.779167,
    "longitude": -96.808891,
    "temperature": 26,
    "humidity": 77,
    "precipitation": 0,
    "wind": 11
  }
}"

s = UDPSocket.new
s.send(payload, 0, 'your_host_or_ip', 5555)
s.close()

Worth Seeing