文章引用自 github Intel(r) IoT Services Orchestration Layer
最近在做Intel的一个物联网比赛,需要用到Intel(r) IoT Services Orchestration Layer,所以今天将github上的这篇readme翻译一下,方便日后其他有需要的人快速阅读,英文水平有限,翻译有误,还望见谅和指出。
Introduction
This is a solution that provides visual graphical programming for developing IoT applications.
Intel IoT Services Orchestration Layer 是一个解决方案,它为开发物联网应用提供了可视化的图形编制程序。
The solution contains a HTML5 IDE running inside browser / WebView for developers to create the IoT application, including its internal logic (e.g. workflows) and its HTML5 based end user interface, through drag-and-drop in an easy and intuitive way.
该解决方案含有运行在浏览器/web视图的HTML5集成开发环境,无论是应用内在的逻辑(例如工作流程),还是基于HTML5的最终用户接口,开发者都可以通过拖拽这种简单而又凭借直觉的方式来完成。
The solution also contains a distributed middleware running on top of Node.js to host and execute the IoT applications created by the IDE.
该解决方案也含有一个运行在Node.js之上的分布式中间件,负责主持和执行由该集成开发环境开发的物联网应用。
The middleware contains an Orchestration Center which runs the workflow engine to execute the logic, and web servers to host the HTML5 IDE for developers and HTML5 UI for end users.
该中间件含有运行着工作流程引擎来执行内部逻辑的编排中心、为开发者支持HTML5 集成开发环境的web 服务器以及为最终用户准备的HTML5 UI。
The middleware also contains one or multiple Service Hubs which actually manages the devices and cloud services in various procotols. The Service Hub roll up these information about services to Orchestration Center to let the developers create applications based on these services. The Service Hub also receives commands from Orchestration Center to actually invoke the services managed by it, according to the logic defined by workflows.
中间层也含有1个或多个服务中心,上面管理着使用多种协议的设备和云服务。服务中心将这些服务信息汇总到编排中心,开发者基于这些服务开发应用程序。服务中心也接收来自编排中心的命令,通过工作流程定义的逻辑,实际调用它所管理的服务。
To understand this by a demo, please go through the instructions below and we do have a demo (with simulated devices and services) project as well.
为了通过一个demo来理解这些,请亲自输入下面的这些命令,我们也将确实完成一个demo(带有一些仿真设备和服务)。
Important Notes
Contribute to the Development Project
The master(default) branch of this project is called as a Release Project.
这个项目的master分支(默认)称为发布项目。
This branch simply host the releases of this solution which is immediately ready-to-go after you have it downloaded.
这个分支仅寄存这这个解决方案的发布版,这意味着在你下载之后可以立即用来开发。
However, if you decide to help contribute to this project, you need to switch to its dev branch. If you cloned from github, you may switch by simply git checkout dev
. We call this dev branch as Development Project.
然而,如果你决定为这个项目出一份力,你需要转换到dev分支。如果你从github上克隆了该项目,你也可以简单地通过git checkout dev
命令切换到dev分支。我们称dev分支为开发项目。
The reason is that the solution is quite complicated. Thus for each release, it needs some building process (e.g. package the modules, build the UI files etc.) from the Development Project. This brings trouble for end users who simply want to use this project instead of contributing to that.
存在这两个分支的原因是这个解决方案相当复杂。对于每个发布版,它需要一些来自开发项目的构建过程(例如打包模块,构建UI文件等)。这给仅仅想使用这个项目而不是为该项目出一份力的最终用户带来麻烦。
So to make the installation much easier, we will build the Development Project (the dev branch) and put the ready-to-run solution here in master branch. Thus end users no need to build by themselves if she/he directly start from this Release Project.
所以为了使得安装更加简单,我们将构建开发项目(dev分支),并且将准备好运行的解决方案放在master分支。因此如果最终用户已经直接从发布项目开始的话,他们不需要再手动的构建这个项目。
However, if you hope to contribute to this project (bug fix, new enhancements etc.), you should work on the Development Project instead.
然而,如果你希望为该项目出一份力(例如修复bug,增加新的功能等等),你应该在开发项目上工作。
Proxies
As this is a solution based on Node.js, so the installation may touch npm (Node.js Package Manager) which would download and install dependent packages from internet.
由于这是一个基于Node.js的解决方案,所以安装该解决方案也许要接触npm(Node.js包管理器),npm将下载和安装来自互联网的独立包。
So if you are behind a firewall / proxy, you may need to configure the proxy settings of your npm so you could download and install. You may do this by running npm config edit
in your shell (command line prompt) to open npm's configuration file, and configure related proxy items inside it. For example, add these lines in it。
所以如果你部署有防火墙或者代理,你也许需要配置你的npm代理设置以便你能够下载和安装。你也可以在shell(命令行提示)中通过运行npm config edit
来打开npm的配置文件,配置里面和代理项有关的内容。例如,添加如下几行。
proxy=http://my_proxy:proxy_port
https-proxy=http://my_proxy:proxy_port
Please replace the my_proxy
and proxy_port
in above example accordingly.
需要将上述例子中的my_proxy
和proxy_port
替换为相应的内容。
Installation
First, Node.js with version >= 0.12 is required. And you might need to configure npm proxy settings as mentioned above.
首先,你需要0.12版本以上的Node.js,并且你也可能需要按照上面提到的修改npm代理设置。
Secondly, if you are using Windows, you need a shell environment to run scripts. You may install cygwin, or gitbash (which is a MingGW)
其次,如果你正使用Windows环境,你需要安装一个shell环境去运行一些脚本。你可以安装cygwin或者gitbash(那是一个MinGW(Minimalist GNU for Windows))。
Install from github
With that, under the shell, you may git clone
this project (or download the zip and uncompress it) and npm install under it for necessary additional packages. Below is an example of installing it。
配置好上述所需环境,在shell环境下,你可以使用git clone
命令克隆这个工程(或者下载zip压缩文件解压),在此工程目录下安装npm来安装一些额外的必要包。下面是一个安装实例。
# Instead of git clone, you may download the zip of project through
# github webpage and then uncompress it
# 代替git clone命令,你可以在github网页下载压缩包然后解压它。
git clone https://github.com/01org/intel-iot-services-orchestration-layer iot-sol
cd iot-sol
# this would install all dependent npm packages for this
npm install
Install from npm
As this solution is also published in npm with the name iot-sol. So instead of installing from github, you may also install it simply with the command below.
由于这个解决方案也以iot-sol的名字在npm上发行,所以除了从github安装以外,也可以简单的用下面的命令安装。
npm install iot-sol
# npm installs it to local node_modules so need cd to it to play with it
# npm 将它安装在node_modules文件夹中,所以需要进入该文件夹去使用它
cd node_modules/iot-sol
Documentation
You may choose ANY of the following options to read the documentation.
你也可以选择下列任何一种方式来阅读文档。
- Read our online document
阅读在线文档 - Offline in your shell, run
./start_doc.sh
离线状态下,在shell中,运行./start_doc.sh
命令 - When you are in the HTML5 IDE of this solution, click the link Help on the top right
当你使用该解决方案的HTML5集成开发环境时,点击右上角的Help链接。
Demos
To help understand the framework, a demo project is created. There are couple ways to run the demo project.
为了帮助理解该框架,这里创建了一个demo工程。我们提供了两种方法运行该工程。
Run Demo in Seperated Shells
One way is to run the Broker, Center and Hub in seperated shells. (Please read the documentation for the concepts of Broker, Center and Hub).
一种方法是在分离的shell中分别运行Broker,Center和Hub(请阅读有关这三者概念的文档)。
Firstly, open a shell and kill all existing running instances of Node.js - this avoids that there is already a demo running at background.
首先,打开一个shell并且关闭所有已经存在的运行着的Node.js实例--这将避免后台已经有一个demo在运行。
# Kill all existing Node.js processes
# This only needs to do once before start Broker
# 在开启Broker之前,关闭所有存在的Node.js进程,这仅需要做一次
killall node 2>/dev/null
Then, still in this shell, start a Broker based on HTTP in it.
然后,还是在这个shell中,开启基于HTTP的Broker进程。
# Start a sample HTTP Broker
./run_demo broker
Then open another (i.e. the 2nd) shell and start the center
然后开启另一个shell(例如第二个)并且开启center进程
# Start a sample Center
./run_demo center
Then open another (i.e. the 3rd) shell and start a Hub (named hub_a)
然后开启另一个shell(例如第三个)并且开启一个Hub进程(命名为hub_a)
# Start a sample Hub
./run_demo hub
(Optional) You may open the 4th shell to start another Hub (named hub_b), although this isn't always necessary
这步是可选的,你可以开启第四个shell,然后开启另一个Hub进程(命名为hub_b),这并不总是必要的。
# Start another sample Hub
./run_demo hub_b
After that, you may navigate to http://localhost:8080
in browser for HTML5 UI for application developers, andhttp://localhost:3000
for HTML5 UI for end users. You may replace localhost to real ip/host if you need to remotely connect to it.
在这之后,你可以在浏览器中导航到为应用开发者准备的HTML5 UI,网址为http://localhost:8080
,也可以导航到为最终用户准备的HTML5 UI,网址为http://localhost:3000
。如果你需要远程连接的话,可以将localhost修改为真实的ip/host。
Run Demo with One Command
Above explains the details of running the demo, we have created a helper script to include all of the above, so instead of openning 4 shells and start related components, you may run the demo via running this script:
上述解释了运行demo程序的细节。现在我们已经创建了一个包含上述步骤的helper脚本,不用打开4个shell并在开启相应的组件,你可以通过运行这个脚本运行该demo。
# This contains all steps above
./start_mock_demo.sh
After that, it is the same as above, i.e. open the browser to navigate the UIs.
运行该命令之后,其余步骤和上述相同,例如打开浏览器导航到上述的UI界面。
If running in this way, there would be logs saved as xxx.log
. xxx
corresponds to broker, center, mock_hub, mock_hub_b etc.
如果按照这个方式运行,将会产生xxx.log
命名的log文件。这里的xxx
对应着broker,center,mock_hub,mock_hub_b等等。
Advanced Topics
To understand more about the iot-sol, it's highly recommended to read the documentation (e.g. by ./start_doc.sh) in get_started/advanced category.
为了对iot-sol理解更深,强烈建议阅读get_started/advanced目录下的文档(例如通过./start_doc.sh命令)。
In high level, iot-sol has these components (Read documentation for more explanations):
在上层中,iot-sol有这些组件(详情见文档):
Center
: It's a Node.js process that manages all of the workflows and also offers the HTML5 UI for developers and end users.
这是一个Node.js进程,管理所有的工作流,并且向开发者和最终用户提供HTML5 交互界面。Hub
: It's also a Node.js process. It hosts many "Things" and the services (the nodes used to compose a workflow) offered by these "Things". For example, a Hub running on Edison may have a Thing so called "LED" which has three services "turn_on", "turn_off", "get_status". And another Hub (running on gateway of Cloud) may have a Thing so called "Gmail" which has services such as "fetch_mail", "send_mail", etc.
这也是一个Node.js进程。他聚集着许多物以及由这些物提供的服务(节点被用来组成一个工作流)。例如,运行在Edison上的Hub也许包含有一个叫做“LED”的物,它提供三种服务,分别是开,关和获取状态。运行在云网关的Hub也许有一个叫做“Gmail”的物,它提供获取邮件,发送邮件等服务。Broker
: Center and Hubs are communicated with the help of Broker. The Broker could be a MQTT, or the built-in HTTP broker written in Node.js (need to start that manually). The Center and Hub don't talk with each directly. Instead, they send messages to Broker, and Broker would dispatch them to the right target. This removes a lot of dependencies related to communication channels and make deployment much more flexible. Center and Hub has corresponding configuration items to define which broker they are using.
Center和众多Hub借助Broker的帮助得以交流。Broker可能是MQTT,或者是用Node.js写的内建的HTTP broker(需要手动开启)。Center和Hub不直接沟通,他们向Broker送消息,Broker将消息分发给正确的目标。这去除了与通信通路有关的大量依赖,而且使部署更加灵活。Center和Hub有对应的配置项,在那里定义了他们他们正在使用哪个Broker。
A solution may have multiple Hubs in entire system. These Hubs would roll up the information about the services they hosted to the Center. Thus in Center, developers could compose a workflow that employs these services. The workflow is stored at Center. When center executes the workflow, based on the logic defined by developer in the workflow, the Center knows which service need to be invoked, and then it sends command to the corresponding Hub which hosts the required service, and the Hub would execute this service. The service may further send out some message and would be disptached to Center to drive the next step of the Workflow.
一个解决方案也许在整个系统中包含有多个Hub。这些Hub将他们聚集的服务信息汇总到Center。因此在Center,开发者能够编写工作流使用这些服务。工作流存储在Center。当Center执行工作流的时候,基于开发者在其中定义的逻辑,Center知晓哪个服务需要被调用,然后传递指令给对应的收集有需要服务的Hub,之后Hub将执行服务。更进一步,服务会发送一些消息,通过broker分发给Center,进而驱动工作流的下一个步。
The communcation between Center and Hub is going through Broker, therefore, Center and Hub could be deployed very flexibly, either sperately on different physical machines / processes (e.g. one in gateway while the other in cloud), or locally on the same machine (e.g. all in the same Edison board).
由于Center和Hub之间的交流是通过Broker实现的,Center和Hub能够被很灵活的部署,既可以分别部署在不同的我物理机或进程(例如,一个部署在网关而另一个部署在云端),或者部署在相同的机器上(例如都部署在相同的Edison板上)。
In above demos, we use run_demo to start related center or hub. And if you look into the actual code of the run_demo script, you would find the normal way to start center / hub is:
在上述demo中,我们使用run_demo
去开启相关的center或者hub。如果你查看run_demo
脚本中的实际代码,你将发现开启center或者hub的标准方式是这样的:
- Normal way to start a center:
./center [path-to-a-configuration]
- Normal way to start a center:
./hub [path-to-a-configuration]
They all need a configuration file provided (default to ./config.json
if not supplied). Details about the configuration file is also documented in get_started/advanced category of the documentation.
他们都需要提供一个配置文件(默认是./config.json
,如果没有被替换的话)。配置文件的细节也被记录在documentation中get_started/advanced目录下。