Skip to content

Commit 9fd78a3

Browse files
author
Fabrizio Mirabito
committed
Fix example
1 parent 242dd57 commit 9fd78a3

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

examples/listenProperties/index.js

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ options = {
1010
}
1111

1212
// Connect to Arduino IoT Cloud MQTT Broker
13-
ArduinoIoTCloud.connect(options).then(() => {
13+
ArduinoIoTCloud.connect(options)
14+
.then(() => {
1415
console.log("Connected to Arduino IoT Cloud MQTT broker");
1516

1617
// Init Arduino API Client
@@ -19,19 +20,22 @@ ArduinoIoTCloud.connect(options).then(() => {
1920

2021
const thingsAPI = new ArduinoIoTAPI.ThingsV2Api(ArduinoIoTClient);
2122
const propertiesAPI = new ArduinoIoTAPI.PropertiesV2Api(ArduinoIoTClient);
22-
thingsAPI.thingsV2List().then(things => {
23+
24+
thingsAPI.thingsV2List()
25+
.then(things => {
2326
things.forEach(thing => {
24-
propertiesAPI.propertiesV2List(thing.id).then(properties => {
25-
properties.forEach(property => {
26-
ArduinoIoTCloud.onPropertyValue(thing.id, property.variable_name, update = value => {
27-
console.log(property.variable_name+": "+value)
28-
}).then(() => {
29-
console.log("Callback registered for "+property.variable_name);
30-
});
31-
});
27+
propertiesAPI.propertiesV2List(thing.id)
28+
.then(properties => {
29+
properties.forEach(property => {
30+
ArduinoIoTCloud.onPropertyValue(thing.id, property.variable_name,
31+
showUpdates = update = value => console.log(property.variable_name+": "+value))
32+
.then(() => console.log("Callback registered for "+property.variable_name))
33+
.catch(error => console.error(error));
34+
});
3235
})
36+
.catch(error => console.log(error));
3337
});
34-
}, error => {
35-
console.log(error)
36-
});
37-
});
38+
})
39+
.catch(error => console.error(error));
40+
})
41+
.catch(error => console.error(error));

0 commit comments

Comments
 (0)