Getting started with ThingsBoard IoT Gateway
What is Thingsboard IoT Gateway?
- Devices > –- modbus –- > converter / connector >
- …
Installation
Docker + Linux
Prerequisites: docker ce + docker-compose
Docker basics
- How to Do a Clean Restart of a Docker Instance details
- Stop the container(s) using the following command:
docker-compose down
- Delete all containers using the following command:
docker rm -f $(docker ps -a -q)
- Delete all volumes using the following command:
docker volume rm $(docker volume ls -q)
Note: Deleting volumes will wipe out their data. Back up any data that you need before deleting a container.
- Restart the containers using the following command:
docker-compose up -d
- …
docker-compose.yml (template here)
- working directory with the file "docker-compose.yml":
cd ~/workspace/tb
docker-compose up -d
docker-compose logs --tail 10
star@gateway:~/workspace/tb$ docker exec -it tb-gw-1 bash
console error
tb-gw-1 | ""2023-01-31 04:50:23" - |ERROR| - [modbus_connector.py] - modbus_connector - __process_slaves - 342 - int() argument must be a string, a bytes-like object or a real number, not 'NoneType'"
tb-gw-1 | Traceback (most recent call last):
tb-gw-1 | File "/thingsboard_gateway/connectors/modbus/modbus_connector.py", line 311, in __process_slaves
tb-gw-1 | self.__connect_to_current_master(device)
tb-gw-1 | File "/thingsboard_gateway/connectors/modbus/modbus_connector.py", line 357, in __connect_to_current_master
tb-gw-1 | device.config['master'], device.config['available_functions'] = self.__configure_master(device.config)
tb-gw-1 | File "/thingsboard_gateway/connectors/modbus/modbus_connector.py", line 419, in __configure_master
tb-gw-1 | master = ModbusSerialClient(method=current_config["method"],
tb-gw-1 | File "/root/.local/lib/python3.10/site-packages/pymodbus/client/serial.py", line 196, in __init__
tb-gw-1 | super().__init__(framer=framer, **kwargs)
tb-gw-1 | File "/root/.local/lib/python3.10/site-packages/pymodbus/client/base.py", line 120, in __init__
tb-gw-1 | self.params.retries = int(retries)
tb-gw-1 | TypeError: int() argument must be a string, a bytes-like object or a real number, not 'NoneType'
tb-gw-1 | ""2023-01-31 04:50:28" - |ERROR| - [modbus_connector.py] - modbus_connector - __process_slaves - 342 - int() argument must be a string, a bytes-like object or a real number, not 'NoneType'"
tb-gw-1 | Traceback (most recent call last):
tb-gw-1 | File "/thingsboard_gateway/connectors/modbus/modbus_connector.py", line 311, in __process_slaves
tb-gw-1 | self.__connect_to_current_master(device)
tb-gw-1 | File "/thingsboard_gateway/connectors/modbus/modbus_connector.py", line 357, in __connect_to_current_master
tb-gw-1 | device.config['master'], device.config['available_functions'] = self.__configure_master(device.config)
tb-gw-1 | File "/thingsboard_gateway/connectors/modbus/modbus_connector.py", line 419, in __configure_master
tb-gw-1 | master = ModbusSerialClient(method=current_config["method"],
tb-gw-1 | File "/root/.local/lib/python3.10/site-packages/pymodbus/client/serial.py", line 196, in __init__
tb-gw-1 | super().__init__(framer=framer, **kwargs)
tb-gw-1 | File "/root/.local/lib/python3.10/site-packages/pymodbus/client/base.py", line 120, in __init__
tb-gw-1 | self.params.retries = int(retries)
tb-gw-1 | TypeError: int() argument must be a string, a bytes-like object or a real number, not 'NoneType'
tb-gw-1 | ""2023-01-31 04:50:33" - |ERROR| - [modbus_connector.py] - modbus_connector - __process_slaves - 342 - int() argument must be a string, a bytes-like object or a real number, not 'NoneType'"
tb-gw-1 | Traceback (most recent call last):
tb-gw-1 | File "/thingsboard_gateway/connectors/modbus/modbus_connector.py", line 311, in __process_slaves
tb-gw-1 | self.__connect_to_current_master(device)
tb-gw-1 | File "/thingsboard_gateway/connectors/modbus/modbus_connector.py", line 357, in __connect_to_current_master
tb-gw-1 | device.config['master'], device.config['available_functions'] = self.__configure_master(device.config)
tb-gw-1 | File "/thingsboard_gateway/connectors/modbus/modbus_connector.py", line 419, in __configure_master
tb-gw-1 | master = ModbusSerialClient(method=current_config["method"],
tb-gw-1 | File "/root/.local/lib/python3.10/site-packages/pymodbus/client/serial.py", line 196, in __init__
tb-gw-1 | super().__init__(framer=framer, **kwargs)
tb-gw-1 | File "/root/.local/lib/python3.10/site-packages/pymodbus/client/base.py", line 120, in __init__
tb-gw-1 | self.params.retries = int(retries)
tb-gw-1 | TypeError: int() argument must be a string, a bytes-like object or a real number, not 'NoneType'
try to make freeze and see that versions of libs
Ubuntu 20 / Debian 11
- (optional but recommended)
sudo apt update
1. Download the deb file (/home/swae/workspace/tb-gw)
2. Install the gateway using apt
3. Check gateway status
details
(optional) 4. Hot Reloader
Enable hot reloader to restart Gateway every time when we edit any project file when using Gateway for development.
python3 ./thingsboard_gateway/tb_gateway.py true
–- source code
python3 /usr/lib/python3/dist-packages/thingsboard_gateway/tb_gateway.py true
Configuration
Directory structure
-
- path: /etc/thingsboard-gateway/config/*
- tb_gateway.yaml
Disable Statistics
-
- statistics.json –- /usr/lib/python3/dist-packages/thingsboard_gateway/config/statistics.json
- …
Custom
iAeris20 setting
gateway 讀取 iAeris register 的資料經由hex轉換成int時會以4位數呈現小數點後兩位,此呈現方式在顯示上並不符合閱讀邏輯。
暫時解決方案為在 bytes_modbus_uplink_converter.py 檔案中添加下方程式碼強制轉換,後續須考慮新方法以解決不同機型產生的數字所代表的含意。
Edit bytes_modbus_uplink_converter.py (+line 83)
p.s. docker在更新過後需重啟docker才能生效
Result:
before:
tb-gw-1 | ""2023-02-21 03:30:37" - |INFO| - [modbus_connector.py] - modbus_connector - run - 651 - {'deviceName': 'iAeris 20', 'deviceType': 'default', 'telemetry': [{'temperature': 2660}, {'humidity': 3590}], 'attributes': []}"
after:
tb-gw-1 | ""2023-02-21 06:41:00" - |INFO| - [modbus_connector.py] - modbus_connector - run - 651 - {'deviceName': 'iAeris 20', 'deviceType': 'default', 'telemetry': [{'temperature': 26.9}, {'humidity': 34.9}], 'attributes': []}"
Troubleshooting
sudo stty -a -F /dev/ttyS0
- error log: tail -f /var/log/thingsboard-gateway/connector.log
sudo pip3 install pymodbus pyserial twisted --upgrade
modpoll
linux-serial-test (helpless wiht RS-485 mode :<)
Log files
- /etc/thingsboard-gateway/config/logs.conf
- /var/log/thingsboard-gateway/*
References
Star's Lab (手上沒有硬體的做法)
- Windows Modbus slave simulator
- Linux Modbus master simulator here