proto-mqtt client
The proto-mqtt client is a wrapper for MQTT.js for easy interfacing with the proto-mqtt broker.
Use proto-mqtt client in your Node project
To use the proto-mqtt-client as a dependency in your project, put yourself in the project folder, and then execute the following :
npm install --save proto-mqtt-client
Use proto-mqtt client in a browser-sided project
In order to convert the Node JS library to a browser library, you'll need to install browserify :
npm install -g browserify
Then clone the source, build it, and then browserify it where you want :
git clone https://github.com/Nolyurn/proto-mqttcd proto-mqtt/apinpm installnpm buildbrowserify dist/index.js -o bundle.js
And your bundle.js
file is now ready to be used in your client-sided
applications.
Usage
Belonging to your privileges, you can use three different classes : one for each privilege. To connect to the broker, whatever is the class, the procedure is the same :
let client = "<proto-mqtt-broker_address>" user:"user" password:"pass"; // You can set callbacks on client events client;
Events fired depends on privilege type.
Admin
The Administrator has the privilege to create and delete users in the database, with the privilege of his choice.
You can see the references on the [[Admin wiki page|Admin]].
Moderator
The moderator has the power to create sensors and to delete those ones. He can specify the type, and the frequency for the simulated sensor.
You can see the references on the [[Moderator wiki page|Moderator]].
Client
The Client has the basic rights : those to connect to the values sent by the simulator.
You can see the references on the [[Client wiki page|Client]].
Examples
Admin
; let callbacks = { console; } { console; } let client = "ws://127.0.0.1:8080" user:"robert" password:"password123"; client;client;
Moderator
; let callbacks = { console; } { console; } let client = "ws://127.0.0.1:8080" user:"robert" password:"password123"; client;client;
Client
; let client = "ws://127.0.0.1:8080" user:"robert" password:"password123"; client; client; client; client; client; client;