简介
node-red-contrib-storfly-iot-external 是一个基于 Node-RED 的 npm 包,用于操作和管理云端存储和外部设备的数据。主要适用于 IoT 技术领域。
安装
在命令行中,输入 npm i node-red-contrib-storfly-iot-external
即可安装最新版的 node-red-contrib-storfly-iot-external 包。
使用
在 Node-RED 的流程中,你可以使用使用此包中提供的节点来操作和管理云端存储和外部设备。
节点介绍
此包中包含以下几个节点:
1. File Upload
用于将本地文件上传至云端存储,或者上传至外部设备。
2. File Download
用于从云端存储或外部设备下载文件到本地。
3. File List
用于获取特定路径下的所有文件列表。
4. File Delete
用于删除云端存储或外部设备上的特定文件。
示例代码
在此给出一个使用 node-red-contrib-storfly-iot-external 包的 Node-RED 示例:
[{"id":"f2100fb0.a5672","type":"file-upload","z":"cf583dcd.1537588","name":"","uploadPath":"","filepath":"","x":710,"y":100,"wires":[["112ee858.81e11b"]]},{"id":"dc8a5b5d.2d827","type":"inject","z":"cf583dcd.1537588","name":"","props":[{"p":"payload"},{"p":"filename","v":"hello.txt"},{"p":"path","v":"./"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":330,"y":100,"wires":[["14b2f2c8.a7b1d4"]]},{"id":"14b2f2c8.a7b1d4","type":"function","z":"cf583dcd.1537588","name":"Read File","func":"msg.payload = fs.readFileSync(msg.path+msg.filename, 'utf8');\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":510,"y":100,"wires":[["f2100fb0.a5672"]]},{"id":"112ee858.81e11b","type":"debug","z":"cf583dcd.1537588","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":910,"y":100,"wires":[]}]
在此示例中,我们使用了 File Upload 节点将名为 hello.txt
的本地文件上传至云端存储或外部设备。
我们首先通过 Inject 节点将要上传的文件读入并发送给 File Upload 节点进行上传,上传成功后,文件会被存储到你设定的相对路径中。
总结
本文介绍了 node-red-contrib-storfly-iot-external 包的使用教程,包括了安装、基本介绍、节点介绍和示例代码。此包的使用将为你的 IoT 技术提供方便和支持,不仅具有指导意义,而且具有深度和学习意义。
来源:JavaScript中文网 ,转载请注明来源 https://www.javascriptcn.com/post/60056d5681e8991b448e6fbd