forked from pulsartronic/LoRaWANGatewaySC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProxy.js
48 lines (39 loc) · 1.37 KB
/
Proxy.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
var udp = require('dgram');
var pcttn = udp.createSocket('udp4');
var gwypc = udp.createSocket('udp4');
var gwaddress = "192.168.1.135";
gwypc.on('message', function(msg, info) {
gwaddress = info.address;
console.log('GW --> PX : ', msg.length + " bytes ", info.address + ":" + info.port);
pcttn.send(msg, 1700, 'router.us.thethings.network', function(error) {
if (error) {
client.close();
} else {
console.log('PX --> TTN');
}
});
});
gwypc.on('listening', function() {
var address = gwypc.address();
console.log('GATEWAY <-> PROXY is listening ' + address.address + ":" + address.port);
});
gwypc.on('error',function(error) { console.log('gwypc Error: ' + error); gwypc.close();});
gwypc.on('close',function() { console.log('gwypc closed !'); });
gwypc.bind(1700);
pcttn.on('message', function(msg, info) {
console.log('PX <-- TTN : ', msg.length + " bytes " + info.address + ":" + info.port, msg);
gwypc.send(msg, 1700, gwaddress, function(error) {
if(error) {
client.close();
} else {
console.log('GW <-- PX ', msg);
}
});
});
pcttn.on('listening', function() {
var address = pcttn.address();
console.log('PROXY <-> TTN is listening ' + address.address + ":" + address.port);
});
pcttn.on('error',function(error) { console.log('pcttn Error: ' + error); gwypc.close();});
pcttn.on('close',function() { console.log('pcttn closed !'); });
pcttn.bind(1800);