Skip to content

Commit

Permalink
feat: update to cleaned-up wot-typescript-definitions (0.5.0-SNAPSHOT.4)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkovatsc committed Jun 20, 2018
1 parent e5df693 commit a0b56c3
Show file tree
Hide file tree
Showing 28 changed files with 893 additions and 1,237 deletions.
27 changes: 18 additions & 9 deletions examples/scripts/counter.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,21 @@ let thing = WoT.produce({

console.log("Created thing " + thing.name);

thing.addProperty(NAME_PROPERTY_COUNT, {
type: "integer",
observable: true,
writeable: true,
value: 23
});
thing.addProperty(
NAME_PROPERTY_COUNT,
{
type: "integer",
description: "current counter value",
"iot:custom": "nothing",
observable: true,
writeable: true
},
0);

thing.addAction(NAME_ACTION_INCREMENT);
thing.setActionHandler(
NAME_ACTION_INCREMENT,
(parameters) => {
() => {
console.log("Incrementing");
return thing.properties[NAME_PROPERTY_COUNT].get().then( (count) => {
let value = count + 1;
Expand All @@ -47,7 +51,7 @@ thing.setActionHandler(
thing.addAction(NAME_ACTION_DECREMENT);
thing.setActionHandler(
NAME_ACTION_DECREMENT,
(parameters) => {
() => {
console.log("Decrementing");
return thing.properties[NAME_PROPERTY_COUNT].get().then( (count) => {
let value = count - 1;
Expand All @@ -59,8 +63,13 @@ thing.setActionHandler(
thing.addAction(NAME_ACTION_RESET);
thing.setActionHandler(
NAME_ACTION_RESET,
(parameters) => {
() => {
console.log("Resetting");
thing.properties[NAME_PROPERTY_COUNT].set(0);
}
);

thing.set("support", "none");
console.info(thing.support);

thing.expose();
73 changes: 31 additions & 42 deletions examples/scripts/counterClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,47 +13,36 @@
* SPDX-License-Identifier: EPL-2.0 OR W3C-20150513
********************************************************************************/

var targetUri = "http://localhost:8080/counter";
WoT.fetch("http://localhost:8080/counter").then( async (td) => {

WoT.fetch(targetUri)
.then(function(td) {
let thing = WoT.consume(td);
console.log("TD: " + td);

// read property #1
thing.readProperty("count")
.then(function(count){
console.log("count value is ", count);
})
.catch(err => { throw err });

// increment property #1
thing.invokeAction("increment")
.then(function(count){
console.log("count value after increment #1 is ", count);
})
.catch(err => { throw err });

// increment property #2
thing.invokeAction("increment")
.then(function(count){
console.log("count value after increment #2 is ", count);
})
.catch(err => { throw err });

// decrement property
thing.invokeAction("decrement")
.then(function(count){
console.log("count value after decrement is ", count);
})
.catch(err => { throw err });

// read property #2
thing.readProperty("count")
.then(function(count){
console.log("count value is ", count);
})
.catch(err => { throw err });

})
.catch(err => { throw err });
console.info("=== TD ===");
console.info(td);
console.info("==========");

// using await for serial execution (note 'async' in then() of fetch())
try {
// read property #1
let read1 = await thing.properties.count.get();
console.info("count value is", read1);

// increment property #1
await thing.actions.increment.run();
let inc1 = await thing.properties.count.get();
console.info("count value after increment #1 is", inc1);

// increment property #2
await thing.actions.increment.run();
let inc2 = await thing.properties.count.get();
console.info("count value after increment #2 is", inc2);

// decrement property
await thing.actions.decrement.run();
let dec1 = await thing.properties.count.get();
console.info("count value after decrement is", dec1);

} catch(err) {
console.error("Script error:", err);
}

}).catch( (err) => { console.error("Fetch error:", err); });
57 changes: 31 additions & 26 deletions examples/scripts/example-blank.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,43 @@
try {
var thing = WoT.produce({ name: "tempSensor" });
// manually add Interactions
thing.addProperty({
name: "temperature",
value: 0.0,
schema: '{ "type": "number" }'
// use default values for the rest
}).addProperty({
name: "max",
value: 0.0,
schema: '{ "type": "number" }'
// use default values for the rest
}).addAction({
name: "reset",
// no input, no output
}).addEvent({
name: "onchange",
schema: '{ "type": "number" }'
});
thing
.addProperty(
"temperature",
{
type: "number"
},
0.0)
.addProperty(
"max",
{
type: "number"
},
0.0)
.addAction("reset")
.addEvent(
"onchange",
{
type: "number"
});

// add server functionality
thing.setActionHandler("reset", () => {
console.log("Resetting maximum");
thing.writeProperty("max", 0.0);
});
thing.setActionHandler(
"reset",
() => {
console.log("Resetting maximum");
return thing.properties.max.set(0.0);
});

thing.start();
thing.expose();

setInterval( async () => {
let mock = Math.random()*100;
thing.writeProperty("temperature", mock);
let old = await thing.readProperty("max");
thing.properties.temperature.set(mock);
let old = await thing.properties.max.get();
if (old < mock) {
thing.writeProperty("max", mock);
thing.emitEvent("onchange");
thing.properties.max.set(mock);
thing.events.onchange.emit();
}
}, 1000);

Expand Down
34 changes: 22 additions & 12 deletions examples/scripts/example-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,38 @@
********************************************************************************/

try {
// internal state, not exposed as Property
var counter = 0;

var thing = WoT.produce({ name: "EventSource" });
// manually add Interactions
thing.addAction({
name: "reset",
thing.addAction(
"reset",
{
// no input, no output
}).addEvent({
name: "onchange",
schema: '{ "type": "number" }'
});
})
.addEvent(
"onchange",
{
type: "number"
});

// add server functionality
thing.setActionHandler("reset", () => {
console.log("Resetting");
counter = 0;
});
thing.setActionHandler(
"reset",
() => {
console.log("Resetting");
counter = 0;
return new Promise((resolve, reject) => {
resolve();
});
});

thing.start();
thing.expose();

setInterval( async () => {
++counter;
thing.emitEvent("onchange", counter);
thing.events.onchange.emit(counter);
}, 5000);

} catch (err) {
Expand Down
8 changes: 5 additions & 3 deletions examples/scripts/example-td.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ try {
// WoT.procude() adds Interactions from TD
let thing = WoT.produce(thingDescription);
// add server functionality
thing.setPropertyReadHandler( (propertyName) => {
thing.setPropertyReadHandler(
"prop1",
(propertyName) => {
console.log("Handling read request for " + propertyName);
return new Promise((resolve, reject) => {
resolve(Math.random(100));
})
}, "prop1");
thing.start();
});
thing.expose();
} catch(err) {
console.log("Script error: " + err);
}
6 changes: 3 additions & 3 deletions packages/binding-coap/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@node-wot/binding-coap",
"version": "0.5.0-SNAPSHOT.1",
"version": "0.5.0-SNAPSHOT.2",
"description": "CoAP client & server protocol binding for node-wot",
"author": "Eclipse Thingweb <[email protected]> (https://thingweb.io/)",
"license": "EPL-2.0 OR W3C-20150513",
Expand All @@ -24,8 +24,8 @@
"typescript-standard": "0.3.30"
},
"dependencies": {
"@node-wot/td-tools": "0.5.0-SNAPSHOT.1",
"@node-wot/core": "0.5.0-SNAPSHOT.1",
"@node-wot/td-tools": "0.5.0-SNAPSHOT.2",
"@node-wot/core": "0.5.0-SNAPSHOT.2",
"coap": "0.21.0"
},
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/binding-coap/src/coap-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export default class CoapClient implements ProtocolClient {
// FIXME coap does not provide proper API to close Agent
return true;
}
public setSecurity = (metadata: any) => true;
public setSecurity = (metadata: Array<WoT.Security>) => true;

private uriToOptions(uri: string): CoapRequestConfig {
let requestUri = url.parse(uri);
Expand Down
6 changes: 3 additions & 3 deletions packages/binding-file/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@node-wot/binding-file",
"version": "0.5.0-SNAPSHOT.1",
"version": "0.5.0-SNAPSHOT.2",
"description": "File client protocol binding for node-wot",
"author": "Eclipse Thingweb <[email protected]> (https://thingweb.io/)",
"license": "EPL-2.0 OR W3C-20150513",
Expand All @@ -19,8 +19,8 @@
"typescript-standard": "0.3.30"
},
"dependencies": {
"@node-wot/td-tools": "0.5.0-SNAPSHOT.1",
"@node-wot/core": "0.5.0-SNAPSHOT.1"
"@node-wot/td-tools": "0.5.0-SNAPSHOT.2",
"@node-wot/core": "0.5.0-SNAPSHOT.2"
},
"scripts": {
"build": "tsc",
Expand Down
7 changes: 4 additions & 3 deletions packages/binding-http/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@node-wot/binding-http",
"version": "0.5.0-SNAPSHOT.1",
"version": "0.5.0-SNAPSHOT.2",
"description": "HTTP client & server protocol binding for node-wot",
"author": "Eclipse Thingweb <[email protected]> (https://thingweb.io/)",
"license": "EPL-2.0 OR W3C-20150513",
Expand All @@ -17,6 +17,7 @@
"@types/chai": "4.0.4",
"@types/node": "8.0.28",
"@types/request-promise": "4.1.41",
"wot-typescript-definitions": "0.5.0-SNAPSHOT.4",
"chai": "4.1.2",
"mocha": "3.5.3",
"mocha-typescript": "1.1.8",
Expand All @@ -27,8 +28,8 @@
"typescript-standard": "0.3.30"
},
"dependencies": {
"@node-wot/td-tools": "0.5.0-SNAPSHOT.1",
"@node-wot/core": "0.5.0-SNAPSHOT.1"
"@node-wot/td-tools": "0.5.0-SNAPSHOT.2",
"@node-wot/core": "0.5.0-SNAPSHOT.2"
},
"scripts": {
"build": "tsc",
Expand Down
Loading

0 comments on commit a0b56c3

Please sign in to comment.