2 * Copyright (c) 2010-2024 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.shelly.internal.api1;
15 import static org.openhab.binding.shelly.internal.ShellyBindingConstants.*;
16 import static org.openhab.binding.shelly.internal.api1.Shelly1CoapJSonDTO.*;
17 import static org.openhab.binding.shelly.internal.util.ShellyUtils.*;
19 import java.net.SocketException;
20 import java.net.UnknownHostException;
21 import java.util.LinkedHashMap;
22 import java.util.List;
24 import java.util.TreeMap;
26 import org.eclipse.californium.core.CoapClient;
27 import org.eclipse.californium.core.coap.CoAP.Code;
28 import org.eclipse.californium.core.coap.CoAP.ResponseCode;
29 import org.eclipse.californium.core.coap.CoAP.Type;
30 import org.eclipse.californium.core.coap.MessageObserverAdapter;
31 import org.eclipse.californium.core.coap.Option;
32 import org.eclipse.californium.core.coap.OptionNumberRegistry;
33 import org.eclipse.californium.core.coap.Request;
34 import org.eclipse.californium.core.coap.Response;
35 import org.eclipse.californium.core.network.Endpoint;
36 import org.eclipse.jdt.annotation.NonNullByDefault;
37 import org.eclipse.jdt.annotation.Nullable;
38 import org.openhab.binding.shelly.internal.api.ShellyApiException;
39 import org.openhab.binding.shelly.internal.api.ShellyApiInterface;
40 import org.openhab.binding.shelly.internal.api.ShellyDeviceProfile;
41 import org.openhab.binding.shelly.internal.api1.Shelly1CoapJSonDTO.CoIotDescrBlk;
42 import org.openhab.binding.shelly.internal.api1.Shelly1CoapJSonDTO.CoIotDescrSen;
43 import org.openhab.binding.shelly.internal.api1.Shelly1CoapJSonDTO.CoIotDevDescrTypeAdapter;
44 import org.openhab.binding.shelly.internal.api1.Shelly1CoapJSonDTO.CoIotDevDescription;
45 import org.openhab.binding.shelly.internal.api1.Shelly1CoapJSonDTO.CoIotGenericSensorList;
46 import org.openhab.binding.shelly.internal.api1.Shelly1CoapJSonDTO.CoIotSensor;
47 import org.openhab.binding.shelly.internal.api1.Shelly1CoapJSonDTO.CoIotSensorTypeAdapter;
48 import org.openhab.binding.shelly.internal.config.ShellyThingConfiguration;
49 import org.openhab.binding.shelly.internal.handler.ShellyColorUtils;
50 import org.openhab.binding.shelly.internal.handler.ShellyThingInterface;
51 import org.openhab.core.library.unit.Units;
52 import org.openhab.core.thing.ThingStatusDetail;
53 import org.openhab.core.types.State;
54 import org.slf4j.Logger;
55 import org.slf4j.LoggerFactory;
57 import com.google.gson.Gson;
58 import com.google.gson.GsonBuilder;
59 import com.google.gson.JsonSyntaxException;
62 * The {@link Shelly1CoapHandler} handles the CoIoT/CoAP registration and events.
64 * @author Markus Michels - Initial contribution
67 public class Shelly1CoapHandler implements Shelly1CoapListener {
68 private static final byte[] EMPTY_BYTE = new byte[0];
70 private final Logger logger = LoggerFactory.getLogger(Shelly1CoapHandler.class);
71 private final ShellyThingInterface thingHandler;
72 private ShellyThingConfiguration config = new ShellyThingConfiguration();
73 private final GsonBuilder gsonBuilder = new GsonBuilder();
74 private final Gson gson;
75 private String thingName;
77 private boolean coiotBound = false;
78 private Shelly1CoIoTInterface coiot;
79 private int coiotVers = -1;
81 private final Shelly1CoapServer coapServer;
82 private @Nullable CoapClient statusClient;
83 private Request reqDescription = new Request(Code.GET, Type.CON);
84 private Request reqStatus = new Request(Code.GET, Type.CON);
85 private boolean updatesRequested = false;
86 private int coiotPort = COIOT_PORT;
88 private int lastSerial = -1;
89 private String lastPayload = "";
90 private Map<String, CoIotDescrBlk> blkMap = new LinkedHashMap<>();
91 private Map<String, CoIotDescrSen> sensorMap = new LinkedHashMap<>();
92 private ShellyDeviceProfile profile;
93 private ShellyApiInterface api;
95 public Shelly1CoapHandler(ShellyThingInterface thingHandler, Shelly1CoapServer coapServer) {
96 this.thingHandler = thingHandler;
97 this.thingName = thingHandler.getThingName();
98 this.profile = thingHandler.getProfile();
99 this.api = thingHandler.getApi();
100 this.coapServer = coapServer;
101 this.coiot = new Shelly1CoIoTVersion2(thingName, thingHandler, blkMap, sensorMap); // Default: V2
103 gsonBuilder.registerTypeAdapter(CoIotDevDescription.class, new CoIotDevDescrTypeAdapter());
104 gsonBuilder.registerTypeAdapter(CoIotGenericSensorList.class, new CoIotSensorTypeAdapter());
105 gson = gsonBuilder.create();
109 * Initialize CoAP access, send discovery packet and start Status server
111 * @param thingName Thing name derived from Thing Type/hostname
112 * @param config ShellyThingConfiguration
113 * @throws ShellyApiException
115 public synchronized void start(String thingName, ShellyThingConfiguration config) throws ShellyApiException {
117 this.thingName = thingName;
118 this.config = config;
119 this.profile = thingHandler.getProfile();
121 logger.trace("{}: CoAP Listener was already started", thingName);
125 logger.debug("{}: Starting CoAP Listener", thingName);
126 if (!profile.coiotEndpoint.isEmpty() && profile.coiotEndpoint.contains(":")) {
127 String ps = substringAfter(profile.coiotEndpoint, ":");
128 coiotPort = Integer.parseInt(ps);
130 coapServer.start(config.localIp, coiotPort, this);
131 statusClient = new CoapClient(completeUrl(config.deviceIp, coiotPort, COLOIT_URI_DEVSTATUS))
132 .setTimeout((long) SHELLY_API_TIMEOUT_MS).useNONs().setEndpoint(coapServer.getEndpoint());
134 Endpoint endpoint = null;
135 CoapClient client = statusClient;
136 if (client != null) {
137 endpoint = client.getEndpoint();
139 if ((endpoint == null) || !endpoint.isStarted()) {
140 logger.warn("{}: Unable to initialize CoAP access (network error)", thingName);
141 throw new ShellyApiException("Network initialization failed");
145 } catch (SocketException e) {
146 logger.warn("{}: Unable to initialize CoAP access (socket exception) - {}", thingName, e.getMessage());
147 throw new ShellyApiException("Network error", e);
148 } catch (UnknownHostException e) {
149 logger.info("{}: CoAP Exception (Unknown Host)", thingName, e);
150 throw new ShellyApiException("Unknown Host: " + config.deviceIp, e);
154 public boolean isStarted() {
155 return statusClient != null;
159 * Process an inbound Response (or mapped Request): decode CoAP options. handle discovery result or status updates
161 * @param response The Response packet
164 public void processResponse(@Nullable Response response) {
165 if (response == null) {
166 thingHandler.incProtErrors();
167 return; // other device instance
169 ResponseCode code = response.getCode();
170 if (code != ResponseCode.CONTENT) {
172 logger.debug("{}: Unknown Response Code {} received, payload={}", thingName, code,
173 response.getPayloadString());
174 thingHandler.incProtErrors();
178 List<Option> options = response.getOptions().asSortedList();
179 String ip = response.getSourceContext().getPeerAddress().toString();
180 boolean match = ip.contains("/" + config.deviceIp + ":");
182 // We can't identify device by IP, so we need to check the CoAP header's Global Device ID
183 for (Option opt : options) {
184 if (opt.getNumber() == COIOT_OPTION_GLOBAL_DEVID) {
185 String devid = opt.getStringValue();
186 if (devid.contains("#") && profile.device.mac != null) {
187 // Format: <device type>#<mac address>#<coap version>
188 String macid = substringBetween(devid, "#", "#");
189 if (getString(profile.device.mac).toUpperCase().contains(macid.toUpperCase())) {
207 thingHandler.incProtMessages();
208 if (logger.isDebugEnabled()) {
209 logger.debug("{}: CoIoT Message from {} (MID={}): {}", thingName,
210 response.getSourceContext().getPeerAddress(), response.getMID(), response.getPayloadString());
212 if (thingHandler.isStopping()) {
213 logger.debug("{}: Thing is shutting down, ignore CoIOT message", thingName);
217 if (response.isCanceled() || response.isDuplicate() || response.isRejected()) {
218 logger.debug("{} ({}): Packet was canceled, rejected or is a duplicate -> discard", thingName, devId);
219 thingHandler.incProtErrors();
223 payload = response.getPayloadString();
224 for (Option opt : options) {
225 switch (opt.getNumber()) {
226 case OptionNumberRegistry.URI_PATH:
227 uri = COLOIT_URI_BASE + opt.getStringValue();
229 case OptionNumberRegistry.URI_HOST: // ignore
231 case OptionNumberRegistry.CONTENT_FORMAT: // ignore
233 case COIOT_OPTION_GLOBAL_DEVID:
234 devId = opt.getStringValue();
235 String sVersion = substringAfterLast(devId, "#");
236 int iVersion = Integer.parseInt(sVersion);
237 if (coiotBound && (coiotVers != iVersion)) {
238 logger.debug("{}: CoIoT versopm has changed from {} to {}, maybe the firmware was upgraded",
239 thingName, coiotVers, iVersion);
240 thingHandler.reinitializeThing();
244 thingHandler.updateProperties(PROPERTY_COAP_VERSION, sVersion);
245 logger.debug("{}: CoIoT Version {} detected", thingName, iVersion);
246 if (iVersion == COIOT_VERSION_1) {
247 coiot = new Shelly1CoIoTVersion1(thingName, thingHandler, blkMap, sensorMap);
248 } else if (iVersion == COIOT_VERSION_2) {
249 coiot = new Shelly1CoIoTVersion2(thingName, thingHandler, blkMap, sensorMap);
251 logger.warn("{}: Unsupported CoAP version detected: {}", thingName, sVersion);
254 coiotVers = iVersion;
258 case COIOT_OPTION_STATUS_VALIDITY:
260 case COIOT_OPTION_STATUS_SERIAL:
261 serial = opt.getIntegerValue();
264 logger.debug("{} ({}): COAP option {} with value {} skipped", thingName, devId, opt.getNumber(),
269 // Don't change state to online when thing is in status config error
270 // (e.g. auth failed, but device sends COAP packets via multicast)
271 if (thingHandler.getThingStatusDetail() == ThingStatusDetail.CONFIGURATION_ERROR) {
272 logger.debug("{}: The device is not configuired correctly, skip Coap packet", thingName);
276 // If we received a CoAP message successful the thing must be online
277 thingHandler.setThingOnline();
279 // The device changes the serial on every update, receiving a message with the same serial is a
280 // duplicate, excep for battery devices! Those reset the serial every time when they wake-up
281 if ((serial == lastSerial) && payload.equals(lastPayload) && (!profile.hasBattery
282 || "ext_power".equalsIgnoreCase(coiot.getLastWakeup()) || ((serial & 0xFF) != 0))) {
283 logger.debug("{}: Serial {} was already processed, ignore update", thingName, serial);
287 // fixed malformed JSON :-(
288 payload = fixJSON(payload);
291 if (uri.equalsIgnoreCase(COLOIT_URI_DEVDESC) || (uri.isEmpty() && payload.contains(COIOT_TAG_BLK))) {
292 handleDeviceDescription(devId, payload);
293 } else if (uri.equalsIgnoreCase(COLOIT_URI_DEVSTATUS)
294 || (uri.isEmpty() && payload.contains(COIOT_TAG_GENERIC))) {
295 handleStatusUpdate(devId, payload, serial);
297 } catch (ShellyApiException e) {
298 logger.debug("{}: Unable to process CoIoT message: {}", thingName, e.toString());
299 thingHandler.incProtErrors();
302 if (!updatesRequested) {
303 // Observe Status Updates
304 reqStatus = sendRequest(reqStatus, config.deviceIp, COLOIT_URI_DEVSTATUS, Type.NON);
305 updatesRequested = true;
307 } catch (JsonSyntaxException | IllegalArgumentException | NullPointerException e) {
308 logger.debug("{}: Unable to process CoIoT Message for payload={}", thingName, payload, e);
310 thingHandler.incProtErrors();
315 * Process a CoIoT device description message. This includes definitions on device units (Relay0, Relay1, Sensors
316 * etc.) as well as a definition of sensors and actors. This information needs to be stored allowing to map ids from
317 * status updates to the device units and matching the correct thing channel.
319 * @param devId The device id reported in the CoIoT message.
320 * @param payload Device desciption in JSon format, example:
321 * {"blk":[{"I":0,"D":"Relay0"}],"sen":[{"I":112,"T":"Switch","R":"0/1","L":0}],"act":[{"I":211,"D":"Switch","L":0,"P":[{"I":2011,"D":"ToState","R":"0/1"}]}]}
323 private void handleDeviceDescription(String devId, String payload) throws ShellyApiException {
324 logger.debug("{}: CoIoT Device Description for {}: {}", thingName, devId, payload);
327 boolean valid = true;
330 CoIotDevDescription descr = fromJson(gson, payload, CoIotDevDescription.class);
331 for (int i = 0; i < descr.blk.size(); i++) {
332 CoIotDescrBlk blk = descr.blk.get(i);
333 logger.debug("{}: id={}: {}", thingName, blk.id, blk.desc);
334 if (!blkMap.containsKey(blk.id)) {
335 blkMap.put(blk.id, blk);
337 blkMap.replace(blk.id, blk);
339 if ((blk.type != null) && !blk.type.isEmpty()) {
340 // in fact it is a sen entry - that's vioaling the Spec
341 logger.trace("{}: fix: auto-create sensor definition for id {}/{}!", thingName, blk.id,
343 CoIotDescrSen sen = new CoIotDescrSen();
347 sen.range = blk.range;
348 sen.links = blk.links;
349 valid &= addSensor(sen);
353 // Save to thing properties
354 thingHandler.updateProperties(PROPERTY_COAP_DESCR, payload);
356 logger.debug("{}: Adding {} sensor definitions", thingName, descr.sen.size());
357 if (descr.sen != null) {
358 for (int i = 0; i < descr.sen.size(); i++) {
359 valid &= addSensor(descr.sen.get(i));
363 logger.debug("{}: WARNING: Incompatible device description detected for CoIoT version {}!", thingName,
368 coiot.completeMissingSensorDefinition(sensorMap); // fix incomplete format
369 } catch (JsonSyntaxException e) {
370 logger.warn("{}: Unable to parse CoAP Device Description! JSON={}", thingName, payload);
371 } catch (NullPointerException | IllegalArgumentException e) {
372 logger.warn("{}: Unable to parse CoAP Device Description! JSON={}", thingName, payload, e);
377 * Add a new sensor to the sensor table
379 * @param sen CoIotDescrSen of the sensor
381 private synchronized boolean addSensor(CoIotDescrSen sen) {
382 logger.debug("{}: id {}: {}, Type={}, Range={}, Links={}", thingName, sen.id, sen.desc, sen.type, sen.range,
384 // CoIoT version 2 changes from 3 digit IDs to 4 digit IDs
385 // We need to make sure that the persisted device description matches,
386 // otherwise the stored one is discarded and a new discovery is triggered
387 // This happens on firmware up/downgrades (version 1.8 brings CoIoT v2 with 4 digit IDs)
388 int vers = coiot.getVersion();
389 if (((vers == COIOT_VERSION_1) && (sen.id.length() > 3))
390 || ((vers >= COIOT_VERSION_2) && (sen.id.length() < 4) && !sen.id.equals("6"))) {
391 logger.debug("{}: Invalid format for sensor definition detected, id={}", thingName, sen.id);
396 CoIotDescrSen fixed = coiot.fixDescription(sen, blkMap);
397 if (!sensorMap.containsKey(fixed.id)) {
398 sensorMap.put(sen.id, fixed);
400 sensorMap.replace(sen.id, fixed);
402 } catch (NullPointerException | IllegalArgumentException e) { // depending on firmware release the CoAP device
403 // description is buggy
404 logger.debug("{}: Unable to decode sensor definition -> skip", thingName, e);
411 * Process CoIoT status update message. If a status update is received, but the device description has not been
412 * received yet a GET is send to query device description.
414 * @param devId device id included in the status packet
415 * @param payload CoAP payload (Json format), example: {"G":[[0,112,0]]}
416 * @param serial Serial for this request. If this the the same as last serial
417 * the update was already sent and processed so this one gets
419 * @throws ShellyApiException
421 private void handleStatusUpdate(String devId, String payload, int serial) throws ShellyApiException {
422 logger.debug("{}: CoIoT Sensor data {} (serial={})", thingName, payload, serial);
423 if (blkMap.isEmpty()) {
424 // send discovery packet
428 // try to uses description from last initialization
429 String savedDescr = thingHandler.getProperty(PROPERTY_COAP_DESCR);
430 if (savedDescr.isEmpty()) {
431 logger.debug("{}: Device description not yet received, trigger auto-initialization", thingName);
435 // simulate received device description to create element table
436 logger.debug("{}: Device description for {} restored: {}", thingName, devId, savedDescr);
437 handleDeviceDescription(devId, savedDescr);
441 CoIotGenericSensorList list = fromJson(gson, fixJSON(payload), CoIotGenericSensorList.class);
442 if (list.generic == null) {
443 logger.debug("{}: Sensor list has invalid format! Payload: {}", devId, payload);
447 List<CoIotSensor> sensorUpdates = list.generic;
448 Map<String, State> updates = new TreeMap<>();
449 logger.debug("{}: {} CoAP sensor updates received", thingName, sensorUpdates.size());
451 ShellyColorUtils col = new ShellyColorUtils();
452 for (int i = 0; i < sensorUpdates.size(); i++) {
454 CoIotSensor s = sensorUpdates.get(i);
455 CoIotDescrSen sen = sensorMap.get(s.id);
457 logger.debug("{}: Unable to sensor definition for id={}, payload={}", thingName, s.id, payload);
460 // find matching sensor definition from device description, use the Link ID as index
461 CoIotDescrBlk element = null;
462 sen = coiot.fixDescription(sen, blkMap);
463 element = blkMap.get(sen.links);
464 if (element == null) {
465 logger.debug("{}: Unable to find BLK for link {} from sen.id={}, payload={}", thingName, sen.links,
469 logger.trace("{}: Sensor value[{}]: id={}, Value={} ({}, Type={}, Range={}, Link={}: {})", thingName,
470 i, s.id, getString(s.valueStr).isEmpty() ? s.value : s.valueStr, sen.desc, sen.type, sen.range,
471 sen.links, element.desc);
473 if (!coiot.handleStatusUpdate(sensorUpdates, sen, serial, s, updates, col)) {
474 logger.debug("{}: CoIoT data for id {}, type {}/{} not processed, value={}; payload={}", thingName,
475 sen.id, sen.type, sen.desc, s.value, payload);
477 } catch (NullPointerException | IllegalArgumentException e) {
478 // even the processing of one value failed we continue with the next one (sometimes this is caused by
479 // buggy formats provided by the device
480 logger.debug("{}: Unable to process data from sensor[{}], devId={}, payload={}", thingName, i, devId,
485 if (!updates.isEmpty()) {
487 for (Map.Entry<String, State> u : updates.entrySet()) {
488 String key = u.getKey();
489 updated += thingHandler.updateChannel(key, u.getValue(), false) ? 1 : 0;
492 logger.debug("{}: {} channels updated from CoIoT status, serial={}", thingName, updated, serial);
493 if (profile.isSensor || profile.isRoller) {
494 // CoAP is currently lacking the lastUpdate info, so we use host timestamp
495 thingHandler.updateChannel(profile.getControlGroup(0), CHANNEL_LAST_UPDATE, getTimestamp());
499 if (profile.isLight && profile.inColor && col.isRgbValid()) {
500 // Update color picker from single values
501 if (col.isRgbValid()) {
502 thingHandler.updateChannel(mkChannelId(CHANNEL_GROUP_COLOR_CONTROL, CHANNEL_COLOR_PICKER),
507 if ((profile.isRGBW2 && !profile.inColor) || profile.isRoller) {
508 // Aggregate Meter Data from different Coap updates
510 double totalCurrent = 0.0;
511 @SuppressWarnings("unused")
512 double totalKWH = 0.0;
513 boolean updateMeter = false;
514 while (i <= thingHandler.getProfile().numMeters) {
515 String meter = CHANNEL_GROUP_METER + i;
516 double current = thingHandler.getChannelDouble(meter, CHANNEL_METER_CURRENTWATTS);
517 double total = thingHandler.getChannelDouble(meter, CHANNEL_METER_TOTALKWH);
518 totalCurrent += current >= 0 ? current : 0;
519 totalKWH += total >= 0 ? total : 0;
520 updateMeter |= current >= 0 | total >= 0;
524 thingHandler.updateChannel(CHANNEL_GROUP_METER, CHANNEL_METER_CURRENTWATTS,
525 toQuantityType(totalCurrent, DIGITS_WATT, Units.WATT));
526 thingHandler.updateChannel(CHANNEL_GROUP_METER, CHANNEL_LAST_UPDATE, getTimestamp());
530 // Old firmware release are lacking various status values, which are not updated using CoIoT.
531 // In this case we keep a refresh so it gets polled using REST. Beginning with Firmware 1.6 most
532 // of the values are available
533 thingHandler.triggerUpdateFromCoap();
535 if (failed == sensorUpdates.size()) {
536 logger.debug("{}: Device description problem detected, re-discover", thingName);
542 // Remember serial, new packets with same serial will be ignored
544 lastPayload = payload;
547 private void discover() {
548 if (coiot.getVersion() >= 2) {
551 // Try to device description using http request (FW 1.10+)
552 String payload = api.getCoIoTDescription();
553 if (!payload.isEmpty()) {
554 logger.debug("{}: Using CoAP device description from successful HTTP /cit/d", thingName);
555 handleDeviceDescription(thingName, payload);
558 } catch (ShellyApiException e) {
559 // ignore if not supported by device
563 reqDescription = sendRequest(reqDescription, config.deviceIp, COLOIT_URI_DEVDESC, Type.CON);
567 * Fix malformed JSON - stupid, but the devices sometimes return malformed JSON with then causes a
568 * JsonSyntaxException
570 * @param json to be checked/fixed
572 private static String fixJSON(String payload) {
573 String json = payload;
574 json = json.replace("}{", "},{");
575 json = json.replace("][", "],[");
576 json = json.replace("],,[", "],[");
581 * Send a new request (Discovery to get Device Description). Before a pending
582 * request will be canceled.
584 * @param request The current request (this will be canceled an a new one will
586 * @param ipAddress Device's IP address
587 * @param uri The URI we are calling (CoIoT = /cit/d or /cit/s)
588 * @param con true: send as CON, false: send as NON
591 private Request sendRequest(@Nullable Request request, String ipAddress, String uri, Type con) {
592 if ((request != null) && !request.isCanceled()) {
597 return newRequest(ipAddress, coiotPort, uri, con).send();
601 * Allocate a new Request structure. A message observer will be added to get the
602 * callback when a response has been received.
604 * @param ipAddress IP address of the device
605 * @param uri URI to be addressed
606 * @param uri The URI we are calling (CoIoT = /cit/d or /cit/s)
607 * @param con true: send as CON, false: send as NON
611 private Request newRequest(String ipAddress, int port, String uri, Type con) {
612 // We need to build our own Request to set an empty Token
613 Request request = new Request(Code.GET, con);
614 request.setURI(completeUrl(ipAddress, port, uri));
615 request.setToken(EMPTY_BYTE);
616 request.addMessageObserver(new MessageObserverAdapter() {
618 public void onResponse(@Nullable Response response) {
619 processResponse(response);
623 public void onCancel() {
624 logger.debug("{}: CoAP Request was canceled", thingName);
628 public void onTimeout() {
629 logger.debug("{}: CoAP Request timed out", thingName);
636 * Reset serial and payload used to detect duplicate messages, which have to be ignored.
637 * We can't rely that the device manages serials correctly all the time. There are firmware releases sending updated
638 * sensor information with the serial from the last packet, which is wrong. We bypass this problem by comparing also
641 private void resetSerial() {
646 public int getVersion() {
651 * Cancel pending requests and shutdown the client
653 public synchronized void stop() {
655 logger.debug("{}: Stopping CoAP Listener", thingName);
656 coapServer.stop(this);
657 CoapClient cclient = statusClient;
658 if (cclient != null) {
662 Request request = reqDescription;
663 if (!request.isCanceled()) {
667 if (!request.isCanceled()) {
675 public void dispose() {
679 private static String completeUrl(String ipAddress, int port, String uri) {
680 return "coap://" + ipAddress + ":" + port + uri;