org.eclipse.californium.core.CoapHandler Java Examples
The following examples show how to use
org.eclipse.californium.core.CoapHandler.
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: AuavRoutines.java From SoftwarePilot with MIT License | 6 votes |
public String invokeHostDriver(String command, String IP, CoapHandler ch, boolean gov){ if(gov) { try { //System.out.println("URI = "+IP+":"+portStr); URI uri = new URI("coap://"+IP+":5117/cr"); CoapClient client = new CoapClient(uri); client.setTimeout(TIMEOUT); client.put(ch,command,TEXT_PLAIN); return("Success"); //return(response.getResponseText()); } catch (Exception e) { return("Unable to reach driver host"); } } return "InvokeDriver with Governor Executed"; }
Example #2
Source File: CoapTestBase.java From hono with Eclipse Public License 2.0 | 6 votes |
/** * Triggers the establishment of a downstream sender * for a tenant so that subsequent messages will be * more likely to be forwarded. * * @param client The CoAP client to use for sending the request. * @param request The request to send. * @return A succeeded future. */ protected final Future<Void> warmUp(final CoapClient client, final Request request) { logger.debug("sending request to trigger CoAP adapter's downstream message sender"); final Promise<Void> result = Promise.promise(); client.advanced(new CoapHandler() { @Override public void onLoad(final CoapResponse response) { waitForWarmUp(); } @Override public void onError() { waitForWarmUp(); } private void waitForWarmUp() { VERTX.setTimer(1000, tid -> result.complete()); } }, request); return result.future(); }
Example #3
Source File: CoapTestBase.java From hono with Eclipse Public License 2.0 | 6 votes |
/** * Gets a handler for CoAP responses. * * @param responseHandler The handler to invoke with the outcome of the request. the handler will be invoked with a * succeeded result if the response contains the expected code. Otherwise it will be invoked with a * result that is failed with a {@link CoapResultException}. * @param expectedStatusCode The status code that is expected in the response. * @return The handler. */ protected final CoapHandler getHandler(final Handler<AsyncResult<OptionSet>> responseHandler, final ResponseCode expectedStatusCode) { return new CoapHandler() { @Override public void onLoad(final CoapResponse response) { if (response.getCode() == expectedStatusCode) { logger.debug("=> received {}", Utils.prettyPrint(response)); responseHandler.handle(Future.succeededFuture(response.getOptions())); } else { logger.warn("expected {} => received {}", expectedStatusCode, Utils.prettyPrint(response)); responseHandler.handle(Future.failedFuture( new CoapResultException(toHttpStatusCode(response.getCode()), response.getResponseText()))); } } @Override public void onError() { responseHandler .handle(Future.failedFuture(new CoapResultException(HttpURLConnection.HTTP_UNAVAILABLE))); } }; }
Example #4
Source File: ManagerTradfri.java From helloiot with GNU General Public License v3.0 | 6 votes |
private CoapObserveRelation subscribeCOAP(String topic) throws TradfriException { try { URI uri = new URI("coaps://" + coapIP + "/" + topic); CoapClient client = new CoapClient(uri); client.setEndpoint(coapEndPoint); CoapHandler handler = new CoapHandler() { @Override public void onLoad(CoapResponse response) { receivedCOAP(topic, response.getResponseText()); } @Override public void onError() { LOGGER.log(Level.WARNING, "COAP subscription error"); } }; return client.observe(handler); } catch (URISyntaxException ex) { LOGGER.log(Level.WARNING, "COAP SEND error: {0}", ex.getMessage()); throw new TradfriException(ex); } }
Example #5
Source File: AuavRoutines.java From SoftwarePilot with MIT License | 5 votes |
AUAVHandler () { ch = new CoapHandler() { @Override public void onLoad(CoapResponse response) { resp = response.getResponseText(); auavLock("continue"); } @Override public void onError() { resp = "CoapHandler Error"; System.out.println("RoutineLock: " +auavLock+"-FAILED"); auavLock("continue"); }}; }
Example #6
Source File: CaptureImageV2Driver.java From SoftwarePilot with MIT License | 5 votes |
public String invokeDriver(String dn, String params, CoapHandler ch) { params = params + "-dp=" + "AUAVsim"; if(this.d2p == null) { try { URI portStr = new URI("coap://127.0.0.1:5117/cr"); CoapClient e = new CoapClient(portStr); CoapResponse client = e.put("dn=list", 0); String ls = client.getResponseText(); this.d2p = new HashMap(); String[] lines = ls.split("\n"); for(int x = 0; x < lines.length; ++x) { String[] data = lines[x].split("-->"); if(data.length == 2) { this.d2p.put(data[0].trim(), data[1].trim()); } } } catch (Exception var12) { this.d2p = null; System.out.println("AUAVRoutine invokeDriver error"); var12.printStackTrace(); return "Invoke Error"; } } if(this.d2p != null) { String var13 = (String)this.d2p.get(dn); if(var13 != null) { try { URI var14 = new URI("coap://127.0.0.1:" + var13 + "/cr"); CoapClient var15 = new CoapClient(var14); var15.put(ch, params, 0); return "Success"; } catch (Exception var11) { return "Unable to reach driver " + dn + " at port: " + var13; } } else { return "Unable to find driver: " + dn; } } else { return "InvokeDriver: Unreachable code touched"; } }
Example #7
Source File: CoapTestBase.java From hono with Eclipse Public License 2.0 | 2 votes |
/** * Gets a handler for CoAP responses. * * @param responseHandler The handler to invoke with the outcome of the request. the handler will be invoked with a * succeeded result if the response contains a 2.04 (Changed) code. Otherwise it will be invoked with a * result that is failed with a {@link CoapResultException}. * @return The handler. */ protected final CoapHandler getHandler(final Handler<AsyncResult<OptionSet>> responseHandler) { return getHandler(responseHandler, ResponseCode.CHANGED); }