A library allows developers to write Node.js Function Compute functions which will run within Link Edge to connect things to it.
npm install linkedge-thing-access-sdkHelloThing sample demonstrates you the procedure that connecting things to Link IoT Edge.examples/HelloThing folder to your workspace.HelloThing folder so that the index.js is on the top of the zip file structure.HelloThing and upload the previous zip file.temperature(type of int32), and an event named high_temperature(type of int32 and has a input parameter named temperature whose type is int32).HelloThing.HelloThing device into the Instance. Choose HelloThing as its driver.HelloThing deviceHelloThing 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.
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()
* Config#get()
* Config#getThingInfos()
* Config#getDriverInfo()
* Config#registerChangedCallback()
* Config#unregisterChangedCallback()
* ThingInfo
* ThingAccessClient()
* ThingAccessClient#setup()
* ThingAccessClient#registerAndOnline()
* ThingAccessClient#online()
* ThingAccessClient#offline()
* ThingAccessClient#getTsl()
* ThingAccessClient#~~getTslConfig()~~
* ThingAccessClient#getTslExtInfo()
* ThingAccessClient#reportEvent()
* ThingAccessClient#reportProperties()
* ThingAccessClient#cleanup()
* ThingAccessClient#unregister()
$3
Returns the global config string.Returns
Promise.$3
Returns the global config as object.Returns
Promise.$3
Returns all thing infos for further use.Returns
Array.$3
Returns global driver info for further use.Returns
Object.$3
Registers a callback that will be notified when the config changed.*
callback(configString): callback to notify when the config changed event occurs.$3
Unregisters a callback.*
callback(configString): callback to notify when the config changed event occurs.$3
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.$3
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.$3
(Deprecated) Performs common constructor intialization and setup operations.Returns
Promise.$3
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.$3
Informs Link IoT Edge platform that thing is connected.Returns
Promise.$3
Informs Link IoT Edge platform that thing is disconnected.Returns
Promise.$3
Returns the TSL(Thing Specification Language) string.Returns
Promise.$3
Deprecated. Use getTslExtInfo instead.Returns the TSL(Thing Specification Language) config string.
Returns
Promise.$3
Returns the TSL(Thing Specification Language) extend info string.Returns
Promise.$3
Reports a event to Link IoT Edge platform.*
eventName: the name of the event, String.
* args: the parameters attached to the event, Object.$3
Reports new property values to Link IoT Edge platform.*
properties: the new properties, String.$3
Called at the end of the usage of the instance to release resources.Returns
Promise.$3
Removes the binding relationship between thing and Link IoT Edge platform. You usually don't call this function.Returns
Promise.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.
``