Last active
June 18, 2019 00:37
-
-
Save gguuss/5ea9ab15c9d2daee4ce2fe1730dd111b to your computer and use it in GitHub Desktop.
List devices using Advanced Google Services
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function listDeviceStatesForRegistry() { | |
| var cloudRegion = 'us-central1'; | |
| var name = 'your-registry-name'; | |
| var projectId = 'your-project-id'; | |
| var parent = 'projects/' + projectId + '/locations/' + cloudRegion; | |
| var registryName = parent + '/registries/' + name; | |
| var response = CloudIoT.Projects.Locations.Registries.Devices.list(registryName); | |
| if (response.devices) { | |
| response.devices.forEach( | |
| function(device){ | |
| var deviceName = registryName + '/devices/' + device.id; | |
| var states = CloudIoT.Projects.Locations.Registries.Devices.States.list(deviceName); | |
| var data = ''; | |
| if (states && states.deviceStates) { | |
| states.deviceStates.forEach(function(state) { | |
| state.binaryData.forEach(function(value) { | |
| data += String.fromCharCode(value); | |
| }); | |
| data += '||'; | |
| }); | |
| } | |
| console.log(data); | |
| }); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment