Created
March 19, 2020 02:54
-
-
Save egekorkan/dfd0f999c22396a997eb10994e11aed6 to your computer and use it in GitHub Desktop.
A node-wot script that consumes another Thing and controls the temperature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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