2.3.2 • Published 4 years ago
iottalk-js v2.3.2
IoTtalk2.0 Javascript SDK
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
- Dummy_Device
- Dummy_Device_Table: A much pretty demo of Dummy_Device.
- Smartphone DA: This is a demo of event-driven push.
Install via NPM or Yarn
npm i iottalk-jsor
yarn add iottalk-jsAPI 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 isfalse.username(string): The DA owner.extraSetupWebpage(string)deviceWebpage(string)onRegister(function): A callback function with signaturefunction (dan). The first argument is the instance ofiottalkjs.DAN.Client.onDeregister(function): A callback function with signaturefunction (dan).onConnect(function): A callback invoked on MQTT broker connected. The signature isfunction (dan).onDisconnect(function): A callback function with signaturefunction (dan).pushInterval(number): The push interval in second.interval(object): The key is the device feature name instring.idfList(Array): Should be a list ofidf, unitpairs. Where aidf, unitpair 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 buildFor 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