File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ const classes = {
4
4
Executor : require ( './Services/executor' ) ,
5
5
Hermes : require ( './Services/hermes' ) ,
6
6
Prometheus : require ( './Services/prometheus' ) ,
7
+ Starbase : require ( './Services/starbase' ) ,
7
8
Streaming : require ( './Services/streaming' ) ,
8
9
Timekeeper : require ( './Services/timekeeper' )
9
10
} ;
Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ class Starbase {
21
21
* @param {string } payload[].unit
22
22
*/
23
23
publishJSON ( clientId , clientSecret , hardwareId , payload ) {
24
- const mqttClient = new MQTT ( {
24
+ let mqttClient = new MQTT ( {
25
25
username : clientId ,
26
26
password : clientSecret ,
27
27
clientId : hardwareId ,
@@ -32,15 +32,30 @@ class Starbase {
32
32
try {
33
33
mqttClient . connect ( async ( err , client ) => {
34
34
if ( err ) {
35
+ client . end ( ) ;
35
36
return reject ( err ) ;
36
37
}
37
38
38
39
mqttClient . rawWrite ( 'json' , JSON . stringify ( payload ) ) ;
39
40
await new Promise ( resolve => setTimeout ( resolve , 1000 ) ) ;
40
41
client . end ( ) ;
42
+ mqttClient = null ;
43
+ return resolve ( ) ;
44
+ } ) ;
45
+
46
+ mqttClient . client . on ( 'error' , ( ) => {
47
+ mqttClient . client . end ( ) ;
48
+ mqttClient = null ;
49
+ return resolve ( ) ;
50
+ } ) ;
51
+ mqttClient . client . on ( 'disconnect' , ( ) => {
52
+ mqttClient . client . end ( ) ;
53
+ mqttClient = null ;
41
54
return resolve ( ) ;
42
55
} ) ;
43
56
} catch ( error ) {
57
+ mqttClient . client . end ( ) ;
58
+ mqttClient = null ;
44
59
return resolve ( ) ;
45
60
}
46
61
} ) ;
You can’t perform that action at this time.
0 commit comments