-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
99 lines (92 loc) · 2.01 KB
/
main.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
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
'use strict'
const wifi = require('Wifi');
const WebSocket = require("ws");
const VERSION = "1.0";
const config = JSON.stringify({ "array" :[
{
"uid": "1",
"type": "<http://vocab.peePonic.com/waterPump>",
"api": [
{
"name": "on",
"bus": "gpio",
"pin": 4,
"direction": "out",
"value": 1
},
{
"name": "off",
"bus": "gpio",
"pin": 4,
"direction": "out",
"value": 0
}
]
},
{
"uid": "2",
"type": "<http://vocab.peePonic.com/waterPump>",
"api": [
{
"name": "on",
"bus": "gpio",
"pin": 4,
"direction": "out",
"value": 1
},
{
"name": "off",
"bus": "gpio",
"pin": 4,
"direction": "out",
"value": 0
}
]
},
{
"uid": "3",
"type": "<http://vocab.peePonic.com/airPump>",
"api": [
{
"name": "none"
}
]
},
{
"uid": "4",
"type": "<http://vocab.peePonic.com/waterSensor>",
"api": [
{
"name": "get",
"bus": "gpio",
"pin": "A0"
}
]
}
]
});
wifi.on("connected", () => {
console.log('Connected as: ' + wifi.getIP().ip);
var ws = new WebSocket('192.168.0.104', {
port: 8080,
path: '/'
});
ws.on("open", () => {
console.log("WEB SOCKET Opened");
digitalWrite(D2, HIGH);
ws.send(config);
});
ws.on("message", (msg) => {
console.log(JSON.parse(msg.toString()));
});
});
wifi.connect("wificonred", {
password: "95440279"
}, function(error) {
if (error) {
console.error(error);
}
});
function main() {
console.log("Started: " + new Date().toString());
}