This is a DA example in Javascript version, which has enabled automatic IDF push/ODF pull.
Modify apiUrl in option
apiUrl: 'http://IP:9992'
Open index.html in your browser
file://file-path-to-index.html
After you bind the DA in your IotTalk project, it will send and receive the data automatically.
If you want to modify it into your own program, you only need to modify sa.js
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, unit
pairs. Where aidf, 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: 'http://IP:9992',
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,
},
});
const da = new iottalkjs.DAI({ ... });
da.run();