2.3.2 • Published 3 years ago

iottalk-js v2.3.2

Weekly downloads
1
License
MIT
Repository
github
Last release
3 years ago

IoTtalk2.0 Javascript SDK

Build Status npm version

Provide DAN of IoTtalk2.0 and some examples.

Usage

The library will export a global variable window.iottalkjs. We provide minified file served from GitHub pages:

<script src="https://iottalk.github.io/iottalk-js/iottalkjs-v2.3.1.js"></script>

There is a pointer for latest master build, it's unstable. Please use it at your own risk.

<script src="https://iottalk.github.io/iottalk-js/iottalkjs.js"></script>

The full build artifacts are here: https://github.com/IoTtalk/iottalk-js/tree/gh-pages

Examples

Install via NPM or Yarn

npm i iottalk-js

or

yarn add iottalk-js

API Reference

class iottalkjs.DAI

constructor iottalkjs.DAI(option)

options is an object:

  • apiUrl (string): The CSM API URL.
  • deviceModel (string)
  • deviceName (string)
  • deviceAddr (string): Should be a valid UUID string.
  • persistentBinding (bool): Default is false.
  • username (string): The DA owner.
  • extraSetupWebpage (string)
  • deviceWebpage (string)
  • onRegister (function): A callback function with signature function (dan). The first argument is the instance of iottalkjs.DAN.Client.
  • onDeregister (function): A callback function with signature function (dan).
  • onConnect (function): A callback invoked on MQTT broker connected. The signature is function (dan).
  • onDisconnect (function): A callback function with signature function (dan).
  • pushInterval (number): The push interval in second.
  • interval (object): The key is the device feature name in string.
  • idfList (Array): Should be a list of idf, unit pairs. Where a idf, unit pair can be following format:
    • [<function pointer>, <unit>]: e.g.: [Dummy_Sensor, ['dB']]
    • [<df name>, <unit>]: In this case, since the function pointer is not provided, the auto-push won't be applied. Please checkout the Smartphone example.
  • odfList (Array)

Example:

const Dummy_Sensor  = () => { ... };
const Dummy_Control = () => { ... };

const da = new iottalkjs.DAI({
  apiUrl: 'https://example.com/csm',
  deviceModel: 'Dummy_Device',
  deviceName: 'MyMagicDevice',
  deviceAddr: '0a14943f-cc88-4f36-a441-dc3f42f03546',
  persistentBinding: true,
  idfList: [[Dummy_Sensor, ['dB']]],
  odfList: [[Dummy_Control, ['dB']]],
});

Example of DF name conversion, the valid underscore suffix (_) in function name will be converted to df naming rules (-):

const Acceleration_I = () => { ... };

const da = new iottalkjs.DAI({
 ...
 idfList: [Acceleration_I, ['g']],
 inverval: {
   'Acceleration-I': 42,
 },
});

run()

const da = new iottalkjs.DAI({ ... });
da.run();

class iottalkjs.DAN.Client

client.push(idf, data, [qos])

  • idf (string): Name of outgoing IDF.
  • data

Development

The following command will output the build module into dir build-web and build-node.

yarn
yarn run build

For nodejs only build, there is a target build:node. For web only build, there is a target build:web.

Publishing NPM package

yarn login
yarn run build
yarn publish
2.3.2

3 years ago

2.3.1

3 years ago

2.3.0

3 years ago

2.0.4

5 years ago

2.0.3

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago