forked from joepavitt/node-red-satellites
-
Notifications
You must be signed in to change notification settings - Fork 0
/
satellites.js
71 lines (60 loc) · 1.99 KB
/
satellites.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
// var positionAndVelocity = satellite.sgp4(satrec, time);
module.exports = function (RED) {
"use strict";
var express = require("express");
var io = require('socket.io');
var socket;
if (typeof define !== 'function') {
var define = require('amdefine')(module)
}
define(['./node_modules/satellite.js/dist/satellite'], function (js) {
function SatelliteNode(config) {
RED.nodes.createNode(this, config);
this.satid = config.satid || '';
this.tle1 = config.tle1 || '';
this.tle2 = config.tle2 || '';
var node = this;
console.log(express.static(__dirname + '/satellites'));
RED.httpNode.use("/earth", express.static(__dirname + '/satellites'));
this.on('input', function (msg) {
var satellite = js.satellite;
// Sample TLE
/*var tleLine1 = '1 25544U 98067A 17117.89041289 -.00158687 00000-0 -24621-2 0 9992',
tleLine2 = '2 25544 51.6432 289.0003 0006055 101.4704 344.3366 15.53834686 53936';*/
// Initialize a satellite record
var satrec = satellite.twoline2satrec(node.tle1, node.tle2);
var posvel = satellite.propagate(satrec, new Date()); // msg.payload.toLowerCase();
msg.payload = {
name : node.satid,
position : posvel.position,
velocity : posvel.velocity
}
node.send(msg);
});
}
RED.nodes.registerType("satellite", SatelliteNode);
});
function EarthNode(config) {
RED.nodes.createNode(this, config);
if (!socket) {
socket = io.listen(RED.server);
}
var node = this;
console.log(express.static(__dirname + '/satellites'));
RED.httpNode.use("/earth", express.static(__dirname + '/satellites'));
var onConnection = function (client) {
node.on('input', function (msg) {
console.log('earth input received');
console.log(msg.payload)
client.emit("earthdata", msg.payload);
});
node.on('close', function() {
node.status({});
client.disconnect(true);
})
};
node.status({});
socket.on('connection', onConnection);
}
RED.nodes.registerType("earth", EarthNode);
};