使用nodejs将数据从Rfid rc522发送到azureiot集线器

//THIS IS THE CODE TO READ SERIAL NUMBER AND SEND DATA TO AZURE IOT HUB var rc522=require("rc522/build/Release/rc522"); var Async = require('async'); var Protocol = require('azure-iot-device-http').Http; var Client = require('azure-iot-device').Client; var ConnectionString = require('azure-iot-device').ConnectionString; var Message = require('azure-iot-device').Message; // Enter Device Connection String: AZURE--> IOTHub --> Devices--> select Device--> Connection String. var connectionString = ''; var deviceId = ConnectionString.parse(connectionString).DeviceId; var client = Client.fromConnectionString(connectionString, Protocol); var connectCallback=function(err){ if(err){ console.error('could not open connection' +err); } else{ console.log('client connected'); rc522(function(serial){ console.log(serial); }); var readings = { Id:serial}; var message = new Message(JSON.stringify(readings)); client.sendEvent(message, function (error) { if (error) { console.log(error.toString()); } else { console.log("Data sent on %s...", new Date()); } }); } } client.open(connectCallback); 

我无法发送rfid rc522序列号到Azure IOT集线器与Nodejs.I能够连接到客户端并在控制台上显示序列号,但无法看到任何收到的消息在azure色的IOT hub.I写function的应用程序,并发送iothub消息到tablestorage。

以下是我的代码和输出

iothub和表格存储输出 ,

rfid nodejs的控制台输出 ,

请稍后解释一下如何将序列号发送到azure IOT集线器。 我已经search了关于这个的资源,但在nodejs中找不到任何资源。

提前谢谢了

JSON.stringify(readings)到控制台时会发生什么? 我不是一个node.js专家,但我认为serial是未定义的,因为它在rc522(function(serial){ ..}

尝试

 rc522(function(serial){ console.log(serial); var readings = { Id:serial}; var message = new Message(JSON.stringify(readings)); client.sendEvent(message, function (error) { // code here }); });