@Test public void testRegisterDevice() throws Exception { CoapClient client = createClientFor(getBaseDeviceUrl()); DeviceRegistrationRequest registration = new DeviceRegistrationRequest(); registration.setDeviceTypeToken("mega2560"); registration.setAreaToken("peachtree"); Map<String, String> metadata = new HashMap<String, String>(); metadata.put("ipaddress", "localhost"); registration.setMetadata(metadata); handleResponse(client.post(MarshalUtils.marshalJson(registration), MediaTypeRegistry.APPLICATION_JSON)); }
/** * Generate a device request containing a device registration request. * * @param deviceToken * @return * @throws SiteWhereException */ public static DeviceRequest generateRegistrationRequest(String deviceToken) throws SiteWhereException { DeviceRequest request = new DeviceRequest(); request.setDeviceToken(deviceToken); request.setType(Type.RegisterDevice); DeviceRegistrationRequest mx = new DeviceRegistrationRequest(); mx.setDeviceTypeToken("mega2560"); mx.setAreaToken("peachtree"); request.setRequest(mx); return request; } }
/** * Convert device registration request from GRPC to API. * * @param grpc * @return * @throws SiteWhereException */ public static DeviceRegistrationRequest asApiDeviceRegistrationRequest(GDeviceRegistrationRequest grpc) throws SiteWhereException { DeviceRegistrationRequest api = new DeviceRegistrationRequest(); api.setToken(grpc.hasToken() ? grpc.getToken().getValue() : null); api.setParentDeviceToken(grpc.hasParentDeviceToken() ? grpc.getParentDeviceToken().getValue() : null); api.setDeviceTypeToken(grpc.hasDeviceTypeToken() ? grpc.getDeviceTypeToken().getValue() : null); api.setStatus(grpc.hasStatus() ? grpc.getStatus().getValue() : null); api.setComments(grpc.hasComments() ? grpc.getComments().getValue() : null); api.setDeviceElementMappings( DeviceModelConverter.asApiDeviceElementMappings(grpc.getDeviceElementMappingsList())); api.setMetadata(grpc.getMetadataMap()); api.setCustomerToken(grpc.hasCustomerToken() ? grpc.getCustomerToken().getValue() : null); api.setAreaToken(grpc.hasAreaToken() ? grpc.getAreaToken().getValue() : null); return api; }
request.setDeviceTypeToken(registration.getDeviceTypeToken().getValue()); if (registration.hasAreaToken()) { request.setAreaToken(registration.getAreaToken().getValue());