JSON sent from node_helper is not seen in main module
E3V3A opened this issue · 1 comments
E3V3A commented
The API is using a Promise
based return and I have not been able to figure out how to send this to the main module MMM_FlightsAbove.js
, and display it after reception, but before sending to the Tabulator generator.
I have also looked into async/await
methods, but to no avail. So I think the problem may be fairly simple in nature.
E3V3A commented
Thanks to @raywo, we now have a working module. Essentially he replaced my complicated Promises
-based code, with the correct API use of using the native array of JS objects.
Before:
radarPing: function() {
Promise.all([
radar(53.05959,12.52388,51.98161,14.29552) // (Berlin)
])
.then(function(results) {
let ping = JSON.stringify(results);
console.log("Sending NEW_RADAR_DATA:");
console.log(ping);
this.sendSocketNotification("NEW_RADAR_DATA", ping);
console.log("This is never shown!");
})
.then(function(error) {
console.log(error);
});
},
After:
radarPing: function() {
radar(53.05959,12.52388,51.98161,14.29552) // (Berlin)
.then((flights) => {
this.sendSocketNotification("NEW_RADAR_DATA", flights);
console.log("Sending NEW_RADAR_DATA:");
console.log(flights);
})
.catch(function(error) {
console.log(error);
});
},