Working example of a Java program that allows activating an actuator of an IoT device configured to the https://iot.bluerange.io server.
The program is implemented by Main.java. All calls to the REST API of the BlueRange server are done using a Java client generated by the OpenAPI Code Generator.
After cloning, run the initial code generation of client from openapi.json file:
$ ./gradlew openApiGenerate
Configuration on demand is an incubating feature.
> Configure project :client
# ...
> Task :openApiGenerate
# ...
Successfully generated code to task ':openApiGenerate' property 'outputDir'
BUILD SUCCESSFUL in 58s
1 actionable task: 1 executed
Once the code was generated to the local client folder, to compile and test the program:
$ ./gradlew check
Configuration on demand is an incubating feature.
> Configure project :client
# ...
BUILD SUCCESSFUL in 24s
7 actionable tasks: 7 executed
To run the software an access token needs to be provided in environment variable BLUERANGE_USER_ACCESS_TOKEN
. The access token can be created using the profile page of the BlueRange server portal as outlined at https://www.bluerange.io/docs/bluerange-development/ApiAuthentication.html#CreateUseAccessToken. E.g. to set the (invalid) token value abcdefghijklmnop
as environment variable:
$ export BLUERANGE_USER_ACCESS_TOKEN=abcdefghijklmnop
To action an actuator pass the device serial number, the actuator type name and the value desired as arguments. This can be done using gradle, e.g. to write out a 1
value to the TURN_ON
actuator of the BXV94
device do:
$ ./gradlew :sample:run --args "BXV94 TURN_ON 1"
Configuration on demand is an incubating feature.
> Configure project :sample
# ...
> Configure project :client
# ...
> Task :sample:run
Okt. 06, 2021 11:19:38 VORM. Main traceResponse
INFORMATION: GET https://iot.bluerange.io/api/v1/devices?filter=%7B%22operation%22%3A%22AND%22%2C%22filters%22%3A%5B%7B%22fieldName%22%3A%22status%22%2C%22values%22%3A%5B%22COMPLIANT%22%2C%22INACTIVE%22%2C%22NONCOMPLIANT%22%5D%2C%22type%22%3A%22stringEnum%22%7D%2C%7B%22fieldName%22%3A%22deviceId%22%2C%22values%22%3A%5B%22BXV94%22%5D%2C%22type%22%3A%22stringEnum%22%7D%5D%2C%22type%22%3A%22logOp%22%7D&getItems=true&getNonpagedCount=false: 200
Okt. 06, 2021 11:19:39 VORM. Main main
INFORMATION: Device ConnectMe Test (39481C1C-11E9-471E-AC60-6B87ADE54BC0/BXV94)
Okt. 06, 2021 11:19:39 VORM. Main main
INFORMATION: Actuator body payload: {"deviceUuids":["39481C1C-11E9-471E-AC60-6B87ADE54BC0"],"type":"TURN_ON","index":0,"value":1}
Okt. 06, 2021 11:19:39 VORM. Main traceResponse
INFORMATION: POST https://iot.bluerange.io/api/v1/iot/actuator/actuatorData/action: 204
BUILD SUCCESSFUL in 2s
4 actionable tasks: 1 executed, 3 up-to-date