Skip to content

Commit ea6d7c9

Browse files
committed
JAN 2020 UPDATE (v2.0.0)
- Added Google Map for Mini-Map Overlay use. - Added Unique-Code for security. ** Updated Readme, MUST read for a thorough understanding of new features and updates. **
1 parent d32ead0 commit ea6d7c9

25 files changed

+14640
-46
lines changed

README.md

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# gps-logger by 715209
2+
# live-map by b3ck
23

34
Download and install this on your android phone:
45
https://github.com/mendhak/gpslogger/releases
@@ -15,14 +16,26 @@ Once it's started go into the settings and turn everything off for logging besid
1516
1617
> [JS REST APP ID & APP CODE EXAMPLE](https://i.imgur.com/74eEKEr.png/)
1718
18-
- 4.) [Open and Forward your ports](https://www.noip.com/support/knowledgebase/general-port-forwarding-guide/), otherwise all of this won't work.
19-
- 5.) Run 'npm start.bat' to start the gps-logger server
19+
- 4.) Also in the `config.js` is a section for a 'UNIQUE_CODE', if you want to protect access to the GPS-LOGGER either generate it or put in your own code, if not then leave it blank;
20+
21+
Get a Code here => https://www.randomcodegenerator.com/en/generate-codes or make up your own.
22+
23+
Add `&key=<UNIQUE_CODE>` at the end of your GPS-LOGGER 'custom url' URL, this will secure your data and everything in turn needs this key to access data and send data.
24+
25+
My Custom URL in GPS-Logger looks like this: ```http://<YOUR-IP-or-DNS>:<PORT>/log?s=%SPD&b=%BATT&lat=%LAT&lon=%LON&a=%ALT&key=<UNIQUE_CODE>```
26+
27+
If you want to access the gps-logger from outside your local network you'll need to add `?key=<UNIQUE-CODE>` to the end of the URL, for example ```http://<YOUR-IP-or-DNS>:<PORT>/map?key=<UNIQUE-CODE>```
28+
29+
This could be a neat tool to give to your most trusted MODs just in case something happens to you, they 'could' provide emergency services with your exact location.
30+
31+
- 5.) [Open and Forward your ports](https://www.noip.com/support/knowledgebase/general-port-forwarding-guide/), otherwise all of this won't work.
32+
- 6.) Run 'npm start.bat' to start the gps-logger server
2033

2134
It should say something like this:
2235

2336
```
2437
PS C:\github\gps-logger> npm start
25-
gps-logger@1.0.0 start C:\github\gps-logger
38+
gps-logger@2.0.0 start C:\github\gps-logger
2639
node app
2740
listening on *:3000
2841
```
@@ -32,11 +45,23 @@ listening on *:3000
3245
> - or http://localhost:3000/stats/a
3346
> - or http://localhost:3000/stats/b
3447
48+
> Other links to know:
49+
> - http://localhost:3000/map
50+
> - > is your regular map
51+
52+
> - http://localhost:3000/map_rotate
53+
> - > is a basic attempt to make the map rotate depending on your current direction, you will need to add &d=%DIR to your Custom URL in the GPS-LOGGER app on your phone, before the UNIQUE-CODE. ```ex; http://<YOUR-IP-or-DNS>:<PORT>/log?s=%SPD&b=%BATT&lat=%LAT&lon=%LON&a=%ALT&d=%DIR&key=<UNIQUE_CODE>```
54+
55+
> - http://localhost:3000/mod_map
56+
> - > this will show a map with all details and stats to help your most trusted MODs in an emergency situtation.
57+
> - > MODs can access this from: ```http://<YOUR-IP-or-DNS>:<PORT>/mod_map?key=<UNIQUE-CODE>```
58+
3559
Now just pull whatever you want into your OBS Scene, and Bob's your uncle. :man:
3660

3761
> Please keep in mind I just left everything styled like I have it in my stream, to truly make it your own all it takes is a little tinkering with CSS.
3862
39-
If you have any issues feel free to submit them here on GitHub.
63+
If you have any issues feel free to submit them here on GitHub, or message me on Discord.
64+
- To see it in action check out my livestream or VODs @ https://twitch.tv/b3ck
4065

4166

4267

app.js

Lines changed: 104 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ const http = require("http").Server(app);
77
const io = require("socket.io")(http);
88
const config = require("./config.js");
99
const fetch = require("node-fetch");
10+
const geoTz = require('geo-tz');
1011

1112
// Don't touch this!
1213
let waitForTheStuff = false; //really you don't want to touch this, like ever, if you do.. nothing will work... seriously.
1314

