使用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 }); });
- 从Azure Passport身份validation节点js注销
- 服务工作者在React应用程序中刷新后导致空白页面
- Azure网站上的Node.js 404错误
- 在Azure网站上从文件系统安装Node.js模块
- Azure Node SDK的文档(不是命令行)?
- 使用node.js在Azure文件存储中上传文件
- Node.js服务器应用程序使用cors,express和google api在azure部署后不工作
- 运行在Azure上的express.js中的multipart / form-data错误
- azure-functions-cli:func init spits错误“No such file or directory”