Install NodeJS from the website https://nodejs.org/en/download
Copy the command or the path you are using to execute NodeJS programs in the Executor Path Configuration of CupCarbon:
Refer to Tutorials 1, 2 and 3 of the page Start with CupCarbon.
You can write NodeJS programs as explained in Section "Start With CupCarbon". The following NodeJS program allows to display alternately Hellow World! and the Blink (mark/unmark) of the device:
const {execSync} = require('child_process');
while (true) {
console.log("print Hello")
console.log("mark")
execSync('sleep 1')
console.log("print World !")
console.log("unmark")
execSync('sleep 1')
}
const mqtt = require("mqtt")
const client = mqtt.connect("mqtt://***broker***")
client.on("connect", () => {
client.subscribe("***topic***", (err) => {
if (!err) {
console.log("print Connected!")
}
})
})
client.on("message", (topic, message) => {
console.log(message.toString())
if(message=="0") console.log("mark")
if(message=="1") console.log("unmark")
})
const mqtt = require("mqtt")
const client = mqtt.connect("mqtt://***broker***")
x = 1
client.on("connect", () => {
console.log("print Connected!")
setInterval(execute, 1000);
})
function execute() {
client.publish("***topic***", ""+x);
x = 1 - x
}