πŸ“¦ Archived documentation: r1 (committed 2026-07-24) View current documentation β†’

udp

Connectionless UDP datagrams: fire-and-forget transmission and a single-port listener with optional AES-256 encryption.

udp works in both directions: udp.send() transmits fire-and-forget datagrams (no delivery confirmation β€” ideal for high-rate telemetry and syslog targets), and udp.handle() listens on a port and hands received packets to a callback, optionally decrypting them with AES-256.

Functions

udp.send()

udp.send(sourcePort, dest, payload, encrypted)

Transmits a UDP packet to a host and port.

Please use the latest firmware, On earlier firmware versions the sourcePort was omitted.

Arguments

NameTypeRequiredDefaultDescription
sourcePort yes β€” Source port for UDP datagrams
dest string yes β€” Destination in "host:port" form, e.g. "192.168.5.159:2115".
payload string | object yes β€” Datagram payload data
encrypted bool optional false Whether to use built in AES256 Encryption and integrity validation

Returns

number 0 = success, >0 = error code

Example

// UDP Stream Example

while(run()){

      let payload = {
      batteryVoltage: 15.3,
      uptime: now()
    };

	udp.send(4000,"192.168.5.159:2115",string(payload));
	waitMS(1000);
}

udp.handle()

udp.handle(port, handler, encrypt)

Listens for UDP packets on a port and passes them to a callback β€” only one listener is supported.

Registers the device's single UDP listener. The handler receives a request object whose req.data holds the packet payload β€” parse JSON payloads with JSON.parse(). When encrypt is true, payloads are decrypted with AES-256 and the integrity validated with a SHA256 checksum before the handler runs.

Arguments

NameTypeRequiredDefaultDescription
port number yes β€” UDP port to listen on, e.g. 9000.
handler function yes β€” Callback function(req){ … } β€” req.data is the received payload.
encrypt boolean yes β€” true to expect AES-256 encrypted payloads.

Example

udp.handle(9000, function(req){   // only a single udp.handle listener is supported
//req = {port:4000,host:"172.16.220.1",data:"{msg:\"Hello World!\"}"}

let data = JSON.parse(req.data);  // parse the received payload as JSON

print(data.msg);
  
}, false); // false: do not use AES-256 encryption or checksums