Total Complexity | 4 |
Complexity/F | 2 |
Lines of Code | 37 |
Function Count | 2 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 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 }"`) |
||
|
|||
33 | } |
||
34 | client.end() |
||
35 | } |
||
36 | }) |
||
37 | }) |
||
38 |