面向 JavaScript 开发人员的 5 大物联网库

{"type":"doc","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"最近元宇宙的概念火遍互联网,自 Facebook 改名 Meta 以来,国内外越来越多的企业纷纷加入到布局元宇宙的行列。元宇宙之所以强势进入人们视野,与其底层技术的进步有着莫大的关系,包括AR/VR、云计算、物联网、5G、人工智能、数字孪生等等。其中,5G作为重要的连接基础,是元宇宙场景得以实现的关键。元宇宙将汇集游戏引擎、AR可穿戴设备、VR、现实世界数据集和不断发展的物联网。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"物联网(英语:InternetofThings,简称 IoT)是一种计算设备、机器、数码机器之间相互联系的系统,它拥有一种统一的统一识别代码(UID),并且能够在网络上传送数据,不需要人与人、或人与设备之间的交互。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"作为一个前端工程师(JavaScript工程师),似乎觉得这一切有点模式,其实不然,现代 JavaScript 的可以使用的场景越来越多,包括物联网,在本文中,将介绍可以在 JavaScript 代码中用于连接设备的 5 个脚本库。","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"1. Cylon.js","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"官方网站:","attrs":{}},{"type":"link","attrs":{"href":"https://cylonjs.com/","title":"","type":null},"content":[{"type":"text","text":"https://cylonjs.com/","attrs":{}}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"link","attrs":{"href":"https://cylonjs.com/","title":"","type":null},"content":[{"type":"text","text":"Cylon.js","attrs":{}}]},{"type":"text","text":" 是用于机器人、物理计算和物联网 (IoT) 的流行 JavaScript 框架之一。不仅仅是一个“物联网”库,它还是一个完整的机器人框架,支持超过 43 个不同的平台,这是与机器连接的 43 种不同的地方或方式,目前支持的机器人和物理计算系统及软件平台有Arduino、Beaglebone Black、BLE、Disispark、Intel Galileo and Edison、Intel IoT Analytics、OpenCV、Octobl、Raspberry Pi、Salesforce等。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"可以使用 ","attrs":{}},{"type":"link","attrs":{"href":"https://cylonjs.com/","title":"","type":null},"content":[{"type":"text","text":"Cylon.js","attrs":{}}]},{"type":"text","text":" 连接到关键字并侦听它或 Arduino 板发送的事件,或者提供一个 HTTP API 接口并通过那里获取数据(它们也支持 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"socket.io","attrs":{}}],"attrs":{}},{"type":"text","text":" 和 ","attrs":{}},{"type":"codeinline","content":[{"type":"text","text":"MQTT","attrs":{}}],"attrs":{}},{"type":"text","text":")。想通过 JavaScript 控制无人机吗?这并非不可以,首先需要安装:","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"codeblock","attrs":{"lang":"text"},"content":[{"type":"text","text":"npm install cylon cylon-firmata cylon-gpio cylon-i2c\n","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"然后运行一个这样的小脚本,","attrs":{}},{"type":"link","attrs":{"href":"https://cylonjs.com/documentation/platforms/ardrone/","title":"","type":null},"content":[{"type":"text","text":"参考文章","attrs":{}}]},{"type":"text","text":":","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"codeblock","attrs":{"lang":"text"},"content":[{"type":"text","text":"npm install cylon cylon-ardrone\n","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"然后运行脚本:","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"codeblock","attrs":{"lang":"text"},"content":[{"type":"text","text":"const Cylon = require(\"cylon\");\n\nCylon.robot({\n connections: {\n ardrone: { adaptor: \"ardrone\", port: \"192.168.1.1\" },\n },\n\n devices: {\n drone: { driver: \"ardrone\" },\n },\n\n work: function (my) {\n my.drone.takeoff();\n after((10).seconds(), function () {\n my.drone.land();\n });\n after((15).seconds(), function () {\n my.drone.stop();\n });\n },\n}).start();\n","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"如果有设备可以试试。","attrs":{}},{"type":"link","attrs":{"href":"https://cylonjs.com/","title":"","type":null},"content":[{"type":"text","text":"Cylon.js","attrs":{}}]},{"type":"text","text":" 的工作方式是允许其他人通过插件的方式提供连接器,这意味着这个库提供的功能没有限制。最重要的是,文档本身非常详细,写得很好,完整的代码示例。","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"2. IoT.js","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"官方网站:","attrs":{}},{"type":"link","attrs":{"href":"https://iotjs.net/","title":"","type":null},"content":[{"type":"text","text":"https://iotjs.net/","attrs":{}}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"link","attrs":{"href":"https://iotjs.net/","title":"","type":null},"content":[{"type":"text","text":"IoT.js","attrs":{}}]},{"type":"text","text":" 是一个用 JavaScript 编写的物联网 (IoT) 框架。它旨在基于网络技术在物联网世界中提供一个可互操作的服务平台。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"如果希望在一个连接的设备中执行一些物联网(而不是在一个强大的、充满资源的服务器中的接收端),那么可能需要针对该环境进行优化。这个 IoT 框架运行在 ","attrs":{}},{"type":"link","attrs":{"href":"https://github.com/jerryscript-project/jerryscript","title":"","type":null},"content":[{"type":"text","text":"JerryScript","attrs":{}}]},{"type":"text","text":" 引擎之上,","attrs":{}},{"type":"link","attrs":{"href":"https://github.com/jerryscript-project/jerryscript","title":"","type":null},"content":[{"type":"text","text":"JerryScript","attrs":{}}]},{"type":"text","text":" 引擎是一个针对小型设备优化的 JavaScript 运行时。这意味着,虽然无法使用最先进的 JS 的全部功能,但确实可以使用:","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"完全支持 ECMAScript 5.1 语法。","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"低内存消耗优化","attrs":{}}]}]},{"type":"listitem","attrs":{"listStyle":null},"content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"能够将 JS 代码预编译为字节码","attrs":{}}]}]}],"attrs":{}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"但是,兼容平台的数量没有 ","attrs":{}},{"type":"link","attrs":{"href":"https://cylonjs.com/","title":"","type":null},"content":[{"type":"text","text":"Cylon.js","attrs":{}}]},{"type":"text","text":" 多,而 ","attrs":{}},{"type":"link","attrs":{"href":"https://iotjs.net/","title":"","type":null},"content":[{"type":"text","text":"IoT.js","attrs":{}}]},{"type":"text","text":" 只兼容:","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"关于他们的文档,这应该是衡量一个库有多好的标准之一。他们有一些基本的例子和入门指南。但可能就是这样了。考虑到 ","attrs":{}},{"type":"link","attrs":{"href":"https://iotjs.net/","title":"","type":null},"content":[{"type":"text","text":"IoT.js","attrs":{}}]},{"type":"text","text":" 是一个底层的硬件接口,现在看起来它希望开发人员已经有使用其他产品的经验,而不是针对JS开发人员寻求进入物联网。","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"3. Johnny-Five","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"官方网站:","attrs":{}},{"type":"link","attrs":{"href":"http://johnny-five.io/","title":"","type":null},"content":[{"type":"text","text":"http://johnny-five.io/","attrs":{}}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"link","attrs":{"href":"http://johnny-five.io/","title":"","type":null},"content":[{"type":"text","text":"Johnny Five","attrs":{}}]},{"type":"text","text":" 是流行的 JavaScript 机器人和物联网平台之一。由 Bocoup 于 2012 年开发的 ","attrs":{}},{"type":"link","attrs":{"href":"http://johnny-five.io/","title":"","type":null},"content":[{"type":"text","text":"Johnny Five","attrs":{}}]},{"type":"text","text":" 一个开源的、基于 Firmata 协议的物联网和机器人编程框架,是 JavaScript 开发人员可用的最古老的机器人和物联网平台之一,从那时起,它的功能和兼容性都在不断增长。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"link","attrs":{"href":"http://johnny-five.io/","title":"","type":null},"content":[{"type":"text","text":"Johnny Five","attrs":{}}]},{"type":"text","text":" 支持 Arduino(所有型号)、Electric Imp、Beagle Bone、Intel Galileo & Edison、Raspberry Pi 等。该平台可轻松与流行的应用程序库(如 Express.js 和 Socket.io)以及物联网框架(如 Octoblu)结合使用。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"他们的文档非常详细,充满了关于硬件连接的示例和图表,这是一个很好的学习资源。","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"4. NodeRed","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"官方网站:","attrs":{}},{"type":"link","attrs":{"href":"https://nodered.org/","title":"","type":null},"content":[{"type":"text","text":"https://nodered.org/","attrs":{}}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"link","attrs":{"href":"https://nodered.org/","title":"","type":null},"content":[{"type":"text","text":"NodeRed","attrs":{}}]},{"type":"text","text":" 是建立在 Node.js 之上,是一个基于流的编程工具,最初由 IBM 的新兴技术服务团队开发,现在是 JS 基金会的一部分。该平台允许在部署之前从浏览器以图形方式设置数据流和工作流。在理想的情况下,不需要编写任何代码,也许设置一些平台凭据。 ","attrs":{}},{"type":"link","attrs":{"href":"https://nodered.org/","title":"","type":null},"content":[{"type":"text","text":"NodeRed","attrs":{}}]},{"type":"text","text":" 还充当和其他人共享他们创建的流程的中心化平台,这是防止每次都重新创建轮子的好方法,即使没有真正编写代码。","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"5. Zetta","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"官方网站:","attrs":{}},{"type":"link","attrs":{"href":"https://www.zettajs.org/","title":"","type":null},"content":[{"type":"text","text":"https://www.zettajs.org/","attrs":{}}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"link","attrs":{"href":"https://www.zettajs.org/","title":"","type":null},"content":[{"type":"text","text":"ZettaJS","attrs":{}}]},{"type":"text","text":" 是一个基于 Node.js 构建的开源平台,用于创建跨地理分布式计算机和云运行的物联网服务器。是另一种通过 JavaScript 与远程设备交互的方式。这里的主要区别在于 ","attrs":{}},{"type":"link","attrs":{"href":"https://www.zettajs.org/","title":"","type":null},"content":[{"type":"text","text":"ZettaJS","attrs":{}}]},{"type":"text","text":" 的目标是将每个设备都变成一个 API,这是将 IoT 泛化为一个通用概念的好方法。如今,设备及其接口的数量正在爆炸增长,但没有对其进行规范控制。 ","attrs":{}},{"type":"link","attrs":{"href":"https://www.zettajs.org/","title":"","type":null},"content":[{"type":"text","text":"ZettaJS","attrs":{}}]},{"type":"text","text":" 正试图在这方面进行改进,通过非常直观的编码方式,可以简单地为设备安装驱动程序,并在其中启用公共接口,并通过代码与它们交互。","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"总结","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"通过上面介绍,JavaScript 不仅限于浏览器,甚至不限于基于 API 的后端开发,还可以随心所欲地从设备中提取数据或从设备中提取数据,并使用几乎完全相同的语言来控制它。","attrs":{}}]}]}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章