How to use the node-coap-client.CoapClient.setSecurityParams 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 eclipse / thingweb.node-wot / packages / binding-coap / src / coaps-client.ts View on Github external
private generateRequest(form: CoapForm, dflt: string, content?: Content): any {
    
    // url only works with http*
    let requestUri = url.parse(form.href.replace(/$coaps/, "https"));
    coaps.setSecurityParams(requestUri.hostname, this.authorization );

    let method: string = dflt;

    if (typeof form["coap:methodCode"] === "number") {
      console.log("CoapsClient got Form 'methodCode'", form["coap:methodCode"]);
      switch (form["coap:methodCode"]) {
        case 1: method = "get"; break;
        case 2: method = "post"; break;
        case 3: method = "put"; break;
        case 4: method = "delete"; break;
        default: console.warn("CoapsClient got invalid 'methodCode', using default", method);
      }
    }

    console.log(`CoapsClient sending ${method} to ${form.href}`);
    let req = coaps.request(
github eclipse / thingweb.node-wot / packages / binding-coap / src / coaps-client.ts View on Github external
public subscribeResource(form: CoapForm, next: ((value: any) => void), error?: (error: any) => void, complete?: () => void): any {

    let requestUri = url.parse(form.href.replace(/$coaps/, "https"));
    coaps.setSecurityParams(requestUri.hostname, this.authorization );

    coaps.observe(
      form.href,
      "get",
      next
    )
    .then(() => { /* observing was successfully set up */})
    .catch((err: any) => { error(err); })

    return new Subscription(() => { coaps.stopObserving(form.href); complete(); });
  }
github AlCalzone / node-tradfri-client / src / tradfri-client.ts View on Github external
private async tryToConnect(identity: string, psk: string): Promise {

		// initialize CoAP client
		coap.reset();
		coap.setSecurityParams(this.hostname, {
			psk: { [identity]: psk },
		});

		log(`Attempting connection. Identity = ${identity}, psk = ${psk}`, "debug");
		const result = await coap.tryToConnect(this.requestBase);
		log(`Connection ${result ? "" : "un"}successful`, "debug");
		return result;
	}