Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
danielpeintner committed May 6, 2020
2 parents 999819a + 9dfc77d commit e3286c5
Show file tree
Hide file tree
Showing 18 changed files with 1,206 additions and 33 deletions.
5 changes: 4 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
.git
.vscode
.vscode
.idea/
examples
**/node_modules
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,6 @@ packages/*
!packages/cli
!packages/browser-bundle
!packages/examples

# JetBrains IDEs
.idea/
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Install the Windows build tools through a CMD shell as administrator:
```
npm install -g --production windows-build-tools
```
> WSL: Windows Services for Linux should follow Linux instructions.
#### Mac OS
Meet the [node-gyp](https://github.com/nodejs/node-gyp#installation) requirements:
Expand Down Expand Up @@ -150,6 +151,8 @@ To reduce the size of the installation from about 800 MByte down to about 200 MB
* `sudo npm run link` does not work
* try `npm run unlock` from project root before calling `[sudo] npm run link`
* try `npm link` in each package directory in this order: td-tools, core, binding-\*, cli, demo-servients
* Build error around `prebuild: npm run bootstrap`
* This has been seen failing on WSL. Try using Node 12.13.0

### As a browser library

Expand Down Expand Up @@ -256,7 +259,9 @@ Note: More protocols can be easily added by implementing `ProtocolClient`, `Prot
#### MediaType Support

* JSON :heavy_check_mark:
* Plain text :heavy_check_mark:
* Text (HTML, CSS, XML, SVG) :heavy_check_mark:
* Base64 (PNG, JPEG, GIF) :heavy_check_mark:
* Octet stream :heavy_check_mark:
* CBOR :heavy_multiplication_x:
* EXI :heavy_multiplication_x:

Expand Down
75 changes: 75 additions & 0 deletions examples/scripts/coffee-machine-client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/********************************************************************************
* Copyright (c) 2018 - 2020 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0, or the W3C Software Notice and
* Document License (2015-05-13) which is available at
* https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document.
*
* SPDX-License-Identifier: EPL-2.0 OR W3C-20150513
********************************************************************************/
// This is an example of Web of Things consumer ("client" mode) Thing script.
// It considers a fictional smart coffee machine in order to demonstrate the capabilities of Web of Things.
// An accompanying tutorial is available at http://thingweb.io/smart-coffee-machine.html.
WoTHelpers.fetch("http://127.0.0.1:8080/Smart%20Coffee%20Machine").then(async (td) => {
try {
let thing = await WoT.consume(td);
log('Thing Description:', td);
// Read property allAvailableResources
let allAvailableResources = await thing.readProperty('allAvailableResources');
log('allAvailableResources value is:', allAvailableResources);
// Now let's change water level to 80
await thing.writeProperty('availableResourceLevel', 80, { 'uriVariables': { 'id': 'water' } });
// And see that the water level has changed
let waterLevel = await thing.readProperty('availableResourceLevel', { 'uriVariables': { 'id': 'water' } });
log('waterLevel value after change is:', waterLevel);
// This can also be seen in allAvailableResources property
allAvailableResources = await thing.readProperty('allAvailableResources');
log('allAvailableResources value after change is:', allAvailableResources);
// It's also possible to set a client-side handler for observable properties
thing.observeProperty('maintenanceNeeded', (data) => {
log('maintenanceNeeded property has changed! New value is:', data);
});
// Now let's make 3 cups of latte!
let makeCoffee = await thing.invokeAction('makeDrink', undefined, { 'uriVariables': { 'drinkId': 'latte', 'size': 'l', 'quantity': 3 } });
if (makeCoffee['result']) {
log('Enjoy your drink!', makeCoffee);
}
else {
log('Failed making your drink:', makeCoffee);
}
// See how allAvailableResources property value has changed
allAvailableResources = await thing.readProperty('allAvailableResources');
log('allAvailableResources value is:', allAvailableResources);
// Let's add a scheduled task
let scheduledTask = await thing.invokeAction('setSchedule', {
'drinkId': 'espresso',
'size': 'm',
'quantity': 2,
'time': '10:00',
'mode': 'everyday'
});
log(scheduledTask['message'], scheduledTask);
// See how it has been added to the schedules property
let schedules = await thing.readProperty('schedules');
log('schedules value: ', schedules);
// It's also possible to set a client-side handler for events
thing.subscribeEvent('outOfResource', (data) => {
log('outOfResource event:', data);
});
}
catch (err) {
console.error('Script error:', err);
}
});
// Print data and an accompanying message in a distinguishable way
function log(msg, data) {
console.info('======================');
console.info(msg);
console.dir(data);
console.info('======================');
}
Loading

0 comments on commit e3286c5

Please sign in to comment.