-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathWebArduino.js
More file actions
109 lines (97 loc) · 2.78 KB
/
WebArduino.js
File metadata and controls
109 lines (97 loc) · 2.78 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
+(function (global, factory) {
if (typeof exports === 'undefined') {
factory(global.webduino || {});
} else {
module.exports = factory;
}
}(this, function (scope) {
'use strict';
var util = scope.util,
TransportEvent = scope.TransportEvent,
Board = scope.Board,
proto;
function WebArduino(options) {
if (typeof options === 'string') {
options = {
device: options
};
}
if (options.area === 'china') {
options.server = WebArduino.SERVER_CHINA;
}
options = util.extend(getDefaultOptions(), options);
options.server = parseServer(options.server);
Board.call(this, options);
}
function getDefaultOptions() {
return {
transport: 'mqtt',
server: WebArduino.DEFAULT_SERVER,
login: 'admin',
password: 'password',
autoReconnect: false,
multi: false,
initialReset: true,
handleDigitalPins: true
};
}
function parseServer(url) {
if (url.indexOf('://') === -1) {
url = (typeof location !== 'undefined' &&
location.protocol === 'https:' ? 'wss:' : 'ws:') +
'//' + url;
}
url = util.parseURL(url);
return url.protocol + '//' + url.host + '/';
}
WebArduino.prototype = proto = Object.create(Board.prototype, {
constructor: {
value: WebArduino
}
});
proto.reportFirmware = function () {
var msg = [
240, 121, 2, 4, 119, 0, 101, 0, 98, 0, 100, 0, 117, 0, 105, 0,
110, 0, 111, 0, 46, 0, 105, 0, 110, 0, 111, 0, 247
];
mockMessageEvent(this, msg);
};
proto.queryCapabilities = function () {
var msg = [
240, 108, 127, 127,
0, 1, 1, 1, 4, 14, 127,
0, 1, 1, 1, 3, 8, 4, 14, 127,
0, 1, 1, 1, 4, 14, 127,
0, 1, 1, 1, 3, 8, 4, 14, 127,
0, 1, 1, 1, 3, 8, 4, 14, 127,
0, 1, 1, 1, 4, 14, 127,
0, 1, 1, 1, 4, 14, 127,
0, 1, 1, 1, 3, 8, 4, 14, 127,
0, 1, 1, 1, 3, 8, 4, 14, 127,
0, 1, 1, 1, 3, 8, 4, 14, 127,
0, 1, 1, 1, 4, 14, 127,
0, 1, 1, 1, 4, 14, 127,
0, 1, 1, 1, 2, 10, 4, 14, 127,
0, 1, 1, 1, 2, 10, 4, 14, 127,
0, 1, 1, 1, 2, 10, 4, 14, 127,
0, 1, 1, 1, 2, 10, 4, 14, 127,
0, 1, 1, 1, 2, 10, 4, 14, 127,
0, 1, 1, 1, 2, 10, 4, 14, 127,
2, 10, 127, 2, 10, 127, 247
];
mockMessageEvent(this, msg);
};
proto.queryAnalogMapping = function () {
var msg = [
240, 106, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, 127,
0, 1, 2, 3, 4, 5, 6, 7, 247
];
mockMessageEvent(this, msg);
};
WebArduino.DEFAULT_SERVER = 'wss://ws.webduino.io:443';
WebArduino.SERVER_CHINA = 'wss://ws.webduino.com.cn';
function mockMessageEvent(board, message) {
board._transport.emit(TransportEvent.MESSAGE, message);
}
scope.WebArduino = WebArduino;
}));