Mqtt library

Index:

Functions:

mqtt-connect

mqtt-connect

Synopsis
Opens a mqtt connection.
Usage
(mqtt-connect
  host
  "username" => username
  "password" => password
)
Returns
connection_id
Where
  • host is string: the MQTT host address.
  • username is string[0..1]: the username to establish the connection.
  • password is string[0..1]: the user's password.
  • connection_id is string: the connection identifier.
Description
Establishes a connection to the specified MQTT host with the given username and password. It returns a connection identifier that is required in subsequent operations.
Examples
(mqtt-connect
  "tcp://iot.eclipse.org:1883"
  "username" => "brain4it_bot"
  "password" => "3248523"
)
"9f77ba0388134fcc872bf1595ec32a83"
Related functions
mqtt-disconnect

mqtt-disconnect

Synopsis
Closes a mqtt connection.
Usage
(mqtt-disconnect connection_id)
Returns
closed
Where
  • connection_id is string: the connection identifier.
  • closed is boolean: true if the connection was closed or false otherwise.
Description
Closes the given mqtt connection.
Examples
(mqtt-disconnect
  "9f77ba0388134fcc872bf1595ec32a83"
)
true
Related functions
mqtt-publish

mqtt-publish

Synopsis
Publishes a message.
Usage
(mqtt-publish connection_id topic payload)
Returns
sent
Where
  • connection_id is string: the connection identifier.
  • topic is string: the message topic.
  • payload is string: the message payload.
  • sent is boolean: true if message was sent successfully or false otherwise.
Description
Publishes a message with the given topic and payload.
Examples
(mqtt-publish conn "foo" "Hello world!")
true
mqtt-receive

mqtt-receive

Synopsis
Receives a message from the subscribed topics.
Usage
(mqtt-receive connection_id wait_millis)
Returns
message
Where
  • connection_id is string: the connection identifier.
  • wait_millis is number[0..1]: the number of milliseconds to wait for a message. If not specified, this function waits forever.
  • message is (topic payload)[0..1]: the message received. May be null if no message arribes in wait_millis milliseconds.
  • topic is string: the message topic.
  • payload is string: the message payload.
Description
Receives one message from the topics previously subscribed with the mqtt-subscribe function.
Examples
(mqtt-receive conn 2000)
("foo" "Hello World!")
Related functions
mqtt-subscribe

mqtt-subscribe

Synopsis
Subscribes a connection to a topic.
Usage
(mqtt-subscribe connection_id topic)
Returns
subscribed
Where
  • connection_id is string: the connection identifier.
  • topic is string: the message topic.
  • subscribed is boolean: true if the given connection was subsribed to the specified topic or false otherwise.
Description
Subscribes the given connection to the specified topic.
Examples
(mqtt-subscribe conn "foo")
true
Related functions
mqtt-unsubscribe

mqtt-unsubscribe

Synopsis
Unsubscribes a connection from a topic.
Usage
(mqtt-unsubscribe connection_id topic)
Returns
unsubscribed
Where
  • connection_id is string: the connection identifier.
  • topic is string: the message topic.
  • unsubscribed is boolean: true if the given connection was unsubsribed from the specified topic or false otherwise.
Description
Unsubscribes the given connection from the specified topic.
Examples
(mqtt-unsubscribe conn "foo")
true
Related functions
Top