Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!-- <script type="text/javascript" src = "mqttws31.js"></script> -->
- <script type="text/javascript" src = "browserMqtt.js"></script>
- <script type="text/javascript">
- /*
- Function: runClient
- create and run client to receive messages from mqtt broker and post these to api server
- for indexing
- Parameters :
- none
- Returns:
- none
- */
- function runClient () {
- console.log('running client');
- var options = {
- // protocolId: 'MQIsdp' // or 'MQIsdp' in MQTT 3.1.1
- // , protocolVersion: 3 // or 3 in MQTT 3.1
- clean: false // or false
- , clientId: '13'
- , keepalive: 60 // seconds, 0 is the default, can be any positive number
- // , username: config['BROKER']['USERNAME']
- // , password: new Buffer(config['BROKER']['PASSWORD']) // passwords are buffers
- // , will: {
- // topic: 'mydevice/status'
- // , payload: new Buffer('dead') // payloads are buffers
- // }
- }
- var client = mqtt.connect('ws://127.0.0.1:8080/mqtt', options);
- client.on('connect', function (connack) {
- // console.log(connack.sessionPresent)
- client.subscribe('/hello', {qos: 1}, function(error, granted){
- console.log(error)
- console.log(granted)
- })
- console.log('connected!')
- });
- client.on('message', function (topic, message, packet) {
- message = message.toString()
- console.log(message)
- });
- }
- runClient()
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement