我试图使用Firebase的云函数使Dialogflow意图导致发布MQTT消息。我已经设法获得了我需要的数据,但我仍然无法完成的是:
由于第二个需要前者,这还不是我关心的。
'use strict';
const functions = require('firebase-functions');
const { WebhookClient, Card, Suggestion } = require('dialogflow-fulfillment');
var mqtt = require('mqtt');
process.env.DEBUG = 'dialogflow:debug';
const HOST = 'broker.mqttdashboard.com';
const PORT = 1883;
const TOPIC = 'topic/voice_recog';
exports.dialogflowFirebaseFulfillment = functions.region('europe-west1').https.onRequest((request, response) => {
const agent = new WebhookClient({ request, response });
try {
function publishParameter(agent) {
let message = agent.parameters.param_test;
return publishToMqtt(message).then((output) => {
agent.add(output);
}).catch(error => {
agent.add('error from publishToMqtt');
});
}
let intentMap = new Map();
intentMap.set('Repeat parameter', publishParameter);
agent.handleRequest(intentMap);
}
catch (err) {
console.error(err);
agent.add(err.message);
agent.send_();
}
});
function publishToMqtt(message) {
console.log("------------------------------");
console.log("Topic: \""+TOPIC+"\"");
console.log("Message: \""+message+"\"");
console.log("------------------------------");
return new Promise((resolve, reject) => {
var options = {
port: PORT,
host: HOST,
clientId: 'mqttjs_' + Math.random().toString(16).substr(2, 8),
keepalive: 60,
reconnectPeriod: 1000,
protocolId: 'MQIsdp',
protocolVersion: 3,
clean: true,
encoding: 'utf8'
};
var client = mqtt.connect("mqtt://"+HOST, {port: PORT});
// is not executed
client.on('connect', function () {
console.log('client connected');
});
// is not executed
client.publish(TOPIC, message, {}, function (err) {
console.log("Tried publishing \""+message+"\" to \""+TOPIC+"\".");
if (err) {
console.log("But the future refused to change:" + err);
reject();
}
else {
resolve(message);
client.end();
clearTimeout(noResp);
}
});
let noResp = setTimeout(() => {
console.log("No connection"); // always gives this result
reject();
client.end();
}, 5000);
});
}
{
"name": "assistant-to-mqtt",
"description": "publishes intent parameter to MQTT broker",
"engines": {
"node": "8"
},
"version": "0.0.1",
"private": true,
"scripts": {
"start": "firebase serve --only functions:publish_mqtt",
"deploy": "firebase deploy --only functions:publish_mqtt"
},
"dependencies": {
"actions-on-google": "^2.1.3",
"dialogflow-fulfillment": "^0.4.1",
"firebase-admin": "^5.12.1",
"firebase-functions": "^2.2.1",
"mqtt": "^2.13.0"
}
}
您实际上使用的是MQTT代理,它被Firebase视为外部访问URL。尝试按此处所述启用计费。
我是PHP领域的新手,在连接到MQTT时遇到了一些问题。 错误为:stream_socket_client():无法连接到TCP://...*:8083(连接超时) 在下面的代码中面临问题:
我想使用ActiveMQ创建一个代理来连接到另一个蚊子代理。然后,我可以使用ActiveMQ接收来自蚊子代理的消息。 我现在要做的是: 将ActiveMQ与JBoss EAP 6.3集成。 在ActiveMQ中创建MQTT代理:http://activemq.apache.org/mqtt.html 但是,在我添加代理配置中的网络连接器之后.xml: 服务器启动后显示异常: "vm://local
我正试图通过MQTT发布服务器发布事件。在提供程序URL中提到了tls://URL:port 当我试图执行时,它会给出以下错误:。我使用的是apache jmeter 5.0和MQTT jar版本:mqtt-jmeter-0.0.1-snapshot java.lang.IllegalArgumentException:tls://...:1887 at org.eclipse.paho.clie
我还要求通过启用TLS/SSL(根据Microsoft Azure文档:https://docs.Microsoft.com/en-us/Azure/iot-hub/iot-hub-mqtt-support#tlsssl-configuration)(如https://github.com/mqttjs/mqtt.js#client上的mqtt.js文档所述)。 如何使用第三方MQTT库和SAS令
我如何用C#将消息发布到外部托管的MQTT代理(在我的例子中是VirtualBox--在openwrt之上)?