Skip to content

Instantly share code, notes, and snippets.

@egekorkan
Created March 19, 2020 02:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save egekorkan/dfd0f999c22396a997eb10994e11aed6 to your computer and use it in GitHub Desktop.
Save egekorkan/dfd0f999c22396a997eb10994e11aed6 to your computer and use it in GitHub Desktop.
A node-wot script that consumes another Thing and controls the temperature
const TemperatureThingAddress = "http://localhost:8080/TemperatureController";
WoTHelpers.fetch(TemperatureThingAddress).then(async (TD) => {
try{
let temperatureThing = await WoT.consume(TD);
//check the room temperature every 1 second and increase it by 4 degrees if it is lower than 20 degrees
setInterval(async() => {
let curTemp = await temperatureThing.readProperty("temperature");
console.log("Room's Current Temperature is ", curTemp);
if (curTemp < 20) {
await temperatureThing.invokeAction("increment",4)
}
}, 1000);
temperatureThing.subscribeEvent("overheat",
x => console.log("!!!CONTACT THE FIRE DEPARTMENT!!!!"),
e => console.error("Error: %s", e),
() => console.info("Completed")
);
}
catch (err) {
console.error("Script error:", err);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment