mirror of
https://github.com/openfaas/faas.git
synced 2025-06-18 12:06:37 +00:00
Add changecolorintent
This commit is contained in:
40
sample-functions/ChangeColorIntent/sendColor.js
Normal file
40
sample-functions/ChangeColorIntent/sendColor.js
Normal file
@ -0,0 +1,40 @@
|
||||
"use strict"
|
||||
|
||||
var mqtt = require('mqtt');
|
||||
|
||||
class Send {
|
||||
constructor(topic) {
|
||||
this.topic = topic;
|
||||
}
|
||||
|
||||
sendIntensity(req, done) {
|
||||
var ops = { port: 1883, host: "iot.eclipse.org" };
|
||||
|
||||
var client = mqtt.connect(ops);
|
||||
|
||||
client.on('connect', () => {
|
||||
console.log("Connected");
|
||||
let payload = req;
|
||||
let cb = () => {
|
||||
done();
|
||||
};
|
||||
client.publish(this.topic, JSON.stringify(payload), {qos: 1}, cb);
|
||||
});
|
||||
}
|
||||
|
||||
sendColor(req, done) {
|
||||
var ops = { port: 1883, host: "iot.eclipse.org" };
|
||||
|
||||
var client = mqtt.connect(ops);
|
||||
let cb = () => {
|
||||
done();
|
||||
};
|
||||
client.on('connect', () => {
|
||||
console.log("Connected");
|
||||
let payload = req;
|
||||
client.publish(this.topic, JSON.stringify(payload), {qos: 1}, cb);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Send;
|
Reference in New Issue
Block a user