How to use the createClient function from mqtt

Find comprehensive JavaScript mqtt.createClient code examples handpicked from public code repositorys.

49
50
51
52
53
54
55
56
57
58
  console.log("Connecting securely to MQTT broker at " + serviceSpec.properties.secureaddress + ":" +
    serviceSpec.properties.secureport);
  this.client = mqtt.createSecureClient(serviceSpec.properties.secureport, serviceSpec.properties.secureaddress,
    opts);
} else {
  this.client = mqtt.createClient(serviceSpec.port, serviceSpec.address);
}

this.spec = serviceSpec;
this.client.subscribe(this.spec.name);
fork icon10
star icon0
watch icon13

32
33
34
35
36
37
38
39
40

For the sake of simplicity, let's put the subscriber and the publisher in the same file:
```js
var mqtt = require('mqtt')

client = mqtt.createClient(1883, 'localhost');

client.subscribe('presence');
client.publish('presence', 'Hello mqtt');
fork icon0
star icon7
watch icon11

+ 7 other calls in file

187
188
189
190
191
192
193
194
195
196
  username:'thermostat-1a',
  password:'the password'
}

// client connection
var client = mqtt.createClient(port, host, settings);

setInterval(sendTemperature, 2000, client);

function sendTemperature(client){
fork icon0
star icon1
watch icon1

+ 3 other calls in file