Skip to content

Instantly share code, notes, and snippets.

@gguuss
Last active June 18, 2019 00:37
Show Gist options
  • Select an option

  • Save gguuss/5ea9ab15c9d2daee4ce2fe1730dd111b to your computer and use it in GitHub Desktop.

Select an option

Save gguuss/5ea9ab15c9d2daee4ce2fe1730dd111b to your computer and use it in GitHub Desktop.
List devices using Advanced Google Services
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