14-
1515
// This area gives the data a nice little home to stay in, if you add anything in the below functions make sure it ends up here.
1616
let lastRequest = {
1717
city: "",
@@ -23,9 +23,58 @@ let lastRequest = {
2323
country: "",
2424
country2: "",
2525
temp: "",
26-
time: ""
26+
time: "",
27+
direction: "",
28+
gapi: ""
2729
};
2830

31+
/////////////////
32+
// Timestamp Stuff //
33+
////////////////////////////////////////////////////////////////
34+
function formatAMPM(date) {
35+
var month = ('0' + (date.getMonth() + 1)).slice(-2);
36+
var day = ('0' + date.getDate()).slice(-2);
37+
var year = date.getFullYear();
38+
var hours = date.getHours();
39+
var minutes = date.getMinutes();
40+
var seconds = date.getSeconds();
41+
var ampm = hours >= 12 ? 'PM' : 'AM';
42+
hours = hours % 12;
43+
hours = hours ? hours : 12; // the hour '0' should be '12'
44+
minutes = minutes < 10 ? '0'+minutes : minutes;
45+
seconds = seconds < 10 ? '0'+seconds : seconds;
46+
var strTime = month + '/' + day + '/' + year + ' - ' + hours + ':' + minutes + ':' + seconds + ' ' + ampm;
47+
return strTime;
48+
}
49+
////////////////////////////////////////////////////////////////
50+
51+
// Map Style Stuff
52+
mapstyle = config.MAPSTYLE + '.json';
53+
54+
// Google Map API Stuff
55+
lastRequest.gapi = config.GOOGLEAPI
56+
57+
// Unqiue Code Stuff
58+
app.use(function checkKey(req, res, next) {
59+
60+
const timestamp = formatAMPM(new Date);
61+
const ip = req.header('x-forwarded-for') || req.connection.remoteAddress;
62+
// console.log(timestamp, ip);
63+
if (ip == "::ffff:127.0.0.1" || ip == "127.0.0.1" || ip == "localhost") {
64+
console.log(timestamp, ip, "- Access Granted")
65+
next();
66+
} else {
67+
if (req.query.key != config.UNIQUE_CODE) {
68+
console.log(timestamp, ip, "- Access Denied")
69+
res.sendStatus(401);
70+
} else {
71+
console.log(timestamp, ip, "- Access Granted")
72+
next();
73+
}
74+
}
75+
76+
});
77+
2978
// Log output page
3079
app.get("/", (req, res) => {
3180
res.sendFile(__dirname + "/index.html");
@@ -36,6 +85,30 @@ app.get("/thestuff", (req, res) => {
3685
res.sendFile(__dirname + "/the_stuff.html");
3786
});
3887

88+
// The Google Maps output page
89+
app.get("/map", (req, res) => {
90+
res.sendFile(__dirname + "/map.html");
91+
});
92+
93+
// The Google Maps output page
94+
app.get("/map_rotate", (req, res) => {
95+
res.sendFile(__dirname + "/map_rotate.html");
96+
});
97+
98+
// The way to get map style
99+
app.get("/style", (req, res) => {
100+
res.sendFile(__dirname + "/map_styles/" + mapstyle);
101+
});
102+
103+
// The way to get default map style
104+
app.get("/default", (req, res) => {
105+
res.sendFile(__dirname + "/map_styles/default.json");
106+
});
107+
108+
app.get("/mod_map", (req, res) => {
109+
res.sendFile(__dirname + "/mod_map.html");
110+
});
111+
39112
// ----------------------------------------------------------------------------------------------------------------------------------------------------------
40113
// Endpoint(s) to grab data for use with nightbot twitch chatbot, or anything really..
41114
//
@@ -55,10 +128,11 @@ app.get("/stats/:anything", (req, res) => {
55128
res.send(`${lastRequest[req.params.anything]}`);
56129
});
57130

58-
59-
// My Custom URL in GPS-Logger looks like this: http://<YOUR-IP-or-DNS>:3000/log?s=%SPD&b=%BATT&lat=%LAT&lon=%LON&a=%ALT
131+
// My Custom URL in GPS-Logger looks like this: http://<YOUR-IP-or-DNS>:3000/log?s=%SPD&b=%BATT&lat=%LAT&lon=%LON&a=%ALT&key=<UNIQUE_CODE>
60132
app.get("/log", (req, res) => {
61133

134+
delete req.query.key;
135+
62136
//Current Altitude (FT) - a=%ALT
63137
if (req.query.a) {
64138
req.query.a = `${Math.round(req.query.a / 0.3048)} FT`;
@@ -82,6 +156,8 @@ app.get("/log", (req, res) => {
82156
if (req.query.lat && req.query.lon) {
83157
const { lat, lon } = req.query;
84158

159+
lastRequest.time = new Date().toLocaleTimeString("en-US", { timeZone: geoTz(lat, lon)[0], hour: '2-digit', minute: '2-digit' });
160+
85161
!waitForTheStuff && getTheStuff(lat, lon);
86162
io.emit("THESTUFF", lastRequest);
87163

@@ -104,7 +180,12 @@ const getTheStuff = (lat, lon) => {
104180

105181
getOpenWeatherMap(lat, lon, config.UNITS, config.OWM_Key);
106182
getHEREdotcom(lat, lon, config.HERE_appid, config.HERE_appcode);
107-
getWeatherGov(lat, lon);
183+
}
184+
185+
const degToCompass = (num) => {
186+
let val = Math.floor((num / 22.5) + 0.5);
187+
let arr = ["N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE", "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW"];
188+
return arr[(val % 16)];
108189
}
109190

110191
// OpenWeatherMap needs an API, please set this in the 'config.js' file.
@@ -113,27 +194,18 @@ const getOpenWeatherMap = async (lat, lon, units, apikey) => {
113194
let data = await fetch(`https://api.openweathermap.org/data/2.5/weather?lat=${lat}&lon=${lon}&units=${units}&appid=${apikey}`);
114195
let openweathermap = await data.json();
115196

197+
icon = openweathermap.weather[0].icon
198+
199+
lastRequest.icon = `http://openweathermap.org/img/wn/${icon}@2x.png`
200+
201+
lastRequest.direction = degToCompass(openweathermap.wind.deg)
116202
lastRequest.temp = Math.floor(openweathermap.main.temp)
117203
} catch (error) {
118204
console.log("getOpenWeatherMap request failed or something.", error);
119205
}
120206

121207
}
122208

123-
// Weather.gov needs no API Key. POGGERS
124-
const getWeatherGov = async (lat, lon) => {
125-
try {
126-
let data = await fetch(`https://api.weather.gov/points/${lat},${lon}`);
127-
let weathergov = await data.json();
128-
129-
// This will grab the current time in 12 hour format based on your LON & LAT.
130-
lastRequest.time = new Date().toLocaleTimeString("en-US", { timeZone: weathergov.properties.timeZone, hour: '2-digit', minute: '2-digit' });
131-
132-
} catch (error) {
133-
console.log("getWeatherGov request failed or something.", error);
134-
}
135-
}
136-
137209
// HERE.com ( https://developer.here.com/sign-up?create=Freemium-Basic&keepState=true&step=account )
138210
const getHEREdotcom = async (lat, lon, appid, appcode) => {
139211
try {
@@ -144,10 +216,15 @@ const getHEREdotcom = async (lat, lon, appid, appcode) => {
144216
here_city = heredotcom.Response.View[0].Result[1].Location.Address.City
145217
here_country = heredotcom.Response.View[0].Result[1].Location.Address.Country
146218

147-
if (here_town == 'undefined' || here_town == null || here_town == here_city) {
148-
lastRequest.town2 = ""
219+
// I wanted to customize certain city names, so this is how I did it.
220+
if (here_town == "Coon Rapids") {
221+
lastRequest.town2 = "( Raccoon City ) - "
222+
} else if (here_town == "Fridley") {
223+
lastRequest.town2 = "( Friendly Fridley ) - "
224+
} else if (here_town == null || here_town == 'undefined' || here_town == here_city) {
225+
lastRequest.town2 = ""
149226
} else {
150-
lastRequest.town2 = `${here_town} - `
227+
lastRequest.town2 = `( ${here_town} ) - `
151228
}
152229

153230
// Result [0]
@@ -157,11 +234,11 @@ const getHEREdotcom = async (lat, lon, appid, appcode) => {
157234
// Result [1]
158235
lastRequest.city = here_city
159236

160-
if (here_city == 'undefined' || here_city == null) {
237+
if (here_city == null || here_town == 'undefined') {
161238
lastRequest.city2 = ""
162-
} else {
163-
lastRequest.city2 = `${here_city}, `
164-
}
239+
} else {
240+
lastRequest.city2 = `${here_city}, `
241+
}
165242

166243
lastRequest.state = heredotcom.Response.View[0].Result[1].Location.Address.State
167244
lastRequest.country = heredotcom.Response.View[0].Result[1].Location.Address.Country
@@ -175,4 +252,4 @@ const getHEREdotcom = async (lat, lon, appid, appcode) => {
175252
//don't touch this either =p
176253
http.listen(config.PORT, () => {
177254
console.log(`listening on *:${config.PORT}`);
178-
});
255+
});

config.js

Lines changed: 42 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
103 KB
Binary file not shown.

0 commit comments

Comments
 (0)