Skip to content

Commit 669f576

Browse files
author
Marco Stoffel
authored
Merge branch 'thin-edge:main' into main
2 parents 4ed52d8 + ce07a0f commit 669f576

23 files changed

+532
-0
lines changed

c8y-operations/Command/README.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# thin-edge.io Command plugin
2+
3+
To use command on a device that runs thin-edge.io, a plugin of the operation plugin concept is used. The tedge_agent is checking for command operation and is triggering the particular plugin. You can use the Shell tab in device management to use a command. Please be aware of the power of such an feature. Somebody with access could start various shell commands. Its more designed as an idea on how the plugin mechanism works.
4+
5+
## Requirements
6+
7+
- Working thin-edge.io installation
8+
9+
- Python3 and pip3 installation (will not work on python2)
10+
11+
12+
## Installation
13+
14+
1. Clone this repo on the thin-edge.io device
15+
2. run pip3 install -r requirements.txt from this Command directory
16+
3. Copy c8y_Command to the following directory "/etc/tedge/operations/c8y/"
17+
4. Copy c8y_Command.py to the following directory "/bin/"
18+
5. Make sure, that both files do have permissions for beeing executed by tedge_mapper ("chmod 644 c8y_Command and chmod 555 c8y_Command.py")
19+
20+
21+
## Usage
22+
23+
Make sure thin-edge.io is connected to Cumulocity.
24+
If installation is done properly according to the steps above, you hae to disconnect and reconnect thin-edge.io. In that way the suppoerted Operations will be updated.
25+
26+
```shell
27+
sudo tedge disconnect c8y
28+
```
29+
30+
and
31+
32+
```shell
33+
sudo tedge connect c8y
34+
```
35+
36+
However it would also to be sufficient to restart the tedge_mapper service via e.g.:
37+
38+
```shell
39+
sudo systemctl tedge_mapper restart
40+
```
41+
42+
You device within Cumulocity should look similar to this afterwards:
43+
44+
45+
<br/><br/>
46+
<p style="text-indent:30px;">
47+
<a>
48+
<center>
49+
<img width="70%" src="pics/dm.png">
50+
</center>
51+
</a>
52+
</p>
53+
<br/>
54+
55+
You can create a command you want to be executed on the device side, such as e.g. ls.
56+
57+
<br/><br/>
58+
<p style="text-indent:30px;">
59+
<a>
60+
<center>
61+
<img width="70%" src="pics/command.png">
62+
</center>
63+
</a>
64+
</p>
65+
<br/>
66+
67+
If you click on "Execute" thin-edge.io triggers the c8y_Command.py script. You can check the output of the command in the section on the right.
68+
69+
<br/><br/>
70+
<p style="text-indent:30px;">
71+
<a>
72+
<center>
73+
<img width="70%" src="pics/result.png">
74+
</center>
75+
</a>
76+
</p>
77+
<br/>

c8y-operations/Command/c8y_Command

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[exec]
2+
topic = "c8y/s/ds"
3+
on_message = "511"
4+
command = "/etc/c8y_Command.py"

c8y-operations/Command/c8y_Command.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/python3
2+
# coding=utf-8
3+
import sys
4+
from paho.mqtt import client as mqtt_client
5+
import os
6+
7+
broker = 'localhost'
8+
port = 1883
9+
client_id = 'command-operation-client'
10+
11+
12+
command = sys.argv[1].split(',')[2]
13+
client = mqtt_client.Client(client_id)
14+
client.connect(broker, port)
15+
16+
17+
client.publish('c8y/s/us','501,c8y_Command')
18+
stream = os.popen(f'{command}')
19+
output = stream.read()
20+
client.publish('c8y/s/us',f'503,c8y_Command,"{output}"')
54.3 KB
Loading

c8y-operations/Command/pics/dm.png

175 KB
Loading
64.5 KB
Loading
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
paho-mqtt
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# thin-edge.io Textbased Configuration plugin
2+
3+
To configure a device that runs thin-edge.io, a plugin of the operation plugin concept is used. The tedge_agent is checking for configuration operation and is triggering the particular plugin. You can use the configuration tab in device management to change a text based configuration. The plugin itself currently only receives and acknowledges the config change, but does not do anything with it. The part where this can be included is shown in the code section.
4+
5+
## Requirements
6+
7+
- Working thin-edge.io installation
8+
9+
- Python3 and pip3 installation (will not work on python2)
10+
11+
12+
## Installation
13+
14+
1. Clone this repo on the thin-edge.io device
15+
2. run pip3 install -r requirements.txt from this Configuration directory
16+
3. Copy c8y_Configuration to the following directory "/etc/tedge/operations/c8y/"
17+
4. Copy c8y_Configuration.py to the following directory "/bin/"
18+
5. Make sure, that both files do have permissions for beeing executed by tedge_mapper ("chmod 644 c8y_Configuration and chmod 555 c8y_Configuration.py")
19+
20+
21+
## Usage
22+
23+
Make sure thin-edge.io is connected to Cumulocity.
24+
If installation is done properly according to the steps above, you hae to disconnect and reconnect thin-edge.io. In that way the suppoerted Operations will be updated.
25+
26+
```shell
27+
sudo tedge disconnect c8y
28+
```
29+
30+
and
31+
32+
```shell
33+
sudo tedge connect c8y
34+
```
35+
36+
However it would also to be sufficient to restart the tedge_mapper service via e.g.:
37+
38+
```shell
39+
sudo systemctl tedge_mapper restart
40+
```
41+
42+
You device within Cumulocity should look similar to this afterwards:
43+
44+
45+
<br/><br/>
46+
<p style="text-indent:30px;">
47+
<a>
48+
<center>
49+
<img width="70%" src="pics/dm.png">
50+
</center>
51+
</a>
52+
</p>
53+
<br/>
54+
55+
You can configure now within the configuration tab to what text, variables etc the config should hold.
56+
57+
<br/><br/>
58+
<p style="text-indent:30px;">
59+
<a>
60+
<center>
61+
<img width="70%" src="pics/config.png">
62+
</center>
63+
</a>
64+
</p>
65+
<br/>
66+
67+
If you click on "Send configuration to device" thin-edge.io triggers the c8y_Configuration.py script.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[exec]
2+
topic = "c8y/s/ds"
3+
on_message = "513"
4+
command = "/bin/c8y_Configuration.py"
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/python3
2+
# coding=utf-8
3+
import sys
4+
from paho.mqtt import client as mqtt_client
5+
6+
broker = 'localhost'
7+
port = 1883
8+
client_id = 'configuration-operation-client'
9+
10+
11+
config = sys.argv[1].split(',')[2]
12+
client = mqtt_client.Client(client_id)
13+
client.connect(broker, port)
14+
client.publish('c8y/s/us','501,c8y_Configuration')
15+
client.publish('c8y/s/us',f'113,{config}')
16+
###Enter code here for doing somethin with the configuration
17+
client.publish('c8y/s/us','503,c8y_Configuration')

0 commit comments

Comments
 (0)