---
title: IoT Gateway - GIGAIPC
tags: Edge
image:
---
# IoT Gateway - GIGAIPC
[toc]
## 維修後帳號
* address : 192.168.1.111
* 帳號:star 密碼:5giotlead
* root密碼:apexx
## todo
* how to check if modbus, serial, gpio are built-in kernel drivers?
* Brand new hardware installation steps
* ...
## 技宸GIGAIPC | QBiX-WP-APLA3940H-A1
### Rear I/O
* 1 x (M12) COM (RS-232/422/485 & RI/5V/12V)
* 2 x (M12) COM (RS-232)
* 1 x (M12) GPIO (8 bits)
* 1 x (M12) DC IN
### BIOS
* ...
* ...
### Distribution
> Debian 11
```
star@gateway:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 11 (bullseye)
Release: 11
Codename: bullseye
$ uname -a
Linux gateway 5.10.0-21-amd64 #1 SMP Debian 5.10.162-1 (2023-01-21) x86_64 GNU/Linux
```
> serial driver
```
$ sudo dmesg | grep -i serial
[ 1.608690] Serial: 8250/16550 driver, 4 ports, IRQ sharing enabled
[ 2.040732] usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[ 2.040738] usb usb1: SerialNumber: 0000:00:15.0
[ 2.046967] usb usb2: New USB device strings: Mfr=3, Product=2, SerialNumber=1
[ 2.046973] usb usb2: SerialNumber: 0000:00:15.0
/lib/modules/5.10.0-21-amd64/kernel/drivers/tty/serial/8250/
8250
├── 8250_exar.ko
├── 8250_lpss.ko
└── serial_cs.ko
```
> gpio driver
```
$ sudo dmesg | grep -i gpio
[ 7.988801] gpio_it87: disagrees about version of symbol module_layout
/lib/modules/5.10.0-21-amd64/kernel/drivers/hwmon/it87.ko
```
### Use case: Display
### Use case: iAeris2
> 室內空氣品質偵測器
[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/ttyS0", #必要 設定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.
},
{
"tag": "humidity",
"type": "16uint",
"functionCode": 3,
"objectsCount": 1,
"address": 27
}
],
"attributeUpdates": [
],
"rpc": [
]
}
]
}
}
```

```
star@gateway:/lib/modules/5.10.0-21-amd64/kernel/drivers/tty$ ls -l /dev/ttyS*
crwxrwxrwx 1 root dialout 4, 64 Feb 1 14:55 /dev/ttyS0
crw-rw-rw- 1 root dialout 4, 65 Jan 30 16:28 /dev/ttyS1
crw-rw-rw- 1 root dialout 4, 66 Jan 30 16:28 /dev/ttyS2
crw-rw-rw- 1 root dialout 4, 67 Jan 30 16:28 /dev/ttyS3
```
* ==接線方式==
### 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)


* ==接線方式==
### GPIO Address based on Super IO - ITE8786E
> Lab 機種,==Default 欄位可能為 Low==。

* **GPIO Driver**
```
//寶高對照組
gwbackup@GW-1:~$ ls -l /dev/gpiochip*
crw------- 1 root root 254, 0 Oct 18 13:43 /dev/gpiochip0
crw------- 1 root root 254, 1 Oct 18 13:43 /dev/gpiochip1
crw------- 1 root root 254, 2 Oct 18 13:43 /dev/gpiochip2
crw------- 1 root root 254, 3 Oct 18 13:43 /dev/gpiochip3
crw-rw-rw- 1 root root 254, 4 Oct 18 13:44 /dev/gpiochip4
gwbackup@GW-1:~$ sudo gpiodetect
[sudo] password for gwbackup:
gpiochip0 [INT3452:00] (78 lines)
gpiochip1 [INT3452:01] (77 lines)
gpiochip2 [INT3452:02] (47 lines)
gpiochip3 [INT3452:03] (43 lines)
gpiochip4 [gpio_it87] (64 lines)
gwbackup@GW-1:~$ lsmod | grep it87
gpio_it87 16384 0
// Lab 實驗組
$ ls -l /dev/gpiochip*
crw------- 1 root root 254, 0 Jan 30 16:28 /dev/gpiochip0
crw------- 1 root root 254, 1 Jan 30 16:28 /dev/gpiochip1
crw------- 1 root root 254, 2 Jan 30 16:28 /dev/gpiochip2
crw------- 1 root root 254, 3 Jan 30 16:28 /dev/gpiochip3
star@gateway:~$ sudo gpiodetect
[sudo] password for star:
gpiochip0 [INT3452:00] (78 lines)
gpiochip1 [INT3452:01] (77 lines)
gpiochip2 [INT3452:02] (47 lines)
gpiochip3 [INT3452:03] (43 lines)
star@gateway:~$ lsmod | grep it87
star@gateway:~$
```
* **insmod gpio_it87**
1.download GPIO-driver.tar.gz
2.``$ tar zxvf GPIO-driver.tar.gz``
```
star@gateway:/bin/root/GPIO/drv$ ls
giodrv.c gpio-it87.ko gpio-it87.mod.o modules.order
giodrv.h gpio-it87.mod gpio-it87.o Module.symvers
gpio-it87.c gpio-it87.mod.c Makefile
```
3.remake gpio-it87.ko ``$ sudo /bin/sh -c make``
```
[sudo] password for star:
make -C /lib/modules/5.10.0-21-amd64/build M=/usr/bin/root/GPIO/drv modules
make[1]: Entering directory '/usr/src/linux-headers-5.10.0-21-amd64'
CC [M] /usr/bin/root/GPIO/drv/gpio-it87.o
MODPOST /usr/bin/root/GPIO/drv/Module.symvers
CC [M] /usr/bin/root/GPIO/drv/gpio-it87.mod.o
LD [M] /usr/bin/root/GPIO/drv/gpio-it87.ko
make[1]: Leaving directory '/usr/src/linux-headers-5.10.0-21-amd64'
```
4.``$ sudo insmod gpio-it87.ko``
5.check gpio
```
star@gateway:/bin/root/GPIO/test$ ls -l /dev/gpiochip*
.crw------- 1 root root 254, 0 Feb 23 12:00 /dev/gpiochip0
crw------- 1 root root 254, 1 Feb 23 12:00 /dev/gpiochip1
crw------- 1 root root 254, 2 Feb 23 12:00 /dev/gpiochip2
crw------- 1 root root 254, 3 Feb 23 12:00 /dev/gpiochip3
crw-rw-rw- 1 root root 254, 4 Mar 3 10:30 /dev/gpiochip4
star@gateway:/bin/root/GPIO/test$ .lsmod | grep it87
star@gateway:/bin/root/GPIO/test$ lsmod | grep it87
gpio_it87 16384 0
it87 65536 0
hwmon_vid 16384 1 it87
gpiochip4 - 64 lines:
line 0: "it87_gp10" unused input active-high
line 1: "it87_gp11" unused input active-high
line 2: "it87_gp12" unused input active-high
line 3: "it87_gp13" unused input active-high
line 4: "it87_gp14" unused input active-high
line 5: "it87_gp15" unused input active-high
line 6: "it87_gp16" unused input active-high
line 7: "it87_gp17" unused input active-high
line 8: "it87_gp20" unused input active-high
line 9: "it87_gp21" unused input active-high
line 10: "it87_gp22" unused input active-high
line 11: "it87_gp23" unused input active-high
line 12: "it87_gp24" unused input active-high
line 13: "it87_gp25" unused input active-high
line 14: "it87_gp26" unused input active-high
line 15: "it87_gp27" unused input active-high
line 16: "it87_gp30" unused input active-high
line 17: "it87_gp31" unused input active-high
line 18: "it87_gp32" unused input active-high
line 19: "it87_gp33" unused input active-high
line 20: "it87_gp34" unused input active-high
line 21: "it87_gp35" unused input active-high
line 22: "it87_gp36" unused input active-high
line 23: "it87_gp37" unused input active-high
line 24: "it87_gp40" unused input active-high
line 25: "it87_gp41" unused input active-high
line 26: "it87_gp42" unused input active-high
line 27: "it87_gp43" unused input active-high
line 28: "it87_gp44" unused input active-high
line 29: "it87_gp45" unused input active-high
line 30: "it87_gp46" unused input active-high
line 31: "it87_gp47" unused input active-high
line 32: "it87_gp50" unused input active-high
line 33: "it87_gp51" unused input active-high
line 34: "it87_gp52" unused input active-high
line 35: "it87_gp53" unused input active-high
line 36: "it87_gp54" unused input active-high
line 37: "it87_gp55" unused input active-high
line 38: "it87_gp56" unused input active-high
line 39: "it87_gp57" unused input active-high
line 40: "it87_gp60" unused input active-high
line 41: "it87_gp61" unused input active-high
line 42: "it87_gp62" unused input active-high
line 43: "it87_gp63" unused input active-high
line 44: "it87_gp64" unused input active-high
line 45: "it87_gp65" unused input active-high
line 46: "it87_gp66" unused input active-high
line 47: "it87_gp67" unused input active-high
line 48: "it87_gp70" unused input active-high
line 49: "it87_gp71" unused input active-high
line 50: "it87_gp72" unused input active-high
line 51: "it87_gp73" unused input active-high
line 52: "it87_gp74" unused input active-high
line 53: "it87_gp75" unused input active-high
line 54: "it87_gp76" unused input active-high
line 55: "it87_gp77" unused input active-high
line 56: "it87_gp80" unused input active-high
line 57: "it87_gp81" unused input active-high
line 58: "it87_gp82" unused input active-high
line 59: "it87_gp83" unused input active-high
line 60: "it87_gp84" unused input active-high
line 61: "it87_gp85" unused input active-high
line 62: "it87_gp86" unused input active-high
line 63: "it87_gp87" unused input active-high
star@gateway:/etc/udev/rules.d$ cat 60-gpio.rules
KERNEL=="gpiochip4", MODE="0666"
star@gateway:/sys/class/gpio$ ls -all
total 0
drwxr-xr-x 2 root root 0 Feb 23 12:00 .
drwxr-xr-x 56 root root 0 Feb 23 12:00 ..
--w------- 1 root root 4096 Feb 24 10:16 export
lrwxrwxrwx 1 root root 0 Mar 6 11:11 gpiochip203 -> ../../devices/gpiochip4/gpio/gpiochip203
lrwxrwxrwx 1 root root 0 Feb 23 12:00 gpiochip267 -> ../../devices/platform/INT3452:03/gpio/gpiochip267
lrwxrwxrwx 1 root root 0 Feb 23 12:00 gpiochip310 -> ../../devices/platform/INT3452:02/gpio/gpiochip310
lrwxrwxrwx 1 root root 0 Feb 23 12:00 gpiochip357 -> ../../devices/platform/INT3452:01/gpio/gpiochip357
lrwxrwxrwx 1 root root 0 Feb 23 12:00 gpiochip434 -> ../../devices/platform/INT3452:00/gpio/gpiochip434
--w------- 1 root root 4096 Feb 24 10:39 unexport
```
### Data Convert
絕大多數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檔中設定每個屬性的乘除常數運算,但僅限乘除運算

### 開機重啟edge、gateway server及web kiosk
[Debian 開機自動執行腳本](https://hackmd.io/@eric82418/HJ43S9Zg2)
* How to program GPIO?
* file system
* sysfs interface
* Python (using various modules)
* C or C++
## References
* [QBiX-WP-APLA3940H-A1](https://drive.google.com/file/d/17tugO7gtcRPit-ClicDPVusX4ygYrPG5/view?usp=share_link)
* [必備的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)
* [Managing snaps](https://snapcraft.io/docs/service-management)