我正试图避免使用Azure SDK。
我正在尝试使用async-mqtt npm程序包连接到Azure IoT中心。
我可以仅使用async-mqtt成功地手动将其发布为默认的devices/${deviceId}/messages/events/
主题,并且可以使用Azure Quickexample(https://github.com/Azure-Samples/azure-iot-samples-node/archive/master.zip)轻松读取已发布的数据。
当我尝试仅使用async-mqtt读取数据时,我无法获取任何数据(以下是我正在使用的代码)。
await client.publish(`devices/${deviceId}/messages/events/`,"testing");
await client.subscribe(`devices/${deviceId}/messages/devicebound/`);
client.on('message',function (topic,message){
console.log("Received");
console.log(message.toString());
});
await client.end();
我做错了。
编辑: 这是客户端配置
var client = MQTT.connect(`mqtts://${iotHubName}.azure-devices.net:8883`,{
keepalive: 10,clientId: MyNodeDevice,protocolId: 'MQTT',clean: true,protocolVersion: 4,reconnectPeriod: 1000,connectTimeout: 30 * 1000,username: username,password:"SAS TOKEN",rejectUnauthorized: false,});