Enable applications to connect to an MQTT broker to publish messages, and to subscribe to topics and receive published messages. It also provides some helper functions to make publishing one off messages to an MQTT server very straightforward. Tools are provided to interoperate with ‘MQTT’ message brokers in R.
Follow these steps to start using mqtt using R :
-
Download and install mosquitto for your OS ( https://mosquitto.org/download/ )
-
Open console and change to mosquitto installation directory
-
Write mosquitto -v in prompt and press enter - This will start the mosquitto broker on local host
-
Install rmqtt from CRAN
install.packages("rmqtt")
or from Githubremotes::install_github("boralprophecy/rmqtt")
-
In R, write
setwd( mosquitto_installation_directory )
to change to mosquitto installation directory -
Run
mqtt_topic_publish( topic = 'topic1', message_to_send = 'Hello World !' )
to publish the message Hello World ! to topic1 in local host -
Run
mqtt_topic_subscribe( topic = 'topic2' )
to subscribe to topic2
To create an effect of two clients, one publishing and another subscribing, install MQTT-Lens ( a chrome extension ). Then you can subscribe in R window and publish message from MQTT-Lens to test or vice versa.
Guide to use MQTT-Lens : http://www.steves-internet-guide.com/using-mqtt-lens/