This folder contains scripts and docker compose files to quickly set up the EMQ X Edge Stack.
Docker
Refer to install docker document for more detailed information.
Docker-compose
Below is an example for how to install docker-compose in centos-7, you can find docker-compose install instruction for other Linux system through Google.
https://linuxize.com/post/how-to-install-and-use-docker-compose-on-centos-7/
Below is an example for how to install docker-compose in ubuntu18 arm.
sudo apt-get install python3 python3-dev python3-pip libffi-dev libevent-dev
pip3 install docker-compose
For convenience, the run.sh
will help you get up and running. It will add,
- The local Kuiper, Neuron and Edge nodes;
- Create a stream named "neuron" in Kuiper which connects to the local neuron's telemetry mqtt topic.
- Create a default database in TDengine and add it to Grafana data source.
git clone git@github.com:emqx/edge-stack.git
cd $edge-stack
developer-scripts/run.sh
Open Neuron dashboard by click Neuron
in the left menu, and then click local_neuron
node. Then do the following setup.
-
Install the Modbus simulator: PeakHMISlaveSimulator. After installation, open Modbus TCP slave.
-
In the neuron dashboard, open Configuration -> Object Setup. Click Edit Driver, and setup the modbus tcp driver and mqtt.
- Driver type: Modbus TCP.
- Host name: Fill in the host where the Modbus simulator is running on.
- Port: 502 by default.
- MQTT Host name: manager-edge, which is the local emqx edge node.
- MQTT Port: 1883.
If the driver setup is correct, the Modbus simulator should show 1 client connected and keep receiving. Click "Submit" button, the Modbus TCP become the current driver.
-
Click "Import" button, select neuron_batch_modbus_5.xlsx. There should be a new line added in the object table. Then click "Send" button at the top-right corner, which will send the configuration to Neuron and restart it.
-
From Tag00001 to Tag00004 is the read-only register.
-
Tag00005 is the read-writer register.
-
-
The setup is done now. Then verify that neuron has connect to the EMQX edge.
- Click edge in the left menu. Then click local_edge in the node list to enter the EMQX edge dashboard.
- In the edge dashboard, click clients in the left menu. There should be one client.
Open Kuiper dashboard by click Kuiper
in the left menu, and then click local_kuiper
node. Then do the following setup.
-
Make sure the
neuron
stream is created. Go to the "Stream" tab, make sure a stream namedneuron
is in the stream list. -
Switch to "Plugins" tab, click "Create plugin", and setup as below. This will create the tdengine plugin so that the rule result can be ported to tdengine.
-
Create a rule.
- A rule will be created for subscribing data published by Neuron, and send the analysis result to TDengine. Switch to "Rules" tab, click "Create rule". Switch to "Text mode" in the top-right. Fill in Rule ID: ruleNeuron or any rule name you want. Enter the below json in the "text" field. Click "Submit", make sure the rule is up and running. Click the rule status, there should be data in and out in the metrics.
{ "sql": "SELECT tele[0]->Tag00001 AS temperature, tele[0]->Tag00002 AS humidity FROM neuron", "actions": [ { "tdengine": { "ip": "taos", "port": 0, "user": "root", "password": "taosdata", "database": "db", "table": "t", "fields": ["temperature","humidity"], "provideTs": false, "tsFieldName": "ts" } } ] }
- Rule 2: Create a rule named
rule2
to control the device when temperature is 30 degree, and write value3
to the register where Tag00005 bind. Click "Submit", make sure the rule is up and running. Click the rule status, there should be data in and out in the metrics.
{ "sql": "SELECT tele[0]->Tag00001 AS temperature, tele[0]->Tag00002 AS humidity FROM neuron WHERE temperature = 30", "actions": [ { "rest": { "url": "http://manager-neuron:7000/api/v1/funcno51", "method": "post", "dataTemplate": "{\"func\":51,\"srcn\":\"Device\",\"attn\":\"Tag00005\",\"valn\":3,\"wtrm\":\"neruon\"}", "sendSingle": true } } ] }
-
Go into the docker container of TDengine.
docker exec -it manager-taos /bin/sh
-
The rule data is in database db, table t. Query the data with SQL like
use db;select * from t;
.
A default dashboard was automatically created by the script which connects to the TDengin db.t table. Open http://yourhost:3000/dashboards in the browser, click taos dashboard. It will show the temperature change over time visually.
You can try to set value of Tag00001 to 30 in PeakHMISlaveSimulator, and then observe the value of Tag00005. If everything goes well, the value of Tag00005 register will be set to 3.
If you having any problems with your environment, then you can run following command to reset your environment.
cd developer-scripts
docker-compose -p emqx_edge_stack down
Please notice that command docker rm docker ps -qa
will remove all of docker instances, if you have docker instances other than edge-stacks and do not want to have all of them removed, please remove edge stack instances one by one.
The default running compose file is docker-compose.yml
. To run another docker compose file, use:
./run.sh docker-compose-test.yml
To stop the current stack, run the command in the current folder.
docker-compose stop
Please refer to docker compose doc for more cli commands.
If you only need to start up all dependant docker container without initializing any data, you can just run the docker compose file directly.
Run docker compose in this folder.
docker-compose up -d
Edge manager will run at http://yourhost:9082
. Two nodes are ready:
- Kuiper:
http://manager-kuiper:9081
. - Edge:
http://manager-edge:8081
. - Neuron:
http://manager-neuron:7000
Notice that, these three nodes are running internally. If you need to access them externally, please modify the ports
in docker-compose.yml to remove 127.0.0.1
. For example, kuiper ports "127.0.0.1:9081:9081"
should be changed to "9081:9081"
.
You can add nodes in the edge manager nodes page.
For testing docker images, modify the docker-compose-test.yml
to point the image to local images and run it.
docker-compose -f docker-compose-test.yml up -d
Modify the docker-compose-test.yml
to configure the ports, environment variables etc.