Reading a GPIO value via the REST API sets its value back to 0 / false.
$ git describe
v2.0.0-dev.2
$ make build
CGO_ENABLED=1 GO111MODULE=on go build -ldflags "-X github.com/edgexfoundry/device-gpio.Version=0.0.0" -o cmd/device-gpio ./cmd
$ mkdir -p /tmp/edgex/secrets/device-gpio/
$ sudo cp /var/snap/edgexfoundry/current/secrets/device-gpio/secrets-token.json /tmp/edgex/secrets/device-gpio/
$ cd cmd
$ sudo ./device-gpio
level=INFO ts=2022-04-01T18:06:50.139803754Z app=device-gpio source=config.go:373 msg="Loaded service configuration from ./res/configuration.toml"
level=INFO ts=2022-04-01T18:06:50.141508792Z app=device-gpio source=secret.go:52 msg="Creating SecretClient"
level=INFO ts=2022-04-01T18:06:50.141571774Z app=device-gpio source=secret.go:59 msg="Reading secret store configuration and authentication token"
level=INFO ts=2022-04-01T18:06:50.141904963Z app=device-gpio source=secret.go:71 msg="Attempting to create secret client"
level=INFO ts=2022-04-01T18:06:50.147615104Z app=device-gpio source=secret.go:76 msg="Created SecretClient"
level=INFO ts=2022-04-01T18:06:50.147725216Z app=device-gpio source=secret.go:81 msg="SecretsFile not set, skipping seeding of service secrets."
level=INFO ts=2022-04-01T18:06:50.147811013Z app=device-gpio source=config.go:510 msg="Using local configuration from file (0 envVars overrides applied)"
level=INFO ts=2022-04-01T18:06:50.147825477Z app=device-gpio source=secrets.go:276 msg="kick off token renewal with interval: 30m0s"
level=INFO ts=2022-04-01T18:06:50.14793533Z app=device-gpio source=httpserver.go:123 msg="Web server starting (localhost:59910)"
level=INFO ts=2022-04-01T18:06:50.148023034Z app=device-gpio source=messaging.go:69 msg="Setting options for secure MessageBus with AuthMode='usernamepassword' and SecretName='redisdb"
level=INFO ts=2022-04-01T18:06:50.152073193Z app=device-gpio source=messaging.go:99 msg="Connected to redis Message Bus @ redis://localhost:6379 publishing on 'edgex/events/device' prefix topic with AuthMode='usernamepassword'"
level=INFO ts=2022-04-01T18:06:50.152349529Z app=device-gpio source=init.go:137 msg="Check core-metadata service's status by ping..."
level=INFO ts=2022-04-01T18:06:50.156037757Z app=device-gpio source=init.go:56 msg="Service clients initialize successful."
level=INFO ts=2022-04-01T18:06:50.156159721Z app=device-gpio source=restrouter.go:47 msg="Registering v2 routes..."
level=INFO ts=2022-04-01T18:06:50.164477929Z app=device-gpio source=driver.go:53 msg="Interface: sysfs"
level=INFO ts=2022-04-01T18:06:50.164634764Z app=device-gpio source=driver.go:54 msg="ChipSelected: 0"
level=INFO ts=2022-04-01T18:06:50.166401674Z app=device-gpio source=service.go:216 msg="device service device-gpio exists, updating it"
level=INFO ts=2022-04-01T18:06:50.170177606Z app=device-gpio source=profiles.go:54 msg="Loading pre-defined profiles from /home/ubuntu/device-gpio/cmd/res/profiles"
level=INFO ts=2022-04-01T18:06:50.173670721Z app=device-gpio source=profiles.go:88 msg="Profile Custom-GPIO-Device exists, using the existing one"
level=INFO ts=2022-04-01T18:06:50.174023836Z app=device-gpio source=devices.go:49 msg="Loading pre-defined devices from /home/ubuntu/device-gpio/cmd/res/devices"
level=INFO ts=2022-04-01T18:06:50.17451486Z app=device-gpio source=devices.go:85 msg="Device GPIO-Device01 exists, using the existing one"
level=INFO ts=2022-04-01T18:06:50.174593861Z app=device-gpio source=autodiscovery.go:33 msg="AutoDiscovery stopped: disabled by configuration"
level=INFO ts=2022-04-01T18:06:50.174647806Z app=device-gpio source=autodiscovery.go:42 msg="AutoDiscovery stopped: ProtocolDiscovery not implemented"
level=INFO ts=2022-04-01T18:06:50.174697492Z app=device-gpio source=message.go:50 msg="Service dependencies resolved..."
level=INFO ts=2022-04-01T18:06:50.174854438Z app=device-gpio source=message.go:51 msg="Starting device-gpio 0.0.0 "
level=INFO ts=2022-04-01T18:06:50.174906569Z app=device-gpio source=message.go:55 msg="device gpio started"
level=INFO ts=2022-04-01T18:06:50.174955217Z app=device-gpio source=message.go:58 msg="Service started in: 36.751223ms"
level=INFO ts=2022-04-01T18:07:14.896777783Z app=device-gpio source=driver.go:61 msg="protocols: map[other:map[Address:device-custom-gpio-01 Port:300]] resource: Power attributes: map[line:17]"
level=INFO ts=2022-04-01T18:07:22.470707344Z app=device-gpio source=driver.go:95 msg="Driver.HandleWriteCommands: protocols: map[other:map[Address:device-custom-gpio-01 Port:300]], resource: Power, attribute: map[line:17], parameters: [DeviceResource: Power, Bool: true]"
level=INFO ts=2022-04-01T18:07:28.820634334Z app=device-gpio source=driver.go:61 msg="protocols: map[other:map[Address:device-custom-gpio-01 Port:300]] resource: Power attributes: map[line:17]"
$ cat /sys/class/gpio/gpio17/value
cat: /sys/class/gpio/gpio17/value: No such file or directory
# Read the GPIO via core-command
$ curl http://localhost:59882/api/v2/device/name/GPIO-Device01/Power
{"apiVersion":"v2","statusCode":200,"event":{"apiVersion":"v2","id":"83637eca-5c4c-4046-852b-08cc90850c63","deviceName":"GPIO-Device01","profileName":"Custom-GPIO-Device","sourceName":"Power","origin":1648836435898034344,"readings":[{"id":"d28e2bb8-ee36-4703-8be7-207bdb479b38","origin":1648836435898034344,"deviceName":"GPIO-Device01","resourceName":"Power","profileName":"Custom-GPIO-Device","valueType":"Bool","value":"false"}]}}
# File is created and GPIO value is 0
$ cat /sys/class/gpio/gpio17/value
0
# Set to true
$ curl -X PUT -d '{"Power":"true"}' http://localhost:59882/api/v2/device/name/GPIO-Device01/Power
{"apiVersion":"v2","statusCode":200}
# GPIO value is changed to 1
ubuntu@mars:~$ cat /sys/class/gpio/gpio17/value
1
# core-command reads 0
$ curl http://localhost:59882/api/v2/device/name/GPIO-Device01/Power
{"apiVersion":"v2","statusCode":200,"event":{"apiVersion":"v2","id":"ffbc04ee-0a88-4a18-b260-3fa933ed7f4e","deviceName":"GPIO-Device01","profileName":"Custom-GPIO-Device","sourceName":"Power","origin":1648836448821058616,"readings":[{"id":"e78de76f-4c98-45c0-bad8-a18748eae83a","origin":1648836448821058616,"deviceName":"GPIO-Device01","resourceName":"Power","profileName":"Custom-GPIO-Device","valueType":"Bool","value":"false"}]}}
# GPIO value is set to 0
$ cat /sys/class/gpio/gpio17/value
0