如何在 Azure 中使用节点 js get/find device/controller 的固件版本?
How to get/find the firmware version of device/controller using node js in azure?
如何在azure中使用node js get/finddevice/controller的固件版本?
The device is actually added in IoT Hub on Azure. I'm using node.js
framework to fetch the firmware version.
下面我添加了我的设备。设备按预期工作。我只是 want/fetch 固件版本。
Please click here to see the image
答案是
//*N++ update table
var macId = GetDeviceId();
updateFirmwareVersion(macId);
//*N+start update firmware version
function updateFirmwareVersion(deviceId){
registry.getTwin(deviceId, function(err, twin){
if (err) {
console.log('Could not query twins: ' + err.constructor.name + ': ' + err.message);
} else {
console.log((JSON.stringify(twin.properties.reported.AzureFwVersion)) + "\n");
var azureFwVersion = twin.properties.reported.AzureFwVersion;
var s = azureFwVersion.lastIndexOf(".");
var res = azureFwVersion.substring(s+1, azureFwVersion.length);
var firmwareV = Number(res).toString(16).toUpperCase() + '00';
//SQL starts
new sql.Request()
.query("UPDATE MY_Table SET firmware = '" + firmwareV + "'").then(function (recordset) {
}).catch(function (err) {
console.log('update table for firmware' + err);
});
}
});
}
//*N+end update firmware version
如何在azure中使用node js get/finddevice/controller的固件版本?
The device is actually added in IoT Hub on Azure. I'm using node.js framework to fetch the firmware version.
下面我添加了我的设备。设备按预期工作。我只是 want/fetch 固件版本。 Please click here to see the image
答案是
//*N++ update table
var macId = GetDeviceId();
updateFirmwareVersion(macId);
//*N+start update firmware version
function updateFirmwareVersion(deviceId){
registry.getTwin(deviceId, function(err, twin){
if (err) {
console.log('Could not query twins: ' + err.constructor.name + ': ' + err.message);
} else {
console.log((JSON.stringify(twin.properties.reported.AzureFwVersion)) + "\n");
var azureFwVersion = twin.properties.reported.AzureFwVersion;
var s = azureFwVersion.lastIndexOf(".");
var res = azureFwVersion.substring(s+1, azureFwVersion.length);
var firmwareV = Number(res).toString(16).toUpperCase() + '00';
//SQL starts
new sql.Request()
.query("UPDATE MY_Table SET firmware = '" + firmwareV + "'").then(function (recordset) {
}).catch(function (err) {
console.log('update table for firmware' + err);
});
}
});
}
//*N+end update firmware version