npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

linkedge-thing-access-sdk

v0.7.0

Published

A library allows developers to write Node.js Function Compute functions which will run within Link Edge to connect things to it.

Downloads

27

Readme

English|中文

Link IoT Edge Thing Access SDK for Node.js

The project providers a node.js package to develop drivers which running on Link IoT Edge and helping things connect to it.

Getting Started - HelloThing

The HelloThing sample demonstrates you the procedure that connecting things to Link IoT Edge.

  1. Copy examples/HelloThing folder to your workspace.
  2. Zip up the content of HelloThing folder so that the index.js is on the top of the zip file structure.
  3. Go to Link IoT Edge console, Edge Management, Driver Management and then Create Driver.
  4. Choose the programming language as nodejs8.
  5. Set the driver name HelloThing and upload the previous zip file.
  6. Create a product, which owns an property named temperature(type of int32), and an event named high_temperature(type of int32 and has a input parameter named temperature whose type is int32).
  7. Create a device of the product created last step, with name HelloThing.
  8. Create a new Edge Instance and add the Link IoT Edge gateway device into it.
  9. Add the HelloThing device into the Instance. Choose HelloThing as its driver.
  10. Add a Message Router with the following configuration:
  • Source: HelloThing device
  • TopicFilter: Properties.
  • Target: IoT Hub
  1. Deploy. A message from HelloThing device should be published to IoT Hub every 2 seconds. You can check this by going to the Device Running State page on Link IoT Edge console.

Usage

First install this library:

npm install linkedge-thing-access-sdk

Then connect things to Link IoT Edge. The most common use is as follows:

const {
  Config,
  ThingAccessClient
} = require('linkedge-thing-access-sdk');

const callbacks = {
  setProperties: function (properties) {
    // Set properties to the physical thing and return the result.
    // Return an object representing the result or the promise wrapper of the object.
    return {
      code: 0,
      message: 'success',
      }
    };
  },
  getProperties: function (keys) {
    // Get properties from the physical thing and return the result.
    // Return an object representing the result or the promise wrapper of the object.
    return {
      code: 0,
      message: 'success',
      params: {
        key1: 'value1',
        key2: 'value2',
      }
    };
  },
  callService: function (name, args) {
    // Call services on the physical thing and return the result.
    // Return an object representing the result or the promise wrapper of the object.
    return new Promise((resolve) => {
      resolve({
        code: 0,
        message: 'success',
      });
    });
  }
};
Config.get()
  .then(config => {
    const thingInfos = config.getThingInfos();
    thingInfos.forEach(thingInfo => {
      const client = new ThingAccessClient(thingInfo, callbacks);
      client.registerAndOnline()
        .then(() => {
          return new Promise(() => {
            setInterval(() => {
              client.reportEvent('high_temperature', { temperature: 41 });
              client.reportProperties({ 'temperature': 41 });
            }, 2000);
          });
        })
        .catch(err => {
          console.log(err);
          client.cleanup();
        });
        .catch(err => {
          console.log(err);
        });
    });
  });

Next follow the Getting Started to upload and test the function.

References

You can run the following command in the project root directory to generate the API references to docs directory:

npm run generate-docs

The main API references are as follows.


getConfig()

Returns the global config string.

Returns Promise<String>.


Config.get()

Returns the global config as object.

Returns Promise<Config>.


Config.getThinginfos()

Returns all thing infos for further use.

Returns Array<ThingInfo>.


Config.getDriverInfo()

Returns global driver info for further use.

Returns Object.


Config.registerchangedcallback(callback)

Registers a callback that will be notified when the config changed.

  • callback(configString): callback to notify when the config changed event occurs.

Config.unregisterchangedcallback(callback)

Unregisters a callback.

  • callback(configString): callback to notify when the config changed event occurs.

ThingInfo

The infos of a thing, which includes:

  • productKey: the product key of the thing, String.
  • deviceName: the device name of the thing, String.
  • custom: the custom config of the thing, Object.

ThingAccessClient(config, callbacks)

Constructs a ThingAccessClient with the specified config and callbacks.

  • config: the meta data config about the client, Object.
  • callbacks: callback functions responding to the requests from Link IoT Edge platform, Object.
    • getProperties(keys): a function responding to get thing properties requests, Function.
    • setProperties(properties): a fucntion responding to set thing properties requests, Function.
    • callService(name, args): a function responding to call thing services requests, Function.

ThingAccessClient.setup()

(Deprecated) Performs common constructor intialization and setup operations.

Returns Promise<Void>.


ThingAccessClient.registerAndOnline()

Registers thing to Link IoT Edge platform and informs it that thing is connected. When register, DEVICE_NAME will be used first if it exists, or LOCAL_NAME is used.

Returns Promise<Void>.


ThingAccessClient.online()

Informs Link IoT Edge platform that thing is connected.

Returns Promise<Void>.


ThingAccessClient.offline()

Informs Link IoT Edge platform that thing is disconnected.

Returns Promise<Void>.


ThingAccessClient.getTsl()

Returns the TSL(Thing Specification Language) string.

Returns Promise<String>.


~~ThingAccessClient.getTslConfig()~~

Deprecated. Use getTslExtInfo instead.

Returns the TSL(Thing Specification Language) config string.

Returns Promise<String>.


ThingAccessClient.getTslExtInfo()

Returns the TSL(Thing Specification Language) extend info string.

Returns Promise<String>.


ThingAccessClient.reportEvent(eventName, args)

Reports a event to Link IoT Edge platform.

  • eventName: the name of the event, String.
  • args: the parameters attached to the event, Object.

ThingAccessClient.reportProperties(properties)

Reports new property values to Link IoT Edge platform.

  • properties: the new properties, String.

ThingAccessClient.cleanup()

Called at the end of the usage of the instance to release resources.

Returns Promise<Void>.


ThingAccessClient.unregister()

Removes the binding relationship between thing and Link IoT Edge platform. You usually don't call this function.

Returns Promise<Void>.

License

Copyright (c) 2017-present Alibaba Group Holding Ltd.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.