A simple mqtt client application implemented in scala for M2M communications.
A solution where the Dev_Raspi can send events to the broker and the Dev_Laptop can subscribe to the event, in which the RaspberryPi will send its temperature events to the Broker and the subscriber will listen to it
-
This project will use Mosquitto as a broker. So if you have not installed mosquitto please follow the links here (https://mosquitto.org/download/)
-
We are considering here two device solution : Dev_Laptop (Subscriber) and Dev_RasberryPi (Publisher)
-
So start your Mosquitto on Dev_Laptop.
-
Configure the application.conf with the port and the url of the mosquitto server.
-
Make a assembly jar of this project using the following command.
sbt assembly
-
Copy the jar to RaspberryPi using the scp command.
scp raspi-mqtt-client.jar pi@<pi-ip-address>:/home/pi/Projects/scala
-
Run the Publisher on Dev_RaspberryPi using the following command
java -cp raspi-mqtt-client.jar com.knoldus.MQTTPublisher
This will start the publisher to sending the temperature events to broker.
-
Run the Subscriber on Dev_Laptop using the following command
java -cp raspi-mqtt-client.jar com.knoldus.MQTTSubscriber
Hurray ! You have successfully developed a sample IOT application :)