---
title: IoT Gateway - 21380A
tags: Edge
image:
---
# IoT Gateway - 21380A
[toc]
## todo
* 如何在沒有 GPIO port 情況下使用 Reed switch
* ...
* ...
## 21380A
### Front I/O
* 1 x Audio out
* 1 x MIC
* 2 x USB
### Rear I/O
* 1 x HDMI
* 2 x USB
* 1 x NIC (4c:02:89:18:8b:69)
* 1 x VGA
* 1 x COM (RS-232)
* 1 x DC IN
### BIOS
* ...
* ...
### Distribution
> Debian 11 (192.168.1.111)
```
display@display:~/workspace/tb-gateway$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 11 (bullseye)
Release: 11
Codename: bullseye
display@display:~/workspace/tb-gateway$ uname -a
Linux display 5.10.0-21-amd64 #1 SMP Debian 5.10.162-1 (2023-01-21) x86_64 GNU/Linux
```
> serial driver
```
display@display:~/workspace/tb-gateway$ sudo dmesg | grep -i serial
[ 2.388696] Serial: 8250/16550 driver, 4 ports, IRQ sharing enabled
[ 2.936085] usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[ 2.936092] usb usb1: SerialNumber: 0000:00:14.0
[ 2.950526] usb usb2: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[ 2.950533] usb usb2: SerialNumber: 0000:00:14.0
[ 3.415870] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[ 3.703574] usb 1-2: New USB device strings: Mfr=1, Product=2, SerialNumber=0
[ 3.997581] usb 1-4: New USB device strings: Mfr=1, Product=3, SerialNumber=0
```
### Install Docker Engine on Debian
1. uninstall old versions
``
$ sudo apt-get remove docker docker-engine docker.io containerd runc
``
2. Set up the repository
* 1. Update the apt package index and install packages to allow apt to use a repository over HTTPS
```
$ sudo apt-get update
$ sudo apt-get install \
ca-certificates \
curl \
gnupg \
lsb-release
```
* 2. Add Docker's official GPG key
```
$ sudo mkdir -m 0755 -p /etc/apt/keyrings
$ curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
```
* 3. Use the following command to set up the repository
```
$ echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
```
3. Install Docker Engine
* 1. Update the apt package index
``
$ sudo apt-get update
``
* 2. Install Docker Engine, containerd,and Docker Compose
``
$ sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
``
4. Add User to docker group
``
$ sudo usermod -aG docker $(whoami)
``
5. Test
``
$ docker run hello-world
``
### Use case: Display
> Install Ubuntu Frame (Debian 11)
```
$ sudo apt install snapd
$ sudo snap install core
$ sudo snap install ubuntu-frame
$ sudo snap set ubuntu-frame daemon=true
$ sudo snap get ubuntu-frame daemon
```
> Install a Web Kiosk in Ubuntu Core
```
$ sudo snap install wpe-webkit-mir-kiosk
$ sudo snap set wpe-webkit-mir-kiosk daemon=true
$ sudo snap get wpe-webkit-mir-kiosk daemon
$ sudo snap logs wpe-webkit-mir-kiosk
$ sudo snap connect wpe-webkit-mir-kiosk:wayland
$ snap info wpe-webkit-mir-kiosk
name: wpe-webkit-mir-kiosk
summary: WPE Webkit in kiosk mode. Intended for mir-kiosk on embedded devices.
publisher: GLANCR labs (glancr)
store-url: https://snapcraft.io/wpe-webkit-mir-kiosk
contact: kontakt@glancr.de
license: unset
description: |
WPE Webkit [1] is an official port of the WebKit project.
This snap packages WPE, backend libraries and the cog web app container [2] in kiosk mode.
Requires the `ubuntu-frame` snap (formerly `mir-kiosk`) on Ubuntu Core, or a compatible Wayland
compositor on desktop systems. See the README [3] for limitations and options.
On Core systems, the browser is running as a service, and will be automatically restarted after
`ubuntu-frame` (or `mir-kiosk`) refreshes.
On desktop systems, the application `wpe-webkit-mir-kiosk.cog` starts the launcher in windowed
mode, suitable for testing.
From the WPE website: “WPE WebKit allows embedders to create simple and performant
systems based on Web platform technologies. It is designed with hardware
acceleration in mind, leveraging common 3D graphics APIs for best
performance.”
1: https://wpewebkit.org
2: https://github.com/Igalia/cog
3: https://gitlab.com/glancr/wpe-webkit-snap/-/blob/main/README.md
commands:
- wpe-webkit-mir-kiosk.cog
- wpe-webkit-mir-kiosk.list-websettings
services:
wpe-webkit-mir-kiosk.daemon: simple, enabled, inactive
wpe-webkit-mir-kiosk.restart-watcher: simple, enabled, active
snap-id: 01sV9tv4UTUQTU3jYsAF1gJ5qv7ZqGls
tracking: latest/stable
refresh-date: today at 13:56 CST
channels:
latest/stable: 2.38.2 2023-01-11 (90) 136MB -
latest/candidate: 2.38.5 2023-02-17 (92) 178MB -
latest/beta: 2.38.5 2023-02-17 (92) 178MB -
latest/edge: 2.38.5 2023-02-17 (92) 178MB -
installed: 2.38.2 (90) 136MB -
```
> Config (cfg file: /var/snap/ubuntu-frame/current/frame.config)
```
sudo snap set ubuntu-frame config="cursor=null"
```
> Display your website / dashboard
```
sudo snap set wpe-webkit-mir-kiosk url=http://192.168.1.110:8080/?username=display@5giotlead.com\&password=display
```
### Use case: iAeris 20
> 室內空氣品質偵測器
[iAeris2 details](https://www.sysinnotec.com/product-cn)
* iAeris simple Command
[iAeris simple Command here](https://hackmd.io/@eric82418/iAeris20SimpleUsermanual)
* config 設定
.00000000000000000000000000000!!!注意Modbus必須將系統範例中的[server device]換成[master,slaves]!!!

```
{
"master": {
"slaves": [
{
"type": "serial", #必要 ModBus連結方式,tcp、udp、serial
"method": "rtu", #必要 ModBus協定,serial分 rtu、ascii ,Tcp/udp分socket、rtu
"port": "/dev/ttyUSB0", #必要 設定serial port 路徑
"baudrate": 19200, #必要 設定設備baudrate
"timeout": 35, #必要
"stopbits": 1, #The number of bits sent after each character in a message to indicate the end of the byte.
"bytesize": 8, #The number of bits in a byte of serial data. This can be one of 5, 6, 7, or 8.
"byteOrder": "BIG", #必要 位元組順序,分LITTLE 及 BIG
"wordOrder": "BIG", #必要
"retries": true, #Retrying sending data to the master. The values: true or false
"retryOnEmpty": true, #Retrying sending data to the master if it is empty
"retryOnInvalid": true, #Retrying sending data to the master if it is failed
"pollPeriod": 5000, #必要 輪詢期 (ms)
"unitId": 1, #必要 設備ID
"deviceName": "iAeris 20", #必要 設備名稱
"deviceType": "intelligent cabinet", #非必要 設定device profile type ,如果DeviceName已存在TB將無法生效
"attributesPollPeriod": 5000,
"timeseriesPollPeriod": 5000,
"sendDataOnlyOnChange": false, #Sending only if data changed from last check, if no – data will send after every check
"connectAttemptTimeMs": 5000, #A period in milliseconds for waiting to connect to the master
"connectAttemptCount": 5, #The number of connection attempts made through the ThingsBoard gateway
"waitAfterFailedAttemptsMs": 300000, #A period in milliseconds for a wait before trying to send data to the master
"attributes": [
],
"timeseries": [
{
"tag": "temperature", #Tag, which will use as attribute key for ThingsBoard platform instance.
"type": "16uint", #Type of value. Available data types
"functionCode": 3, #Function to use in processing data. Modbus functions
"objectsCount": 1, #Count of objects to read.
"address": 26 #Object address to check.
"divider": 100 #除以常數
},
{
"tag": "humidity",
"type": "16uint",
"functionCode": 3,
"objectsCount": 1,
"address": 27
"multiplier ": 100 #乘以常數
}
],
"attributeUpdates": [
],
"rpc": [
]
}
]
}
}
```
```
display@display:~/workspace/tb-gateway$ ls -l /dev/ttyUSB*
crw-rw---- 1 root dialout 188, 0 Mar 13 22:29 /dev/ttyUSB0
```
### Convert Data in Rule chian
絕大多數Device 的數據儲存都是以 2 word 方式,在16進為轉換後皆需做一次二次轉換才能變成易讀取的數字。在Rule chian進行轉換可以不更動gateway本身程式碼,目前有兩種方式可進行數據轉換,Math function 及 Script
1. Math function
Math function 是最簡易的一種轉換方式,可以將一個或多個數據導入進行各式計算,但也存在缺點產出的輸出只能有一個,故計算多筆數據時,需產生大量Tool block在Rule Chain


2. Script
Script 顧名思義為腳本撰寫,除可計算數據多輸出外,還可進行更多的判斷式,其中分TBEL及Java Script兩種語言撰寫,可以在做簡易的腳本測試,再加入Rule chian



3. Config檔設定
可以在config檔中設定每個屬性的乘除常數運算,但僅限乘除運算

* ==接線方式==
### Use case: Reed switch
> 磁磺開關
[Garrison](https://www.garrison.com.tw/zh-tw/Category/%E7%A3%81%E7%A3%BA%E9%96%8B%E9%97%9C)
### 開機重啟edge、gateway server及web kiosk
[Debian 開機自動執行腳本](https://hackmd.io/@eric82418/HJ43S9Zg2)
## References
* [必備的RS485接口知識](http://www.thcsys.com.tw/tech-inner.php?tech_id=25)
* [Using uart from a linux shell](https://developer.technexion.com/docs/using-uart-from-a-linux-shell)
* [Using gpio from a linux shell](https://developer.technexion.com/docs/using-gpio-from-a-linux-shell)
* [GPIO Programming: Using the sysfs Interface](https://www.ics.com/search/node?keys=gpio)
* [ICS Tech Blog](https://www.ics.com/blog)
* **GPIO Programming**
* [Part 1 An Introduction](https://www.ics.com/blog/introduction-gpio-programming)
* [Part 2 Explore Hardware Capabilities of Raspberry Pi's GPIO Interface](https://www.ics.com/blog/explore-hardware-capabilities-raspberry-pis-gpio-interface)
* [Part 3 Using the sysfs Interface](https://www.ics.com/blog/gpio-programming-using-sysfs-interface)
* [Part 4 Control Raspberry Pi GPIO Pins from Python](https://www.ics.com/blog/control-raspberry-pi-gpio-pins-python)
* [Part 5 How to Control GPIO Hardware from C or C++](https://www.ics.com/blog/how-control-gpio-hardware-c-or-c)
* [Part 6 Experiment with this GPIO Learning Board](https://www.ics.com/blog/experiment-gpio-learning-board)
* [Part 7 A Look at Toradex Colibri SOM with Aster Carrier Board](https://www.ics.com/blog/look-toradex-colibri-som-aster-carrier-board)
* [Part 8 Examining the Cross-Platform libsoc Library](https://www.ics.com/blog/examining-cross-platform-libsoc-library)
* [Part 9 Exploring the libgpiod Library](https://www.ics.com/blog/gpio-programming-exploring-libgpiod-library)
* **Linux_GPIO-Evolution_and_Current_State_of_the_User_API** [PDF](https://elinux.org/images/c/cb/Linux_GPIO-Evolution_and_Current_State_of_the_User_API.pdf)
* [Install Docker Engine on Debian](https://docs.docker.com/engine/install/debian/)
* [Ubuntu Digital Signage](https://hackmd.io/dmG6O4KvR0uagRGSWSoacA)
* **Thingsboard Rule chian**
* [Action Nodes](https://thingsboard.io/docs/user-guide/rule-engine-2-0/action-nodes/)
* [Transform incoming telemetry](https://thingsboard.io/docs/user-guide/rule-engine-2-0/tutorials/transform-incoming-telemetry/)