@@ -14,7 +14,7 @@ module.exports = function (RED) {
1414 this . thing = config . thing ;
1515 this . propertyId = config . property ;
1616 this . propertyName = config . propname ;
17- this . arduinoClient = await connectionManager . getClientMqtt ( connectionConfig ) ;
17+ this . arduinoClient = await connectionManager . getClientMqtt ( connectionConfig , RED ) ;
1818 if ( this . arduinoClient && this . arduinoClient . connection . connected ) {
1919 await this . arduinoClient . onPropertyValue ( this . thing , this . propertyName , ( msg ) => {
2020 this . send (
@@ -63,7 +63,7 @@ module.exports = function (RED) {
6363 this . propertyName = config . name ;
6464 this . on ( 'input' , async function ( msg ) {
6565 try {
66- this . arduinoRestClient . setProperty ( this . thing , this . propertyId , msg . payload ) ;
66+ await this . arduinoRestClient . setProperty ( this . thing , this . propertyId , msg . payload ) ;
6767 const s = getStatus ( msg . payload ) ;
6868 if ( s != undefined )
6969 this . status ( { fill : "grey" , shape : "dot" , text : s } ) ;
@@ -107,33 +107,38 @@ module.exports = function (RED) {
107107 this . propertyId = config . property ;
108108 this . propertyName = config . name ;
109109 node . on ( 'input' , async function ( ) {
110- const now = moment ( ) ;
111- const end = now . format ( ) ;
112- const count = this . timeWindowCount
113- if ( count !== null && count !== "" && count !== undefined && Number . isInteger ( parseInt ( count ) ) && parseInt ( count ) !== 0 ) {
114- const start = now . subtract ( count * this . timeWindowUnit , 'second' ) . format ( ) ;
110+ try {
111+ const now = moment ( ) ;
112+ const end = now . format ( ) ;
113+ const count = this . timeWindowCount
114+ if ( count !== null && count !== "" && count !== undefined && Number . isInteger ( parseInt ( count ) ) && parseInt ( count ) !== 0 ) {
115+ const start = now . subtract ( count * this . timeWindowUnit , 'second' ) . format ( ) ;
115116
116- const result = await this . arduinoRestClient . getSeries ( this . thing , this . propertyId , start , end ) ;
117- const times = result . responses [ 0 ] . times ;
118- const values = result . responses [ 0 ] . values ;
119- let data = [ ] ;
120- if ( values && times ) {
121- values . forEach ( function ( item , index , array ) {
122- data . push ( {
123- x : moment ( times [ index ] ) . unix ( ) * 1000 ,
124- y : values [ index ]
117+ const result = await this . arduinoRestClient . getSeries ( this . thing , this . propertyId , start , end ) ;
118+ const times = result . responses [ 0 ] . times ;
119+ const values = result . responses [ 0 ] . values ;
120+ let data = [ ] ;
121+ if ( values && times ) {
122+ values . forEach ( function ( item , index , array ) {
123+ data . push ( {
124+ x : moment ( times [ index ] ) . unix ( ) * 1000 ,
125+ y : values [ index ]
126+ } ) ;
125127 } ) ;
126- } ) ;
127- }
128- node . send (
129- {
130- topic : config . name ,
131- payload : [ {
132- series : [ ] ,
133- data : [ data ]
134- } ]
135128 }
136- ) ;
129+ node . send (
130+ {
131+ topic : config . name ,
132+ payload : [ {
133+ series : [ ] ,
134+ data : [ data ]
135+ } ]
136+ }
137+ ) ;
138+ }
139+ } catch ( err ) {
140+ console . log ( err ) ;
141+ this . status ( { fill : "red" , shape : "dot" , text : "Error getting value" } ) ;
137142 }
138143 } ) ;
139144
@@ -233,20 +238,24 @@ module.exports = function (RED) {
233238 this . propertyId = config . property ;
234239 this . propertyName = config . name ;
235240 node . on ( 'input' , async function ( ) {
236-
237- const property = await this . arduinoRestClient . getProperty ( this . thing , this . propertyId ) ;
238- this . send (
239- {
240- topic : property . name ,
241- payload : property . last_value ,
242- timestamp : property . value_updated_at
243- }
244- ) ;
245- const s = getStatus ( property . last_value ) ;
246- if ( s != undefined )
247- this . status ( { fill : "grey" , shape : "dot" , text : s } ) ;
248- else
249- this . status ( { } ) ;
241+ try {
242+ const property = await this . arduinoRestClient . getProperty ( this . thing , this . propertyId ) ;
243+ this . send (
244+ {
245+ topic : property . name ,
246+ payload : property . last_value ,
247+ timestamp : property . value_updated_at
248+ }
249+ ) ;
250+ const s = getStatus ( property . last_value ) ;
251+ if ( s != undefined )
252+ this . status ( { fill : "grey" , shape : "dot" , text : s } ) ;
253+ else
254+ this . status ( { } ) ;
255+ } catch ( err ) {
256+ console . log ( err ) ;
257+ this . status ( { fill : "red" , shape : "dot" , text : "Error getting value" } ) ;
258+ }
250259 } ) ;
251260 this . on ( 'close' , function ( done ) {
252261 connectionManager . deleteClientHttp ( connectionConfig . credentials . clientid ) . then ( ( ) => { done ( ) ; } ) ;
0 commit comments