Skip to content

Commit

Permalink
Merge pull request #36 from Privacywonk/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
Privacywonk authored Apr 22, 2018
2 parents b317264 + 9c9dc73 commit fe98b7f
Show file tree
Hide file tree
Showing 12 changed files with 287 additions and 84 deletions.
11 changes: 10 additions & 1 deletion MMM-Surf.css
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,22 @@
}

.MMM-Surf .swellred {
color: #FF0055;
/* color: #FF0055; */
color: #C00000;
}

.MMM-Surf .swellorange {
color: #FF5500;
}

.MMM-Surf .swellblue {
color: #3dafeb;
}

.fa-small {
font-size: .8em;
}


.MMM-Surf .day {
padding-left: 0;
Expand Down
207 changes: 169 additions & 38 deletions MMM-Surf.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

MMM-Surf is a [Magic Mirror](https://github.com/MichMich/MagicMirror) module that will display weather, tides, water temp, and Magicseaweed forecast data for your favorite spot. It is currently North America centric, pulling tide and water temperature from the National Oceanic and Atmospheric Administration (NOAA).

The surf forecast data is minimized from the normal Magicseaweed interface to focus on "at-a-glance" information only: The Magicseaweed star rating system, height of swell at periodicity, swell direction, wind direction, and speed. These bits of information are color coded based on certain configurable items (see below): Green means the condition is right for the spot, orange means acceptable, red is slop. If I see all green, I go.
The surf forecast data is minimized from the normal Magicseaweed interface to focus on "at-a-glance" information only: The [Magicseaweed star rating system](https://magicseaweed.com/help/forecast-table/star-rating), height of swell at periodicity, swell direction, wind direction, and speed. These bits of information are color coded based on certain configurable items (see below): Green means the condition is right for the spot, orange means acceptable, red is slop. If I see all green, I go.

![image](https://user-images.githubusercontent.com/9799911/37928485-faba035e-310a-11e8-90bb-daca18812be0.PNG)
![image](https://user-images.githubusercontent.com/9799911/39096515-0dd16c7e-461f-11e8-8b14-8f64dbe41bc5.png)

### Prerequisites

Expand Down
Binary file modified img/High.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/HighTide1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/HighTide2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/HighTide3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified img/Low.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/LowTide1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/LowTide2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/LowTide3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
149 changes: 106 additions & 43 deletions node_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ var request = require('request');
var moment = require('moment');
const exec = require('child_process').exec;
var helperDebug = "";
var tempTime = "";

module.exports = NodeHelper.create({
start: function() {
Expand All @@ -20,12 +21,38 @@ module.exports = NodeHelper.create({
this.wunderPayload = "";
//NOAA Water Temp and Tides
this.NOAAfetcherRunning = false;
this.NOAAPayload = "";
this.NOAATidePayload = "";
this.NOAATempPayload = "";
//Magicseaweed Surf Forecast
this.MAGICfetcherRunning = false;
this.magicseaweed = "";
this.started = false;
},

scheduleUpdate: function() {
var nextload = this.config.updateInterval;
tempTime = moment();
tempTime.add(nextload, 'ms');
console.log ("INITIAL LOAD - NEXT LOAD TIME: " +tempTime.format('YYYY-MM-DD >> HH:mm:ss.SSSZZ'));
var self = this;
if (this.config.debug === 1) {
apiMessage = moment().format('YYYY-MM-DDTHH:mm:ss.SSSZZ') + ' UPDATE: Next update set for: ' + tempTime.format('YYYY-MM-DD >> HH:mm:ss.SSSZZ');
self.sendSocketNotification('HELPER_MESSAGE', apiMessage);
}
this.updateTimer = setInterval(function() {
if (self.config.debug === 1) {
apiMessage = moment().format('YYYY-MM-DDTHH:mm:ss.SSSZZ') + ' UPDATE: scheduleUpdate() triggered. Fetching new data';
self.sendSocketNotification('HELPER_MESSAGE', apiMessage);
}
self.fetchNOAAData(self);
self.fetchWunderground(self);
self.fetchMagicseaweedData(self);
tempTime = moment();
tempTime.add(nextload, 'ms');
console.log ("UPDATE LOAD - NEXT LOAD TIME: " +tempTime.format('YYYY-MM-DD >> HH:mm:ss.SSSZZ'));
}, nextload); //define update setInterval timer
}, //end scheduleUpdate function

/*
* build Wunderground API request
* Original code from RedNax's MMM-Wunderground module
Expand Down Expand Up @@ -53,8 +80,9 @@ module.exports = NodeHelper.create({
function(error, response, body) {

if (!error && response.statusCode == 200) {
this.wunderPayload = body;
//for some reason, when inside function(error, response, body) we lose the ability to see this.config.debug...
//this.wunderPayload = body;
wunderPayload = body;
//for some reason, when inside function(error, response, body) we lose the ability to see this.config.debug...
//but with declaration of self = this...we change to self.config.debug et voila.
if (self.config.debug === 1) {
apiMessage = moment().format('YYYY-MM-DDTHH:mm:ss.SSSZZ') + ' HELPER: Wunderground Data API RESPONSE (4): Received';
Expand All @@ -67,13 +95,6 @@ module.exports = NodeHelper.create({
self.sendSocketNotification('HELPER_MESSAGE', apiMessage);
}
}
// setInterval(function() {
// if (self.config.debug === 1) {
// apiMessage = moment().format('YYYY-MM-DDTHH:mm:ss.SSSZZ') + ' HELPER: setInterval called in fetchWunderground: ' + self.config.updateInterval;
// self.sendSocketNotification('HELPER_MESSAGE', apiMessage);
// }
// self.fetchWunderground();
// }, self.config.updateInterval);
} // end request(function())
); // end request()
this.WufetcherRunning = false; // turn our running flag off.
Expand Down Expand Up @@ -110,12 +131,14 @@ module.exports = NodeHelper.create({
}, function(error, response, body) {

if (!error && response.statusCode == 200) {
this.NOAAPayload = body;
//this.NOAATempPayload = body;
NOAATempPayload = body;
if (self.config.debug === 1) {
apiMessage = moment().format('YYYY-MM-DDTHH:mm:ss.SSSZZ') + ' HELPER: NOAA Water Temp API RESULT(4): Received';
self.sendSocketNotification('HELPER_MESSAGE', apiMessage);
}
self.sendSocketNotification('NOAA_WATERTEMP', body);

self.sendSocketNotification('NOAA_WATERTEMP', body);
} else {
if (self.config.debug === 1) {
apiMessage = moment().format('YYYY-MM-DDTHH:mm:ss.SSSZZ') + ' HELPER: NOAA Water Temp API ERROR (5): ' + error;
Expand All @@ -138,7 +161,8 @@ module.exports = NodeHelper.create({
},
function(error, response, body) {
if (!error && response.statusCode == 200) {
this.NOAAPayload = body;
//this.NOAATidePayload = body;
NOAATidePayload = body;
if (self.config.debug === 1) {
apiMessage = moment().format('YYYY-MM-DDTHH:mm:ss.SSSZZ') + ' HELPER: NOAA Tide Data API RESULT(4): Received';
self.sendSocketNotification('HELPER_MESSAGE', apiMessage);
Expand All @@ -152,16 +176,6 @@ module.exports = NodeHelper.create({
}
}

// setInterval(function() {
// if (self.config.debug === 1) {
// apiMessage = moment().format('YYYY-MM-DDTHH:mm:ss.SSSZZ') + ' HELPER: setInterval called in fetchNOAAData: ' + self.config.updateInterval;

// self.sendSocketNotification('HELPER_MESSAGE', apiMessage);
// }
// self.fetchNOAAData();
// }, self.config.updateInterval);


} //end request(function())
); //end request() for NOAA Tides
this.NOAAfetcherRunning = false;
Expand All @@ -184,26 +198,24 @@ module.exports = NodeHelper.create({
},
function(error, response, body) {
if (!error && response.statusCode == 200) {
this.magicseaweed = body;
//this.magicseaweed = body;
magicseaweed = body;
if (self.config.debug === 1) {
apiMessage = moment().format('YYYY-MM-DDTHH:mm:ss.SSSZZ') + ' HELPER: Magicseaweed API RESULT(4): Received';
self.sendSocketNotification('HELPER_MESSAGE', apiMessage);
}
self.sendSocketNotification('MAGICSEAWEED', body);
} else {
self.sendSocketNotification('MAGICSEAWEED', body);
this.sendCachedTime = "";
sendCachedTime = moment().format('YYYY-MM-DD >> HH:mm:ss.SSSZZ');
self.sendSocketNotification('LAST_UPDATED', sendCachedTime); //send notification back to MMM-Surf.js to set update time


} else {
if (self.config.debug === 1) {
apiMessage = moment().format('YYYY-MM-DDTHH:mm:ss.SSSZZ') + ' HELPER: Magicseaweed API ERROR(4): ' + error;
self.sendSocketNotification('HELPER_MESSAGE', apiMessage);
}
}
// setInterval(function() {
// if (self.config.debug === 1) {
// apiMessage = moment().format('YYYY-MM-DDTHH:mm:ss.SSSZZ') + ' HELPER: setInterval called in fetchMagicseaweedData: ' + self.config.updateInterval;
// self.sendSocketNotification('HELPER_MESSAGE', apiMessage);
// }
// self.fetchMagicseaweedData();
// }, self.config.updateInterval);

} // end request(function())
); //end Magicseaweed request
this.MAGICfetcherRunning = false;
Expand All @@ -213,7 +225,28 @@ module.exports = NodeHelper.create({
socketNotificationReceived: function(notification, payload) {
var self = this;
var apiMessage = "";
if (notification === 'GET_NOAA') {
if (notification === 'UPDATE_TIMER') {
this.config = payload;
if (this.started !== true) {
this.started = true;
this.scheduleUpdate();
if (this.config.debug === 1) {
apiMessage = moment().format('YYYY-MM-DDHH:mm:ss.SSSZZ') + ' UPDATE: ' + notification + ': Setting update schedule';
self.sendSocketNotification('HELPER_MESSAGE', apiMessage)
}
} else {
var self = this;
if (this.config.debug === 1) {
apiMessage = moment().format('YYYY-MM-DDTHH:mm:ss.SSSZZ') + ' UPDATE: scheduleUpdate already set. Next update at: '+ tempTime.format('YYYY-MM-DD >> HH:mm:ss.SSSZZ');
self.sendSocketNotification('HELPER_MESSAGE', apiMessage)
}
}
} //end UPDATE_TIMER Socket Config



if (notification === 'GET_NOAA' && this.started == false) {
// if we haven't started, go fetch data. Otherwise dont & send cached data back
this.config = payload;
if (this.config.debug === 1) {
apiMessage = moment().format('YYYY-MM-DDTHH:mm:ss.SSSZZ') + ' HELPER_SOCKET(RECEIVED FROM MAIN): ' + notification + ': Fetching Data (2)';
Expand All @@ -227,10 +260,24 @@ module.exports = NodeHelper.create({
apiMessage = moment().format('YYYY-MM-DDTHH:mm:ss.SSSZZ') + ' HELPER_SOCKET(ERROR)(2): ' + self.name + ': NOAAfetcherRunning = ' + this.NOAAfetcherRunning;
self.sendSocketNotification('HELPER_MESSAGE', apiMessage)
}
}
} //end NOAA Socket Config
} // end get live data if clause
} else if (notification === 'GET_NOAA' && this.started == true) {
//send cached NOAA data back to module for new client to load
self.sendSocketNotification('LAST_UPDATED', sendCachedTime); //send notification back to MMM-Surf.js to set update time

if (notification === 'GET_MAGIC') {
if (this.config.debug === 1) {
apiMessage = moment().format('YYYY-MM-DDTHH:mm:ss.SSSZZ') + ' HELPER_SOCKET(RECEIVED FROM MAIN): ' + notification + ': Sending cached data: NOAA_WATERTEMP'};
self.sendSocketNotification('HELPER_MESSAGE', apiMessage)
self.sendSocketNotification('NOAA_WATERTEMP', NOAATempPayload); // send previously fetched data
if (this.config.debug === 1) {
apiMessage = moment().format('YYYY-MM-DDTHH:mm:ss.SSSZZ') + ' HELPER_SOCKET(RECEIVED FROM MAIN): ' + notification + ': Sending cached data: NOAA_TIDE_DATA'};
self.sendSocketNotification('HELPER_MESSAGE', apiMessage)
self.sendSocketNotification('NOAA_TIDE_DATA', NOAATidePayload); // send previously fetched data

} //end NOAA Socket Config

if (notification === 'GET_MAGIC' && this.started == false) {
// if we haven't started, go fetch data. Otherwise dont & send cached data back
this.config = payload;
if (this.config.debug === 1) {
apiMessage = moment().format('YYYY-MM-DDTHH:mm:ss.SSSZZ') + ' HELPER_SOCKET(RECEIVED FROM MAIN): ' + notification + ': Fetching Data (2)';
Expand All @@ -244,25 +291,41 @@ module.exports = NodeHelper.create({
apiMessage = moment().format('YYYY-MM-DDTHH:mm:ss.SSSZZ') + ' HELPER_SOCKET(ERROR)(2): ' + self.name + ': MAGICfetcherRunning = ' + this.MAGICfetcherRunning;
self.sendSocketNotification('HELPER_MESSAGE', apiMessage)
}
} //end get live data if clause
} else if (notification === 'GET_MAGIC' && this.started == true) {
//send cached Magicseaweed data back to module for new client to load
if (this.config.debug === 1) {
apiMessage = moment().format('YYYY-MM-DDTHH:mm:ss.SSSZZ') + ' HELPER_SOCKET(RECEIVED FROM MAIN): ' + notification + ': Sending cached data';
self.sendSocketNotification('HELPER_MESSAGE', apiMessage)
self.sendSocketNotification('MAGICSEAWEED', magicseaweed); //send previously fetched data
}
} //end Magicseaweed Socket config
} //end Magicseaweed Socket config

if (notification === 'GET_WUNDERGROUND') {
if (notification === 'GET_WUNDERGROUND' && this.started == false) {
// if we haven't started, go fetch data. Otherwise dont & send cached data back
this.config = payload;
if (this.config.debug === 1) {
apiMessage = moment().format('YYYY-MM-DDTHH:mm:ss.SSSZZ') + ' HELPER_SOCKET(RECEIVED FROM MAIN): ' + notification + ': Fetching Data (2)';
self.sendSocketNotification('HELPER_MESSAGE', apiMessage)
}
if (!this.WufetcherRunnin) {
if (!this.WufetcherRunning) {
this.fetchWunderground();
} else {
var self = this;
if (this.config.debug === 1) {
apiMessage = moment().format('YYYY-MM-DDTHH:mm:ss.SSSZZ') + ' HELPER_SOCKET(ERROR)(2): ' + self.name + ': WufetcherRunning = ' + this.WufetcherRunning;
self.sendSocketNotification('HELPER_MESSAGE', apiMessage)
}
}
} //end Wunderground Socket config
} //end get live data if clause
} else if (notification === 'GET_WUNDERGROUND' && this.started == true) {
//send cached Wunderground data back to module for new client to load
if (this.config.debug === 1) {
apiMessage = moment().format('YYYY-MM-DDTHH:mm:ss.SSSZZ') + ' HELPER_SOCKET(RECEIVED FROM MAIN): ' + notification + ': Sending cached data';
self.sendSocketNotification('HELPER_MESSAGE', apiMessage)
self.sendSocketNotification('WUNDERGROUND', wunderPayload); //send previously fetched data
}

} //end Wunderground Socket config
} // end socketNotification

}); //end helper module
Expand Down

0 comments on commit fe98b7f

Please sign in to comment.