forked from qnap-dev/qnap-qiot-sdks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
http.js
43 lines (37 loc) · 1.14 KB
/
http.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/**
* This sample code demo random number value send to QIoT Suite Lite by HTTP protocol
* requirement:
* -- npm install
* run command: node http.js
*/
var qiot = require('./lib/qiot');
/**
* Setup connection options
*/
var connection = new qiot(qiot.protocol.HTTP);
var connection_option = connection.readResource('./res/resourceinfo.json');
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
/**
* Send data to QIoT Suite Lite.
* content of ./res/resourceinfo.json
* {
* ...
* "resources": [
* {
* ...
* "resourceid": "temp",
* "topic": "qiot/things/admin/abccccc/temp",
* ...
* }
* ]
* }
*/
setInterval(function() {
// TODO: you could replace "temp" by any resource id set form QIoT Suite Lite
connection.publishById("temp", getRandomInt(0, 50));
// or publish by resource topic
// TODO: you could replace "qiot/things/admin/edison/temp" by any Topic form QIoT Suite Lite like following
// connection.publishByTopic("qiot/things/admin/edison/temp", getRandomInt(0, 50));
}, 1000);