面向 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":{}}]}]}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章