Passed
Push — master ( d06fb8...9f4cb8 )
by André
03:15 queued 01:29
created

spec/fixtures/mqtt/mqtt-send.js   A

Complexity

Total Complexity 4
Complexity/F 2

Size

Lines of Code 37
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 26
mnd 2
bc 2
fnc 2
dl 0
loc 37
rs 10
bpm 1
cpm 2
noi 1
c 0
b 0
f 0
1
let mqtt = require('mqtt')
2
3
let username = 'test',
4
	password = 'test',
5
	url = 'mqtt://0.0.0.0',
6
	port = 1883,
7
	topic = 'test'
8
9
let options = {
10
	username: username,
11
	password: password,
12
	port: port,
13
	clientId: 'mqtt-send',
14
	retain: true,
15
	will: {
16
		topic: 'device',
17
		payload: 'pipeline'
18
	}
19
}
20
21
let client = mqtt.connect(url, options)
22
23
client.on('connect', function () {
24
	client.subscribe(topic, function (err) {
25
		if (!err) {
26
			for ( let i = 0; i <= 1000; i++ ) {
27
				let message = `Hello message no. ${ i }`
28
				client.publish(topic, message, {
29
					qos: 0,
30
					retain: true
31
				})
32
				console.log(`Message sent: "${ message }"`)
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
33
			}
34
			client.end()
35
		}
36
	})
37
})
38