How to use the node-coap-client.CoapClient function in node-coap-client

To help you get started, we’ve selected a few node-coap-client examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github AlCalzone / node-tradfri-client / build / tradfri-client.js View on Github external
return __awaiter(this, void 0, void 0, function* () {
            // create actual payload
            let jsonPayload;
            if (payload != null) {
                jsonPayload = JSON.stringify(payload);
                logger_1.log("sending custom payload: " + jsonPayload, "debug");
                jsonPayload = Buffer.from(jsonPayload);
            }
            // wait for the CoAP response and respond to the message
            const resp = yield this.swallowInternalCoapRejections(node_coap_client_1.CoapClient.request(`${this.requestBase}${path}`, method, jsonPayload));
            return {
                code: resp.code.toString(),
                payload: parsePayload(resp),
            };
        });
    }
github AlCalzone / node-tradfri-client / build / tradfri-client.js View on Github external
return __awaiter(this, void 0, void 0, function* () {
            // check if we are already observing this resource
            const observerUrl = this.getObserverUrl(path);
            if (this.observedPaths.indexOf(observerUrl) > -1)
                return false;
            // start observing
            this.observedPaths.push(observerUrl);
            // and remember the callback to restore it after a soft-reset
            this.rememberedObserveCallbacks.set(observerUrl, callback);
            yield this.swallowInternalCoapRejections(node_coap_client_1.CoapClient.observe(observerUrl, "get", callback));
            return true;
        });
    }
github AlCalzone / node-tradfri-client / build / tradfri-client.js View on Github external
return __awaiter(this, void 0, void 0, function* () {
            // initialize CoAP client
            node_coap_client_1.CoapClient.reset();
            node_coap_client_1.CoapClient.setSecurityParams(this.hostname, {
                psk: { [identity]: psk },
            });
            logger_1.log(`Attempting connection. Identity = ${identity}, psk = ${psk}`, "debug");
            const result = yield node_coap_client_1.CoapClient.tryToConnect(this.requestBase);
            if (result === true) {
                logger_1.log("Connection successful", "debug");
            }
            else {
                logger_1.log("Connection failed. Reason: " + result, "debug");
            }
            return result;
        });
    }
github AlCalzone / node-tradfri-client / build / tradfri-client.js View on Github external
return __awaiter(this, void 0, void 0, function* () {
            // initialize CoAP client
            node_coap_client_1.CoapClient.reset();
            node_coap_client_1.CoapClient.setSecurityParams(this.hostname, {
                psk: { [identity]: psk },
            });
            logger_1.log(`Attempting connection. Identity = ${identity}, psk = ${psk}`, "debug");
            const result = yield node_coap_client_1.CoapClient.tryToConnect(this.requestBase);
            if (result === true) {
                logger_1.log("Connection successful", "debug");
            }
            else {
                logger_1.log("Connection failed. Reason: " + result, "debug");
            }
            return result;
        });
    }
github eclipse / thingweb.node-wot / packages / binding-coap / src / coaps-client.ts View on Github external
* information regarding copyright ownership.
 * 
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v. 2.0 which is available at
 * http://www.eclipse.org/legal/epl-2.0, or the W3C Software Notice and
 * Document License (2015-05-13) which is available at
 * https://www.w3.org/Consortium/Legal/2015/copyright-software-and-document.
 * 
 * SPDX-License-Identifier: EPL-2.0 OR W3C-20150513
 ********************************************************************************/

/**
 * CoAPS client based on node-coap-client by AlCalzone
 */

const coaps = require("node-coap-client").CoapClient;
import * as url from "url";
import * as TD from "@node-wot/td-tools";

import { Subscription } from 'rxjs/Subscription';

import { ProtocolClient, Content } from "@node-wot/core";
import { CoapForm } from "./coap";

export default class CoapsClient implements ProtocolClient {

  // FIXME coap Agent closes socket when no messages in flight -> new socket with every request
  private authorization: any;

  constructor() {
    // Intentionally blank
  }
github AlCalzone / node-tradfri-client / build / tradfri-client.js View on Github external
return __awaiter(this, void 0, void 0, function* () {
            // initialize CoAP client
            node_coap_client_1.CoapClient.reset();
            node_coap_client_1.CoapClient.setSecurityParams(this.hostname, {
                psk: { [identity]: psk },
            });
            logger_1.log(`Attempting connection. Identity = ${identity}, psk = ${psk}`, "debug");
            const result = yield node_coap_client_1.CoapClient.tryToConnect(this.requestBase);
            if (result === true) {
                logger_1.log("Connection successful", "debug");
            }
            else {
                logger_1.log("Connection failed. Reason: " + result, "debug");
            }
            return result;
        });
    }
github AlCalzone / node-tradfri-client / build / tradfri-client.js View on Github external
stopObservingResource(path) {
        // remove observer
        const observerUrl = this.getObserverUrl(path);
        const index = this.observedPaths.indexOf(observerUrl);
        if (index === -1)
            return;
        node_coap_client_1.CoapClient.stopObserving(observerUrl);
        this.observedPaths.splice(index, 1);
        this.rememberedObserveCallbacks.delete(observerUrl);
    }
    /**
github AlCalzone / node-tradfri-client / build / tradfri-client.js View on Github external
ping(timeout) {
        return node_coap_client_1.CoapClient.ping(this.requestBase, timeout);
    }
    /**