|
1 | 1 | # modbus-plugin |
2 | 2 |
|
3 | | -# Requirements |
| 3 | +## Requirements |
| 4 | +* Ubuntu >= 22.04 or Debian >= 11.0 |
4 | 5 | * Python >= 3.9 |
| 6 | +* pip |
5 | 7 |
|
6 | | -# Setup (without deb package) |
| 8 | +## Build |
| 9 | + |
| 10 | +### Python Wheel |
| 11 | +* cd to the source root |
| 12 | +* install the build helper via `pip install build` and do a `python -m build` |
| 13 | + |
| 14 | +### Debian package |
| 15 | + |
| 16 | +Make sure to run the following on a build environment that matches the target. |
| 17 | +If you are using a WSL container, make sure that the build directory is not on a Windows path (e.g. /mnt/c), |
| 18 | +as Windows filesystem won't handle the permissions correctly (sets +x on everything) |
| 19 | + |
| 20 | +* do the Python Wheel build: install the build helper via `pip install build` and do a `python -m build` |
| 21 | +* install all dependencies `sudo apt-get install build-essential debhelper devscripts equivs dh-virtualenv` |
| 22 | +* cd into the source root folder (the one that includes the debian directory) |
| 23 | +* run `dpkg-buildpackage -us -uc -b` In case you are running into problems with virtualenv, try a `sudo pip install virtualenv` first |
| 24 | + |
| 25 | +## Deployment |
| 26 | + |
| 27 | +### As Python script (for dev only) |
7 | 28 | * copy modbus-plugin folder to target device |
8 | 29 | * ssh into device and go to the plugin folder |
9 | 30 | * create the virtualenv with `python -m venv venv` |
10 | 31 | * activate venv environment with `source ./venv/bin/activate` |
11 | 32 | * install all dependencies with `python -m pip install -r requirements.txt` |
12 | | -* run the reader with `python c8y_ModbusListener/reader.py -c ./config` |
| 33 | +* run the reader with `python modbus_reader/reader.py -c ./config` |
| 34 | + |
| 35 | +### As deb file |
| 36 | +Run `sudo dpkg -i te-modbus-plugin-<version>-<arch>.deb` |
| 37 | + |
| 38 | + |
| 39 | + |
| 40 | +## Logs and systemd service |
| 41 | +Executing the deb installer will place the config files into /etc/tedege/plugins/modbus/. |
| 42 | +If systemd is installed, it will run the service as part of the post-installation routine. |
| 43 | + |
| 44 | +Check the status of the systemd service with `sudo systemctl status te-modbus-plugin.service` |
| 45 | +When running as a service, the default log output goes to /var/log/te-modbus-plugin/modbus.log. |
13 | 46 |
|
14 | | -# Config files |
| 47 | + |
| 48 | +## Config files |
15 | 49 |
|
16 | 50 | All config files are expected to be in the /etc/tedge/plugins/modbus folder. |
17 | 51 | As alternative the directory can be based with -c or --configdir to the python script like so: |
18 | | -`python c8y_ModbusListener/reader.py --configdir <configfolder>` |
| 52 | +`python modbus_reader/reader.py --configdir <configfolder>` |
19 | 53 |
|
20 | 54 |
|
21 | | -## modbus.toml |
| 55 | +### modbus.toml |
22 | 56 | Includes the basic configuration for the plugin: |
23 | 57 | * poll rate |
24 | 58 | * connection to thin-edge (MQTT broker needs to match the one of tedge) |
25 | 59 |
|
26 | | -## devices.toml |
| 60 | +### devices.toml |
27 | 61 |
|
28 | 62 | Defines the existing child devices and their protocol for polling the Modbus folder. |
29 | 63 | The structure is based on the Cloud Fieldbus protocols. |
| 64 | +Add a `[[device]]` entry for each different IP address |
30 | 65 |
|
31 | | -## watchdog |
32 | | -The watchdog will take care of restarting the MQTT and Modbus connection when either |
| 66 | +### Updating the config files |
| 67 | +A watchdog observer will take care of restarting the MQTT and Modbus connection when either |
33 | 68 | devices.toml or modbus.toml changes. So there should be no need to manually restart the |
34 | | -python script. |
| 69 | +python script / service. |
| 70 | + |
| 71 | + |
| 72 | +## Cumulocity Integration |
| 73 | +### Installation via Software Management |
| 74 | + |
| 75 | +Upload the deb package to the Cumulocity Software Repository. The name **must** be *te-modbus-plugin* and |
| 76 | +the version **must** match the version in the *.deb package name (e.g. 1.0.0). The rest of the fields can be set as necessary. |
| 77 | +Go to the Software tab of the target device and select the package for installation. After the operation is successfull the plugin will start automatically on the device. |
| 78 | + |
| 79 | +### Log file access |
| 80 | + |
| 81 | + |
| 82 | +For integration with the C8Y log plugin add the following line to the /etc/tedge/c8y/c8y-log-plugin.toml |
| 83 | + |
| 84 | + { type = "modbus", path = "/var/log/te-modbus-plugin/modbus.log" } |
| 85 | + |
| 86 | + |
| 87 | + |
| 88 | +### Config management |
| 89 | +Both config files can either be updated in-place (i.e. simply editing with an editor) or |
| 90 | +by using the c8y-configuration plugin. Add the following lines to the c8y-configuration-plugin.toml |
| 91 | +to be able to access them from the Cumulocity Configuration UI: |
| 92 | + |
| 93 | + {path = '/etc/tedge/plugins/modbus/modbus.toml', type='modbus'}, |
| 94 | + {path = '/etc/tedge/plugins/modbus/devices.toml', type='modbus-devices'} |
| 95 | + |
| 96 | +To replace the files with a version from the C8Y Configuration Repository you have to download a copy, |
| 97 | +edit it and upload it to the repository. The device type **must** be set to *thin-edge.io* and the config type must match |
| 98 | +the definition in your c8y-configuration-plugin.toml. I.e either *modbus* (for modbus.toml) or *modbus-devices* for (devices.toml) |
| 99 | + |
| 100 | + |
0 commit comments