Exemplo n.º 1
0
    iotAgentLib.getDevice(deviceId, group.service, group.subservice, function(error, device) {
        if (!error && device) {
            callback(null, device, group);
        } else if (error.name === 'DEVICE_NOT_FOUND') {
            var newDevice = {
                id: deviceId,
                service: group.service,
                subservice: group.subservice,
                type: group.type
            };

            if (
                config.getConfig().iota &&
                config.getConfig().iota.iotManager &&
                config.getConfig().iota.iotManager.protocol
            ) {
                newDevice.protocol = config.getConfig().iota.iotManager.protocol;
            }

            // Fix transport depending on binding
            if (!newDevice.transport) {
                newDevice.transport = transport;
            }

            if ('timestamp' in group) {
                newDevice.timestamp = group.timestamp;
            }

            iotAgentLib.register(newDevice, function(error, device) {
                callback(error, device, group);
            });
        } else {
            callback(error);
        }
    });
Exemplo n.º 2
0
    iotAgentLib.getDevice(deviceId, group.service, group.subservice, function(error, device) {
        if (!error && device) {
            callback(null, device, group);
        } else if (error.name === 'DEVICE_NOT_FOUND') {
            var newDevice = {
                id: deviceId,
                service: group.service,
                subservice: group.subservice,
                type: group.type
            };

            if (config.getConfig().iota && config.getConfig().iota.iotManager &&
                config.getConfig().iota.iotManager.protocol) {
                newDevice.protocol = config.getConfig().iota.iotManager.protocol;
            }

            iotAgentLib.register(newDevice, function(error, device) {
                callback(error, device, group);
            });
        } else {
            callback(error);
        }
    });