@Override public MqttParameters extractDeliveryParameters(IDeviceNestingContext nesting, IDeviceAssignment assignment, IDeviceCommandExecution execution) throws SiteWhereException { MqttParameters params = new MqttParameters(); String commandTopic = String.format(getCommandTopicExpr(), nesting.getGateway().getHardwareId()); params.setCommandTopic(commandTopic); String systemTopic = String.format(getSystemTopicExpr(), nesting.getGateway().getHardwareId()); params.setSystemTopic(systemTopic); return params; }
execution.getInvocation().getId()); if (nested.getNested() != null) { LOGGER.debug("Targeting nested device with specification: " + nested.getNested().getSpecificationToken() + " at path " + nested.getPath()); headBuilder.setField(header.findFieldByName(ProtobufNaming.HEADER_NESTED_PATH_FIELD_NAME), nested.getPath()); headBuilder.setField(header.findFieldByName(ProtobufNaming.HEADER_NESTED_SPEC_FIELD_NAME), nested.getNested().getSpecificationToken());
execution.getInvocation().getId().toString()); if (nested.getNested() != null) { IDeviceType nestedType = deviceManagement.getDeviceType(nested.getNested().getDeviceTypeId()); LOGGER.debug( "Targeting nested device with type: " + nestedType.getName() + " at path " + nested.getPath()); headBuilder.setField(header.findFieldByName(ProtobufNaming.HEADER_NESTED_PATH_FIELD_NAME), nested.getPath()); headBuilder.setField(header.findFieldByName(ProtobufNaming.HEADER_NESTED_TYPE_FIELD_NAME), nestedType.getToken());
@Override public SmsParameters extractDeliveryParameters(IDeviceNestingContext nesting, IDeviceAssignment assignment, IDeviceCommandExecution execution) throws SiteWhereException { SmsParameters params = new SmsParameters(); // Load hostname and port from device metadata. Map<String, String> deviceMeta = nesting.getGateway().getMetadata(); String phone = deviceMeta.get(getPhoneNumberMetadataField()); params.setSmsPhoneNumber(phone); if (phone == null) { throw new SiteWhereException("No phone number found in device metadata. Unable to deliver."); } return params; }
@Override public CoapParameters extractDeliveryParameters(IDeviceNestingContext nesting, IDeviceAssignment assignment, IDeviceCommandExecution execution) throws SiteWhereException { Map<String, String> metadata = nesting.getGateway().getMetadata(); String hostname = metadata.get(getHostnameMetadataField()); String port = metadata.get(getPortMetadataField()); String url = metadata.get(getUrlMetadataField()); String method = metadata.get(getMethodMetadataField()); CoapParameters coap = new CoapParameters(); coap.setHostname(hostname); if (port != null) { coap.setPort(Integer.parseInt(port)); } if (url != null) { coap.setUrl(url); } if (method != null) { coap.setMethod(method); } return coap; }
@Override public MqttParameters extractDeliveryParameters(IDeviceNestingContext nesting, IDeviceAssignment assignment, IDeviceCommandExecution execution) throws SiteWhereException { MqttParameters params = new MqttParameters(); Map<String, String> values = new HashMap<>(); values.put("tenant", getTenantEngine().getTenant().getToken()); values.put("device", nesting.getGateway().getToken()); values.put("assignment", assignment.getToken()); String commandTopic = StrSubstitutor.replace(getCommandTopicExpr(), values); params.setCommandTopic(commandTopic); String systemTopic = StrSubstitutor.replace(getSystemTopicExpr(), values); params.setSystemTopic(systemTopic); return params; }
/** * Get {@link ICommandDestination} for device based on specification token * associated with the device. * * @param nesting * @return * @throws SiteWhereException */ protected ICommandDestination<?, ?> getDestinationForDevice(IDeviceNestingContext nesting) throws SiteWhereException { String specToken = nesting.getGateway().getSpecificationToken(); String destinationId = mappings.get(specToken); if (destinationId == null) { if (getDefaultDestination() != null) { destinationId = getDefaultDestination(); } else { throw new SiteWhereException("No command destination mapping for specification: " + specToken); } } ICommandDestination<?, ?> destination = getDestinations().get(destinationId); if (destination == null) { throw new SiteWhereException("No destination found for destination id: " + destinationId); } return destination; }
/** * Get {@link ICommandDestination} for device based on specification token * associated with the device. * * @param nesting * @return * @throws SiteWhereException */ protected ICommandDestination<?, ?> getDestinationForDevice(IDeviceNestingContext nesting) throws SiteWhereException { UUID deviceTypeId = nesting.getGateway().getDeviceTypeId(); String destinationId = mappings.get(deviceTypeId); if (destinationId == null) { if (getDefaultDestination() != null) { destinationId = getDefaultDestination(); } else { throw new SiteWhereException("No command destination mapping for device type: " + deviceTypeId); } } ICommandDestination<?, ?> destination = getCommandDestinationsManager().getCommandDestinations() .get(destinationId); if (destination == null) { throw new SiteWhereException("No destination found for destination id: " + destinationId); } return destination; }
@Override public CoapParameters extractDeliveryParameters(IDeviceNestingContext nesting, IDeviceAssignment assignment, IDeviceCommandExecution execution) throws SiteWhereException { // Load hostname and port from device metadata. Map<String, String> deviceMeta = nesting.getGateway().getMetadata(); String hostname = deviceMeta.get(getHostnameMetadataField()); String port = deviceMeta.get(getPortMetadataField()); // Load url and method from command metadata. Map<String, String> commandMeta = execution.getCommand().getMetadata(); String url = commandMeta.get(getUrlMetadataField()); String method = commandMeta.get(getMethodMetadataField()); CoapParameters coap = new CoapParameters(); coap.setHostname(hostname); if (hostname == null) { throw new SiteWhereException("Hostname not found in device metadata. Unable to deliver command."); } if (port != null) { coap.setPort(Integer.parseInt(port)); } if (url != null) { coap.setUrl(url); } if (method != null) { coap.setMethod(method); } return coap; }