Skip to content

Commit 67bef4f

Browse files
author
Lenny Goodell
authored
Merge pull request #216 from lenny-intel/readme
docs: Update README to link to new docs
2 parents 1d94a7d + 2b14691 commit 67bef4f

File tree

1 file changed

+19
-253
lines changed

1 file changed

+19
-253
lines changed

README.md

Lines changed: 19 additions & 253 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,29 @@
77
>
88
> **The source for the latest release can be found at [Releases](https://github.com/edgexfoundry/device-gpio/releases).**
99
10-
## Overview
11-
GPIO Micro Service - device service for connecting GPIO devices to EdgeX
10+
## Documentation
1211

13-
- Function:
14-
- This device service uses sysfs ABI (default) or chardev ABI (experiment) to control GPIO devices
15-
For a connected GPIO device, update the configuration files, and then start to read or write data from GPIO device
16-
- This device service **ONLY works on Linux system**
17-
- This device service is contributed by [Jiangxing Intelligence](https://www.jiangxingai.com)
12+
This device service is contributed by [Jiangxing Intelligence](https://www.jiangxingai.com)
13+
14+
For latest documentation please visit https://docs.edgexfoundry.org/latest/microservices/device/services/device-gpio/Purpose
15+
16+
## Build Instructions
17+
18+
1. Clone the device-gpio repo with the following command:
19+
20+
git clone https://github.com/edgexfoundry/device-gpio.git
21+
22+
2. Build a docker image by using the following command:
23+
24+
make docker
25+
26+
3. Alternatively the device service can be built natively:
27+
28+
make build
1829

1930
## Build with NATS Messaging
2031
Currently, the NATS Messaging capability (NATS MessageBus) is opt-in at build time.
21-
This means that the published Docker image does not include the NATS messaging capability.
32+
This means that the published Docker images do not include the NATS messaging capability.
2233

2334
The following make commands will build the local binary or local Docker image with NATS messaging
2435
capability included.
@@ -39,251 +50,6 @@ For docker, please refer to the [Dockerfile] and [Docker Compose Builder] script
3950
[Dockerfile]: Dockerfile
4051
[Docker Compose Builder]: https://github.com/edgexfoundry/edgex-compose/tree/main/compose-builder
4152

42-
## Usage
43-
- This Device Service runs with other EdgeX Core Services, such as Core Metadata, Core Data, and Core Command
44-
- The gpio device service can contains many pre-defined devices which were defined by [device.custom.gpio.yaml](cmd/res/devices/device.custom.gpio.yaml) such as `GPIO-Device01`. These devices are created by the GPIO device service in core metadata when the service first initializes
45-
- Device profiles ([device.custom.gpio.yaml](cmd/res/profiles/device.custom.gpio.yaml)) are used to describe the actual GPIO hardware of a device and allow individual gpios to be given human-readable names/aliases
46-
- After the gpio device service has started, we can read or write these corresponding pre-defined devices
47-
48-
```yaml
49-
name: "Custom-GPIO-Device"
50-
manufacturer: "Jiangxing Intelligence"
51-
model: "SP-01"
52-
labels:
53-
- "device-custom-gpio"
54-
description: "Example of custom gpio device"
55-
56-
deviceResources:
57-
-
58-
name: "Power"
59-
isHidden: false
60-
description: "mocking power button"
61-
attributes: { line: 17 }
62-
properties:
63-
valueType: "Bool"
64-
readWrite: "RW"
65-
66-
-
67-
name: "LED"
68-
isHidden: false
69-
description: "mocking LED"
70-
attributes: { line: 27 }
71-
properties:
72-
valueType: "Bool"
73-
readWrite: "W"
74-
75-
-
76-
name: "Switch"
77-
isHidden: false
78-
description: "mocking switch"
79-
attributes: { line: 22 }
80-
properties:
81-
valueType: "Bool"
82-
readWrite: "R"
83-
```
84-
85-
- Since GPIO sysfs interface is **deprecated after Linux version 4.8**, we provide two ABI interfaces: the sysfs version and the new chardev version. By default we set interface to sysfs, and you can change it inside `Driver` section of `configuration.yaml`. For the chardev interface, you still need to specify a selected chip, this is also under `Driver` section.
86-
87-
## Guidance
88-
Here we give two step by step guidance examples of using this device service. In these examples, we use RESTful API to interact with EdgeX (please notice that, you still need to use Core Command service rather than directly interact with GPIO device service).
89-
90-
Since the `edgex-cli` has released, we can use this new approach to operate devices:
91-
92-
`edgex-cli command list -d GPIO-Device01`
93-
94-
If you would prefer the traditional RESTful way to operate, you can try:
95-
96-
`curl http://localhost:59882/api/v3/device/name/GPIO-Device01`
97-
98-
Use the `curl` response to get the command URLs (with device and command ids) to issue commands to the GPIO device via the command service as shown below. You can also use a tool like `Postman` instead of `curl` to issue the same commands.
99-
100-
```json
101-
{
102-
"apiVersion": "v2",
103-
"statusCode": 200,
104-
"deviceCoreCommand": {
105-
"deviceName": "GPIO-Device01",
106-
"profileName": "Custom-GPIO-Device",
107-
"coreCommands": [
108-
{
109-
"name": "Power",
110-
"get": true,
111-
"set": true,
112-
"path": "/api/v3/device/name/GPIO-Device01/Power",
113-
"url": "http://edgex-core-command:59882",
114-
"parameters": [
115-
{
116-
"resourceName": "Power",
117-
"valueType": "Bool"
118-
}
119-
]
120-
},
121-
{
122-
"name": "LED",
123-
"set": true,
124-
"path": "/api/v3/device/name/GPIO-Device01/LED",
125-
"url": "http://edgex-core-command:59882",
126-
"parameters": [
127-
{
128-
"resourceName": "LED",
129-
"valueType": "Bool"
130-
}
131-
]
132-
},
133-
{
134-
"name": "Switch",
135-
"get": true,
136-
"path": "/api/v3/device/name/GPIO-Device01/Switch",
137-
"url": "http://edgex-core-command:59882",
138-
"parameters": [
139-
{
140-
"resourceName": "Switch",
141-
"valueType": "Bool"
142-
}
143-
]
144-
}
145-
]
146-
}
147-
}
148-
```
149-
150-
### Direction setting with sysfs
151-
When using sysfs, the operations to access and "read" or "write" the GPIO pins are to:
152-
153-
1. Export the pin
154-
2. Set the direction (either IN or OUT)
155-
3. Read the pin input or write the pin value based on the direction
156-
4. Unexport the pin
157-
158-
When using sysfs, setting the direction causes the value to be reset. Therefore, this implementation only sets the direction on opening the line to the GPIO. After that, it is assumed the same direction is used while the pin is in use and exported.
159-
160-
The direction is set by an optional attribute in the device profile called `defaultDirection`. It can be set to either "in" or "out". If it is not set, the default direction is assumed to be "out".
161-
162-
``` yaml
163-
-
164-
name: "LED"
165-
isHidden: false
166-
description: "mocking LED"
167-
attributes: { line: 27, defaultDirection: "out" }
168-
properties:
169-
valueType: "Bool"
170-
readWrite: "W"
171-
```
172-
173-
Note: the direction should not be confused with the device profile's read/write property. If you set the defaultDirection to "in" but then set the readWrite property to "RW" or "W", any attempt to write to the pin will result in a "permission denied" error. For consistency sake, when your defaultDirection is "in" set readWrite to "R" only.
174-
175-
### Write value to GPIO
176-
Assume we have a GPIO device (used for power enable) connected to gpio17 on current system of raspberry pi 4b. When we write a value to GPIO, this gpio will give a high voltage.
177-
178-
```shell
179-
# Set the 'Power' gpio to high
180-
$ curl -X PUT -d '{"Power":"true"}' http://localhost:59882/api/v3/device/name/GPIO-Device01/Power
181-
{"apiVersion":"v2","statusCode":200}
182-
$ cat /sys/class/gpio/gpio17/direction ; cat /sys/class/gpio/gpio17/value
183-
out
184-
1
185-
186-
# Set the 'Power' gpio to low
187-
$ curl -X PUT -d '{"Power":"false"}' http://localhost:59882/api/v3/device/name/GPIO-Device01/Power
188-
{"apiVersion":"v2","statusCode":200}
189-
$ cat /sys/class/gpio/gpio17/direction ; cat /sys/class/gpio/gpio17/value
190-
out
191-
0
192-
```
193-
194-
Now if you test gpio17 of raspberry pi 4b , it is outputting high voltage.
195-
196-
197-
### Read value from GPIO
198-
Assume we have another GPIO device (used for button detection) connected to pin 22 on current system. When we read a value from GPIO, this gpio will be exported and set direction to input.
199-
200-
```shell
201-
$ curl http://localhost:59882/api/v3/device/name/GPIO-Device01/Switch
202-
```
203-
204-
Here, we post some results:
205-
206-
```bash
207-
{
208-
"apiVersion": "v2",
209-
"statusCode": 200,
210-
"event": {
211-
"apiVersion": "v2",
212-
"id": "a6104256-92a4-41a8-952a-396cd3dabe25",
213-
"deviceName": "GPIO-Device01",
214-
"profileName": "Custom-GPIO-Device",
215-
"sourceName": "Switch",
216-
"origin": 1634221479227566300,
217-
"readings": [
218-
{
219-
"id": "240dc2ea-d69f-4229-94c4-3ad0507cf657",
220-
"origin": 1634221479227566300,
221-
"deviceName": "GPIO-Device01",
222-
"resourceName": "Switch",
223-
"profileName": "Custom-GPIO-Device",
224-
"valueType": "Bool",
225-
"value": "false"
226-
}
227-
]
228-
}
229-
}
230-
```
231-
232-
233-
234-
### docker-compose.yml
235-
236-
Add the `device-gpio` to the docker-compose.yml of edgex foundry 2.0-Ireland.
237-
238-
```yml
239-
...
240-
device-gpio:
241-
container_name: edgex-device-gpio
242-
depends_on:
243-
- consul
244-
- data
245-
- metadata
246-
environment:
247-
CLIENTS_CORE_COMMAND_HOST: edgex-core-command
248-
CLIENTS_CORE_DATA_HOST: edgex-core-data
249-
CLIENTS_CORE_METADATA_HOST: edgex-core-metadata
250-
CLIENTS_SUPPORT_NOTIFICATIONS_HOST: edgex-support-notifications
251-
CLIENTS_SUPPORT_SCHEDULER_HOST: edgex-support-scheduler
252-
DATABASES_PRIMARY_HOST: edgex-redis
253-
EDGEX_SECURITY_SECRET_STORE: "false"
254-
MESSAGEQUEUE_HOST: edgex-redis
255-
REGISTRY_HOST: edgex-core-consul
256-
SERVICE_HOST: edgex-device-gpio
257-
hostname: edgex-device-gpio
258-
image: edgexfoundry/device-gpio:0.0.0-dev
259-
networks:
260-
edgex-network: {}
261-
ports:
262-
- 59910:59910/tcp
263-
read_only: false
264-
privileged: true
265-
volumes:
266-
- "/sys:/sys"
267-
- "/dev:/dev"
268-
security_opt:
269-
- no-new-privileges:false
270-
user: root:root
271-
...
272-
```
273-
274-
275-
276-
## API Reference
277-
278-
- `device-custom-gpio-profile.yaml`
279-
280-
| Core Command | Method | parameters | Description | Response |
281-
| ------------ | ------ | ----------------- | ------------------------------------------------------------ | -------- |
282-
| Power | put | {"Power":<value>} | Set value for the specified gpio<br/><value>: bool, "true" or "false" | 200 ok |
283-
| | get | | Get value of the specified gpio<br/>valueType: Bool | "true" |
284-
285-
286-
28753
## License
28854
[Apache-2.0](LICENSE)
28955

0 commit comments

Comments
 (0)