mqtt_topic_subscribe: Subscribes to mqtt topics

View source: R/mqtt_topic_subscribe.R

mqtt_topic_subscribeR Documentation

Subscribes to mqtt topics

Description

The function mqtt_topic_subscribe subscribes to mqtt topics

Usage

mqtt_topic_subscribe(
  topic,
  intern = F,
  host = "localhost",
  port = NULL,
  num.messages = 0,
  timeout = 0,
  qos = 0,
  verbose = F,
  append.eol = T,
  enable.debugging = F,
  clientid = NULL,
  keepalive = 60
)

Arguments

topic

character string, mqtt topic to subscribe to.

intern

logical (not NA), indicates whether to capture the output as an R character vector. Defaults to FALSE.

host

character string, mqtt host to connect to. Defaults to localhost.

port

integer, connect to the specified port. Default NULL denotes 1883 for plain MQTT or 8883 for MQTT over TLS.

num.messages

non negative integer, disconnect and exit the program immediately after the given count of messages have been received. Defaults to 0, means it continues to collect messages until stopped using Ctrl + C.

timeout

non negative integer, specifies a timeout in seconds how long to process incoming MQTT messages. Defaults to 0, means no timeout.

qos

integer : 0 or 1 or 2, quality of service level to use for the subscription. Defaults to 0.

verbose

logical (not NA), print received messages verbosely. With this argument, messages will be printed as "topic payload". When this argument is not given, the messages are printed as "payload". Default is FALSE.

append.eol

logical (not NA), whether to add an end of line character when printing / capturing ( see intern ) the payload. Defaults to TRUE.

enable.debugging

logical (not NA), whether debug messages should be enabled. Default is FALSE.

clientid

character string, id to use for this client. Defaults to NULL, means mosquitto_sub_ appended with the process id of the client.

keepalive

positive integer, umber of seconds between sending PING commands to the broker for the purposes of informing it we are still connected and functioning. Defaults to 60 seconds.

Details

If both num.messages and timeout is supplied, disconnection happens whichever condition is fulfilled first. append.eol allows streaming of payload data from multiple messages directly to another application unmodified. Only really makes sense when not using verbose.

Examples



mqtt_topic_subscribe( topic = 'magicblock/demo_user/temperature2', host = 'test.mosquitto.org' )


#.... Stores output as R character vector. Turning it off, just prints the output to console ....


mqtt_topic_subscribe( topic = 'magicblock/demo_user/temperature2', intern = T,
host = 'test.mosquitto.org' )


#.... Disconnects after receiving 5 messages ....


mqtt_topic_subscribe( topic = 'magicblock/demo_user/temperature2', host = 'test.mosquitto.org',
 num.messages = 5 )


#.... Disconnects after 6 seconds of starting connection with broker, also showing verbose ....


mqtt_topic_subscribe( topic = 'magicblock/demo_user/temperature2', host = 'test.mosquitto.org',
 timeout = 6, verbose = T )


#.... End of line character is not added after messages are received ....


mqtt_topic_subscribe( topic = 'magicblock/demo_user/temperature2', host = 'test.mosquitto.org',
 num.messages = 5, append.eol = F )


#.... Enabling debug messages .....

mqtt_topic_subscribe( topic = 'magicblock/demo_user/temperature2', host = 'test.mosquitto.org',
 num.messages = 5, enable.debugging = T )



boralprophecy/rmqtt documentation built on Aug. 7, 2023, 1:33 p.m.