_commandSubscriptionCallback(err, granted) { if (err == null) { for (var index in granted) { let grant = granted[index]; this.log.debug("[DeviceClient:connect] Subscribed to device commands on " + grant.topic + " at QoS " + grant.qos); } } else { this.log.error("[DeviceClient:connect] Unable to establish subscription for device commands: " + err); this.emit("error", new Error("Unable to establish subscription for device commands: " + err)); } }
publishEvent(eventId, format, data, qos, callback){ qos = qos || 0; if (!isDefined(eventId) || !isDefined(format)) { this.log.error("[DeviceClient:publishEvent] Required params for publishEvent not present"); this.emit('error', "[DeviceClient:publishEvent] Required params for publishEvent not present"); return; } let topic = util.format("iot-2/evt/%s/fmt/%s", eventId, format); this._publish(topic, data, qos, callback); return this; }
addEventError(data) { log.error('addEventError called. data=', data); }
const sendError = (res, httpCode, data) => { let content = { message: '', code: -1 }; log.error(data); if (typeof data === 'object') { content.message = data.message || JSON.stringify(data); content.code = data.code || -1; } else if (typeof data === 'string') { content.message = data; } res.status(httpCode).send(content); }
// ========================================================================== // Device Commands // ========================================================================== publishCommand(typeId, deviceId, commandId, format, data, qos, callback) { qos = qos || 0; if (!isDefined(typeId) || !isDefined(deviceId) || !isDefined(commandId) || !isDefined(format)) { this.log.error("[ApplicationClient:publishDeviceCommand] Required params for publishDeviceCommand not present"); this.emit('error', "[ApplicationClient:publishDeviceCommand] Required params for publishDeviceCommand not present"); return; } var topic = "iot-2/type/" + typeId + "/id/" + deviceId + "/cmd/" + commandId + "/fmt/" + format; this._publish(topic, data, qos, callback); return this; }
this.log.error("[BaseClient:onError] " + error); this.log.error("[BaseClient:onError] One or more configuration parameters are wrong. Modify the configuration before trying to reconnect."); this.mqtt.end(false, () => { this.log.info("[BaseClient:onError] Closed the MQTT connection due to client misconfiguration");
log.info(c.gray('[*]') + ` logging CSV data to ${args.logfile}`) } catch (err) { log.error(c.red('[!]') + ` error writing to --logfile ${args.logfile}:`) log.error(err) log.error(c.red('[!]') + ' exiting.') process.exit(1) log.error(c.red('[!]') + ` error writing to ${args.logfile}`) log.error(err) log.error(c.red('[!]') + ' native-dns server error:') log.error(err.stack) }) let m = c.red('[!]') m += ` Fatal error binding to port ${args.port}, address in use.` log.error(m)
// ========================================================================== // Device Events // ========================================================================== publishEvent(typeId, deviceId, eventId, format, data, qos, callback) { qos = qos || 0; if (!isDefined(typeId) || !isDefined(deviceId) || !isDefined(eventId) || !isDefined(format)) { this.log.error("[ApplicationClient:publishDeviceEvent] Required params for publishDeviceEvent not present"); this.emit('error', "[ApplicationClient:publishDeviceEvent] Required params for publishDeviceEvent not present"); return; } var topic = "iot-2/type/" + typeId + "/id/" + deviceId + "/evt/" + eventId + "/fmt/" + format; this._publish(topic, data, qos, callback); return this; }
getEventsError(data) { log.error('getEventsError called. data=', data); }