Simple NodeJs App with MQTT
What is MQTT?
MQTT is a lightweight, publish-subscribe network protocol that transports messages between devices. The protocol usually runs over TCP/IP, however, any network protocol that provides ordered, lossless, bi-directional connections can support MQTT.
MQTT is used for data exchange between constrained devices and server applications. It keeps bandwidth requirements to an absolute minimum, handles unreliable networks, requires little implementation effort for developers, and is, therefore, ideal for machine-to-machine (M2M) communication.
Node JS Application using MQTT
Create a publish file. (pub.js)
Create a Subscriber file. (sub.js)
Now, we need to execute the application. Open two command prompt, one for publisher (pub.js) and one for subscriber (sub.js)
In Publisher Command Prompt, execute "node pub.js"
In Subscriber Command Prompt, execute "node sub.js"
Comments
Post a Comment