Java Code Examples for org.eclipse.californium.core.CoapClient#shutdown()
The following examples show how to use
org.eclipse.californium.core.CoapClient#shutdown() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Main.java From TRADFRI2MQTT with Apache License 2.0 | 6 votes |
private void set(String uriString, String payload) { //System.out.println("payload\n" + payload); try { URI uri = new URI(uriString); CoapClient client = new CoapClient(uri); client.setEndpoint(endPoint); CoapResponse response = client.put(payload, MediaTypeRegistry.TEXT_PLAIN); if (response != null && response.isSuccess()) { //System.out.println("Yay"); } else { System.out.println("Sending payload to " + uriString + " failed!"); } client.shutdown(); } catch (URISyntaxException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
Example 2
Source File: ManagerTradfri.java From helloiot with GNU General Public License v3.0 | 6 votes |
String requestPostCOAP(String topic, String payload) throws TradfriException { LOGGER.log(Level.FINE, "request POST COAP: {0}, {1}", new Object[]{topic, payload}); try { URI uri = new URI("coaps://" + coapIP + "/" + topic); CoapClient client = new CoapClient(uri); client.setEndpoint(coapEndPoint); CoapResponse response = client.post(payload, MediaTypeRegistry.TEXT_PLAIN); if (response == null || !response.isSuccess()) { LOGGER.log(Level.WARNING, "COAP GET error: Response error."); throw new TradfriException("Connection to gateway failed. Check host and PSK."); } String result = response.getResponseText(); client.shutdown(); return result; } catch (URISyntaxException ex) { LOGGER.log(Level.WARNING, "COAP GET error: {0}", ex.getMessage()); throw new TradfriException(ex); } }
Example 3
Source File: ManagerTradfri.java From helloiot with GNU General Public License v3.0 | 6 votes |
String requestGetCOAP(String topic) throws TradfriException { LOGGER.log(Level.FINE, "requext GET COAP: {0}", new Object[]{topic}); try { URI uri = new URI("coaps://" + coapIP + "/" + topic); CoapClient client = new CoapClient(uri); client.setEndpoint(coapEndPoint); CoapResponse response = client.get(); if (response == null || !response.isSuccess()) { LOGGER.log(Level.WARNING, "COAP GET error: Response error."); throw new TradfriException("Connection to gateway failed. Check host and PSK."); } String result = response.getResponseText(); client.shutdown(); return result; } catch (URISyntaxException ex) { LOGGER.log(Level.WARNING, "COAP GET error: {0}", ex.getMessage()); throw new TradfriException(ex); } }
Example 4
Source File: TradfriGateway.java From ThingML-Tradfri with Apache License 2.0 | 5 votes |
protected void set(String path, String payload) { Logger.getLogger(TradfriGateway.class.getName()).log(Level.INFO, "SET: " + "coaps://" + gateway_ip + "/" + path + " = " + payload); CoapClient client = new CoapClient("coaps://" + gateway_ip + "/" + path); client.setEndpoint(coap); CoapResponse response = client.put(payload, MediaTypeRegistry.TEXT_PLAIN); if (response != null && response.isSuccess()) { //System.out.println("Yay"); } else { logger.log(Level.SEVERE, "Sending payload to " + "coaps://" + gateway_ip + "/" + path + " failed!"); } client.shutdown(); }
Example 5
Source File: ManagerTradfri.java From helloiot with GNU General Public License v3.0 | 5 votes |
void requestPutCOAP(String topic, String payload) { LOGGER.log(Level.FINE, "requext PUT COAP: {0}, {1}", new Object[]{topic, payload}); try { URI uri = new URI("coaps://" + coapIP + "/" + topic); CoapClient client = new CoapClient(uri); client.setEndpoint(coapEndPoint); CoapResponse response = client.put(payload, MediaTypeRegistry.TEXT_PLAIN); if (response == null || !response.isSuccess()) { LOGGER.log(Level.WARNING, "COAP PUT error: {0}", response.getResponseText()); } client.shutdown(); } catch (URISyntaxException ex) { LOGGER.log(Level.WARNING, "COAP PUT error: {0}", ex.getMessage()); } }