物联网集线器azure-ble设备和pwa应用程序



我有一个物联网设备,它通过蓝牙与我的PWA(Vue js(应用程序通信。

遥测是否可以发送到IOT azure集线器?

IOT集线器对我来说不是很清楚。我必须创建一个与PWA通信的服务器吗?(able<->PWA->后端->物联网集线器(

var Mqtt = require('azure-iot-device-mqtt').Mqtt;
var DeviceClient = require('azure-iot-device').Client
var Message = require('azure-iot-device').Message;
var client = DeviceClient.fromConnectionString(connectionString, Mqtt);
// Create a message and send it to the IoT hub every second
setInterval(function(){
// Simulate telemetry.
var temperature = 20 + (Math.random() * 15);
var message = new Message(JSON.stringify({
temperature: temperature,
humidity: 60 + (Math.random() * 20)
}));
// Add a custom application property to the message.
// An IoT hub can filter on these properties without access to the message body.
message.properties.add('temperatureAlert', (temperature > 30) ? 'true' : 'false');
console.log('Sending message: ' + message.getData());
// Send the message.
client.sendEvent(message, function (err) {
if (err) {
console.error('send error: ' + err.toString());
} else {
console.log('message sent');
}
});
}, 10000);

不需要创建后端服务器来与PWA通信。实际上,您可以使用Web套接字上的MQTT协议在vue js应用程序中建立通信。请参阅以下内容:

https://learn.microsoft.com/en-us/azure/iot-hub/iot-hub-mqtt-support

相关内容

最新更新