You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- 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:
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.
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
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.
0 commit comments