1212 *
1313 * SPDX-License-Identifier: EPL-2.0 OR W3C-20150513
1414 ********************************************************************************/
15+
16+ /* eslint no-console: "off" */
17+
1518import { Servient } from "@node-wot/core" ;
1619import { OPCUAClientFactory } from "@node-wot/binding-opcua" ;
1720import { thingDescription } from "./opcua-coffee-machine-thing-description" ;
@@ -25,18 +28,27 @@ const pause = async (ms: number) => new Promise((resolve) => setTimeout(resolve,
2528 const thing = await wot . consume ( thingDescription ) ;
2629
2730 try {
28- thing . observeProperty ( "waterTankLevel" , async ( data ) => {
29- const waterTankLevel = await data . value ( ) ;
30- console . log ( "------------------------------" ) ;
31- console . log ( "tankLevel : " , waterTankLevel , "ml" ) ;
32- console . log ( "------------------------------" ) ;
33- } ) ;
34- thing . observeProperty ( "coffeeBeanLevel" , async ( data ) => {
35- const coffeBeanLevel = await data . value ( ) ;
36- console . log ( "------------------------------" ) ;
37- console . log ( "bean level : " , coffeBeanLevel , "g" ) ;
38- console . log ( "------------------------------" ) ;
39- } ) ;
31+ thing
32+ . observeProperty ( "waterTankLevel" , async ( data ) => {
33+ const waterTankLevel = await data . value ( ) ;
34+ console . log ( "------------------------------" ) ;
35+ console . log ( "tankLevel : " , waterTankLevel , "ml" ) ;
36+ console . log ( "------------------------------" ) ;
37+ } )
38+ . catch ( ( err ) => {
39+ console . error ( "Error observing waterTankLevel property:" , err ) ;
40+ } ) ;
41+ thing
42+ . observeProperty ( "coffeeBeanLevel" , async ( data ) => {
43+ const coffeBeanLevel = await data . value ( ) ;
44+ console . log ( "------------------------------" ) ;
45+ console . log ( "bean level : " , coffeBeanLevel , "g" ) ;
46+ console . log ( "------------------------------" ) ;
47+ } )
48+ . catch ( ( err ) => {
49+ console . error ( "Error observing coffeeBeanLevel property:" , err ) ;
50+ } ) ;
51+
4052 await thing . invokeAction ( "brewCoffee" , { CoffeeType : 1 } ) ;
4153 await pause ( 5000 ) ;
4254 await thing . invokeAction ( "brewCoffee" , { CoffeeType : 0 } ) ;
@@ -47,4 +59,6 @@ const pause = async (ms: number) => new Promise((resolve) => setTimeout(resolve,
4759 } finally {
4860 await servient . shutdown ( ) ;
4961 }
50- } ) ( ) ;
62+ } ) ( ) . catch ( ( err ) => {
63+ console . error ( "Script error:" , err ) ;
64+ } ) ;
0 commit comments