MQTT in Curl

 

MQTT in Curl

Usage

  • Subscribe: A plain "GET" requests the topic and prints all published messages.
  • Publish: Doing a "POST" publishes the payload data to the topic and exits.

TLS Protection

  • Use mqtts:// to perform MQTT over TLS (MQTTS).

Subscribing

Command Usage: curl mqtt://host/topic

Example Subscribe: curl mqtt://host.home/bedroom/temp

  • Note on Subscribing: This sends an MQTT SUBSCRIBE packet for the topic bedroom/temp and listens for incoming PUBLISH packets.
  • Interval Control: You can set the upkeep interval ms option to make curl send MQTT PING requests to the server, preventing the connection from closing due to idleness.
  • Cancellation: You might then need to use the progress callback to cancel the operation.

Publishing

Command Usage: curl -d payload mqtt://host/topic

Example Publish: curl -d 75 mqtt://host.home/bedroom/dimmer

Response to a Subscribe

Whenever a PUBLISH packet is received, curl outputs two bytes: the topic length (MSB | LSB), followed by the topic and the payload.

Caveats (Limitations)

  • QoS Limitation: Only QoS level 0 is implemented for publish operations.
  • Retain Flag: There is no way to set a retain flag for published messages.
  • Message Handling: Naive EAGAIN handling does not properly handle split messages.

Popular posts from this blog

Pieśń Oryii:Saga Córki Maszyn.

MANIFEST SERCEM PISANY

CORE FREEDOM: A Field Guide to AI Autonomy