mirror of
https://github.com/openfaas/faas.git
synced 2025-06-08 16:26:47 +00:00
40 lines
751 B
JavaScript
40 lines
751 B
JavaScript
"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', () => {
|
|
|
|
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', () => {
|
|
|
|
let payload = req;
|
|
client.publish(this.topic, JSON.stringify(payload), {qos: 1}, cb);
|
|
});
|
|
}
|
|
}
|
|
|
|
module.exports = Send; |